Repository navigation
fix(python): report dependency declarations deptry cannot read instead of skipping silently - #200
tuyentran4992 wants to merge 2 commits into
Conversation
…d of skipping silently A project that declares its dependencies only in setup.py, setup.cfg or a Pipfile was silently never checked: deptry failed with DependencySpecificationNotFoundError, the sensor printed [] and the run was reported clean. The sensor now reports a single parse-error finding that carries one issue per existing declaration file. A project with no declaration file, and every other deptry failure, behave exactly as before.
| @pytest.mark.parametrize( | ||
| ("declaration", "contents"), DECLARATIONS, ids=[name for name, _ in DECLARATIONS] | ||
| ) | ||
| def test_dependencies_deptry_cannot_read_are_not_silently_skipped( | ||
| tmp_path: Path, deptry: str, declaration: str, contents: str | ||
| ) -> None: |
There was a problem hiding this comment.
CI's ruff check step fails on this PR: the parametrized test takes four arguments where the repo caps at three (max-args = 3 in the root pyproject). The two data arguments are one thing — a declaration file — and its contents are fixture data like any other, so a named constant keyed by filename keeps each argument meaningful and passes:
DECLARATION_CONTENTS = {
"setup.py": "from setuptools import setup\n\nsetup(name='demo', version='0.0.0')\n",
"setup.cfg": "[metadata]\nname = demo\nversion = 0.0.0\n\n"
"[options]\ninstall_requires =\n attrs\n",
"Pipfile": "[packages]\nattrs = '*'\n",
}
@pytest.mark.parametrize(
"declaration", DECLARATION_CONTENTS, ids=list(DECLARATION_CONTENTS)
)
def test_dependencies_deptry_cannot_read_are_not_silently_skipped(
tmp_path: Path, deptry: str, declaration: str
) -> None:
(tmp_path / declaration).write_text(
DECLARATION_CONTENTS[declaration], encoding="utf-8"
)| "message": ( | ||
| f"dependencies declared in {declaration} are never " | ||
| "checked — deptry reads pyproject.toml or requirements " | ||
| "files only" |
There was a problem hiding this comment.
Could you make sure the explanation lands in details.content rather than details.message? The shared guides print content after the file, and nothing renders message, so as written the user never sees why the run failed.
| "message": ( | |
| f"dependencies declared in {declaration} are never " | |
| "checked — deptry reads pyproject.toml or requirements " | |
| "files only" | |
| "content": ( | |
| f"dependencies declared in {declaration} are never " | |
| "checked — deptry reads pyproject.toml or requirements " | |
| "files only" | |
| ), |
…anation via details.content Addresses the two review points: the parametrized test keeps three parameters (fixture contents now live in a DECLARATION_CONTENTS mapping keyed by filename, satisfying PLR0913/max-args = 3), and the parse-error finding explains itself via details.content, which the shared guides render after the file. ruff check --config pyproject.toml src tests plugins: 0 errors; pytest plugins/python/tests: 7 passed.
|
Both points are addressed in c43d5e2:
|
Closes #129.
A project that declares its dependencies only in
setup.py,setup.cfgor aPipfileis silently never checked: deptry fails withDependencySpecificationNotFoundError, the sensor prints[], and the run is reported clean.The sensor now reports a single
parse-errorfinding that carries one issue per existing declaration file, instead of printing[]. Two behaviours stay unchanged: a project with no declaration file at all keeps today's clean run ([], rc 0), and any other deptry failure still exits 2.Note that
parse-errorisenforced, so such projects fail the run rather than pass silently — the trade-off discussed on the issue.Test:
plugins/python/tests/test_dependencies_deptry_cannot_read_are_not_silently_skipped.py(each declaration format, plus the multi-file case), running alongside the existingtest_a_project_declaring_no_dependencies_is_clean.py.