8000 fix(python): report dependency declarations deptry cannot read instead of skipping silently by tuyentran4992 · Pull Request #200 · habit-hooks/habit-hooks · GitHub
[go: up one dir, main page]

Skip to content

fix(python): report dependency declarations deptry cannot read instead of skipping silently - #200

Open
tuyentran4992 wants to merge 2 commits into
habit-hooks:mainfrom
tuyentran4992:fix-deptry-unreadable-declarations
Open

tuyentran4992 wants to merge 2 commits into
habit-hooks:mainfrom
tuyentran4992:fix-deptry-unreadable-declarations

Conversation

@tuyentran4992
Copy link
Copy Markdown

Closes #129.

A project that declares its dependencies only in setup.py, setup.cfg or a Pipfile is silently never checked: deptry fails with DependencySpecificationNotFoundError, the sensor prints [], and the run is reported clean.

The sensor now reports a single parse-error finding 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-error is enforced, 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 existing test_a_project_declaring_no_dependencies_is_clean.py.

…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.
Comment on lines +40 to +45
@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:
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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"
    )

Comment on lines +46 to +49
"message": (
f"dependencies declared in {declaration} are never "
"checked — deptry reads pyproject.toml or requirements "
"files only"
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Suggested change
"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.
@tuyentran4992
Copy link
Copy Markdown
Author

Both points are addressed in c43d5e2:

  • The test function keeps three parameters again. The fixture contents moved into a DECLARATION_CONTENTS mapping keyed by filename, exactly as suggested, so PLR0913 (max-args = 3) is satisfied; ruff check --config pyproject.toml src tests plugins reports 0 errors on the branch (it reported the single PLR0913 before the change).
  • The parse-error finding now carries its explanation in details.content instead of details.message.

pytest plugins/python/tests is green (7 passed). Thanks for the review.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Dependencies declared in setup.py, setup.cfg or a Pipfile are silently never checked

2 participants

0