Skip to content

fix(hygiene): detect unpinned dependencies with environment markers - #107

Open
rioyu123 wants to merge 3 commits into
NVIDIA:mainfrom
rioyu123:codex/fix-requirement-marker-pinning
Open

fix(hygiene): detect unpinned dependencies with environment markers#107
rioyu123 wants to merge 3 commits into
NVIDIA:mainfrom
rioyu123:codex/fix-requirement-marker-pinning

Conversation

@rioyu123

Copy link
Copy Markdown
Contributor

Summary

  • Detect unpinned dependencies even when a PEP 508 environment marker contains comparison operators, such as requests; python_version < "3.13".
  • Inspect only the requirement portion before the marker when deciding whether a package has a version constraint.
  • Preserve the existing policy that any requirement comparator counts as constrained; this does not redefine ?pinned? to require ==.
  • Keep direct-reference behavior unchanged because direct-reference URLs may legally contain semicolons.
  • Document the newly emitted warning in the Unreleased changelog.

Before this change, the validator searched the entire physical line for [=<>!], so marker operators could hide an unversioned package:

Requirement Previous result New result
requests; python_version < "3.13" no warning unpinned warning
requests; sys_platform == "win32" no warning unpinned warning
requests>=2; python_version < "3.13" accepted accepted
requests @ https://example.invalid/a;v=1/requests.whl unchanged unchanged

Known adjacent behavior remains out of scope: direct references keep their existing constraint policy, inline comments are not parsed, and backslash continuations are still evaluated as physical lines.

Verification

  • I am familiar with the Contributing Guidelines
  • Added or updated focused tests
  • Updated documentation for user-visible changes
  • Ran make lint
  • Ran make test ? ran the complete affected validator domain instead
  • Ran make build
  • Did not add credentials, private datasets, or proprietary benchmark content

Results:

  • uv run pytest -q tests/validators/test_hygiene.py ? 26 passed, 1 skipped
  • uv run pytest -q tests/validators on Linux ? 847 passed
  • make PYTHON=.venv/bin/python lint ? passed
  • make PYTHON=.venv/bin/python build ? passed

Release Impact

  • No user-visible release note needed
  • Updated CHANGELOG.md

Signed-off-by: Rio Yu <52408936+rioyu123@users.noreply.github.com>

@rng1995 rng1995 left a comment

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.

One blocking marker-parsing case remains.

# Marker comparisons do not constrain the package version. Leave
# direct references intact because their URLs may contain ";";
# markers on direct references therefore keep existing behavior.
constraint_part = line if "@" in line else line.partition(";")[0]

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.

Checking for @ anywhere in the full line misclassifies a marker value as a direct reference. For example, requests; implementation_name == "cpython@corp" produces no unpinned warning. Detect a direct-reference @ only in the requirement portion before ; (or parse the PEP 508 requirement), and add this regression.

@rioyu123 rioyu123 Aug 31, 2026

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Fixed in 5afe819. The direct-reference check now only considers @ before the environment marker, so requests; implementation_name == "cpython@corp" is still reported as unpinned. I added that regression, merged the latest upstream main without rewriting history, and resolved the CHANGELOG conflict. The focused hygiene tests pass (37 passed, 1 skipped), Ruff is clean, and the package build succeeds. The updated GitHub CI is now running.

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.

Thanks for handling the at-sign inside marker values. The direct-reference branch does not actually treat the at-sign as a constraint; it only scans the full URL for comparison characters. As a result, an ordinary requests direct reference to https://example.invalid/requests.whl is still reported as unpinned. The new direct-reference tests pass only because their URL or marker contains a comparison character. Please make the at-sign in requirement_part sufficient while keeping marker text excluded, and add a plain-URL regression.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Thanks — fixed in 29877b2. An @ in the pre-marker requirement now directly identifies a direct reference, while non-direct requirements only check comparison operators before the marker. I also added a plain-URL regression. The hygiene tests pass (38 passed, 1 skipped), and the full Ruff lint and build pass.

Signed-off-by: Rio Yu <52408936+rioyu123@users.noreply.github.com>
Signed-off-by: Rio Yu <52408936+rioyu123@users.noreply.github.com>
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.

2 participants