-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add back PEP 420 support behind feature flag (#808)
* feat(cli): add `--experimental-namespace-package` option * test(core): more robust local modules tests * feat(core): handle subdirectories in PEP 420 mode * test(functional): add tests for namespaced package * docs(usage): document `--experimental-namespace-package`
- Loading branch information
1 parent
b5a5478
commit 6d2344b
Showing
11 changed files
with
205 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
/build |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
from os import chdir, walk | ||
from pathlib import Path | ||
|
||
import flake8 | ||
import white as w | ||
|
||
from foo import api |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
[project] | ||
# PEP 621 project metadata | ||
# See https://www.python.org/dev/peps/pep-0621/ | ||
name = "foo" | ||
version = "1.2.3" | ||
requires-python = ">=3.7" | ||
dependencies = ["tomli==2.0.1"] | ||
|
||
[project.optional-dependencies] | ||
dev = ["flake8==7.1.1"] | ||
|
||
[build-system] | ||
requires = ["setuptools>=61.0.0"] | ||
build-backend = "setuptools.build_meta" | ||
|
||
[tool.deptry] | ||
pep621_dev_dependency_groups = ["dev"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
from __future__ import annotations | ||
|
||
import uuid | ||
from pathlib import Path | ||
from typing import TYPE_CHECKING | ||
|
||
import pytest | ||
|
||
from tests.functional.utils import Project | ||
from tests.utils import get_issues_report | ||
|
||
if TYPE_CHECKING: | ||
from tests.utils import PipVenvFactory | ||
|
||
|
||
@pytest.mark.xdist_group(name=Project.NAMESPACE) | ||
def test_cli_with_namespace(pip_venv_factory: PipVenvFactory) -> None: | ||
with pip_venv_factory(Project.NAMESPACE) as virtual_env: | ||
issue_report = f"{uuid.uuid4()}.json" | ||
result = virtual_env.run(f"deptry . --experimental-namespace-package -o {issue_report}") | ||
|
||
assert result.returncode == 1 | ||
assert get_issues_report(Path(issue_report)) == [ | ||
{ | ||
"error": {"code": "DEP004", "message": "'flake8' imported but declared as a dev dependency"}, | ||
"module": "flake8", | ||
"location": {"file": str(Path("foo/database/bar.py")), "line": 4, "column": 8}, | ||
}, | ||
{ | ||
"error": {"code": "DEP001", "message": "'white' imported but missing from the dependency definitions"}, | ||
"module": "white", | ||
"location": {"file": str(Path("foo/database/bar.py")), "line": 5, "column": 8}, | ||
}, | ||
{ | ||
"error": {"code": "DEP002", "message": "'tomli' defined as a dependency but not used in the codebase"}, | ||
"module": "tomli", | ||
"location": {"file": str(Path("pyproject.toml")), "line": None, "column": None}, | ||
}, | ||
] | ||
|
||
|
||
@pytest.mark.xdist_group(name=Project.NAMESPACE) | ||
def test_cli_with_namespace_without_experimental_flag(pip_venv_factory: PipVenvFactory) -> None: | ||
with pip_venv_factory(Project.NAMESPACE) as virtual_env: | ||
issue_report = f"{uuid.uuid4()}.json" | ||
result = virtual_env.run(f"deptry . -o {issue_report}") | ||
|
||
assert result.returncode == 1 | ||
assert get_issues_report(Path(issue_report)) == [ | ||
{ | ||
"error": {"code": "DEP004", "message": "'flake8' imported but declared as a dev dependency"}, | ||
"module": "flake8", | ||
"location": {"file": str(Path("foo/database/bar.py")), "line": 4, "column": 8}, | ||
}, | ||
{ | ||
"error": {"code": "DEP001", "message": "'white' imported but missing from the dependency definitions"}, | ||
"module": "white", | ||
"location": {"file": str(Path("foo/database/bar.py")), "line": 5, "column": 8}, | ||
}, | ||
{ | ||
"error": {"code": "DEP003", "message": "'foo' imported but it is a transitive dependency"}, | ||
"module": "foo", | ||
"location": {"file": str(Path("foo/database/bar.py")), "line": 7, "column": 1}, | ||
}, | ||
{ | ||
"error": {"code": "DEP002", "message": "'tomli' defined as a dependency but not used in the codebase"}, | ||
"module": "tomli", | ||
"location": {"file": str(Path("pyproject.toml")), "line": None, "column": None}, | ||
}, | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters