Skip to content

fix: read includes of a symlinked requirements file from the link's folder - #618

Merged
patrickballard merged 4 commits into
wheelgap:mainfrom
Dikshant-Neupane:fix/604-symlinked-requirements-include
Nov 21, 2026
Merged

patrickballard merged 4 commits into
wheelgap:mainfrom
Dikshant-Neupane:fix/604-symlinked-requirements-include

Conversation

@Dikshant-Neupane

Copy link
Copy Markdown
Contributor

Closes #604.

pip resolves a relative -r against the folder of the file as it was named, with no symlink resolution. wheelgap resolved symlinks first, so an include in a symlinked requirements file was read from the folder the link points into. With a shared reqs.txt linked into several service folders, each with its own base.txt, wheelgap checked other packages than pip installs.

This reads every requirements file through the folder it was named in (os.path.abspath, no symlink resolution), so includes resolve against the link's folder, as pip does.

The loop and already-read identity stays the resolved path, so a file reached by two names is still read once and a cycle through a link is still refused. Pip uses the abspath for that identity too, which would read such a file twice and list its packages twice; the resolved identity keeps the single-read behaviour. The cycle error names the file as written, as pip does.

--github-annotations now annotates the file pip reads, and --dockerfile-inputs still refuses symlinks in a build context.

The tracker check from the issue (tests/test_check_driver.py and tests/test_check_parity.py) is not run here, the tracker repo is not on this box. The missing-include error now names the as-named path, which is what needs() reads, so that path should still work.

AI assistance was used to prepare this PR, and I reviewed the changes before opening it.

@patrickballard

Copy link
Copy Markdown
Collaborator

Thanks @Dikshant-Neupane, this looks good overall: includes now resolve against the folder the file was named in, as pip does, while the resolved path stays the identity for the "already read" and cycle checks, and the PR says clearly why you chose that. The tests cover every case the issue lists.

One thing to flag: test (windows-latest, py3.14) fails on two of the new tests. Both look like test problems on Windows rather than a problem in the fix:

  • test_requirements_symlinked_file_missing_include_names_the_path_pip_would_open compares against str(caught.value), which shows the filename as a repr (doubled backslashes on Windows). Comparing caught.value.filename would avoid that.
  • test_github_annotations_symlinked_requirements_file_names_the_link exits 2 instead of 1. It is the only new test that makes its link from a string with forward slashes (symlink_to("../real/reqs.txt")) where the others pass a Path, so the link is probably broken on Windows.

#604 is a help wanted issue, so Patrick will review and merge this one himself, and he'll sort out those two tests as part of that. Nothing more needed from you for now.

(Review assisted by Claude.)

… tests

pip 26.3 compares the include's os.path.abspath with the chain, so one shared file linked into two folders can be on the chain under both names without being a cycle; the resolved-path check refused that layout with 'pip refuses this' although pip installs it. The already-read identity stays the resolved path. relative_path() resolves links again, as on main: git keeps a link as a link, so an annotation under the link's path has no lines to show, and other inputs' annotations stay as they were. The two tests that failed on Windows compared a path with its repr and made a link with forward slashes.

Co-Authored-By: Claude Fable 5.2 <[email protected]>
@patrickballard

Copy link
Copy Markdown
Collaborator

Thanks @Dikshant-Neupane! The core change matches pip: we checked real pip 26.3 on a symlinked file, a symlinked folder and a link to a link, and it resolves includes against the folder the file was named in each time.

Adding to the earlier review, we've made these changes so it can go in:

  • The cycle check compares files by the name they were included under, as pip does. With resolved paths, one shared file linked into two service folders was refused as a loop, though pip installs it. Two tests cover that layout.
  • Annotations resolve links again, so a line in a linked file points at the real file GitHub can show.
  • The two tests that failed on Windows are fixed.
  • The docs sentence is marked "(after 0.13.0)".

Please name the AI tool in the PR description, if one helped. It'll merge once a final review passes.

(Review assisted by Claude.)

@patrickballard
patrickballard merged commit 6d0f892 into wheelgap:main Nov 21, 2026
13 checks passed
@patrickballard

Copy link
Copy Markdown
Collaborator

Merged, thanks @Dikshant-Neupane! The final review ran real pip 26.3 on eleven symlink layouts, and wheelgap reads the same packages in each.

If you would like another, tracker#213 is open and unclaimed: the repo checker gives an unhelpful error for a package name or a GitLab URL typed in the box.

(Reply assisted by Claude.)

patrickballard added a commit to kunalkshah1/wheelgap that referenced this pull request Nov 21, 2026
CHANGELOG keeps both bullets, this PR's first.

Co-Authored-By: Claude Fable 5.2 <[email protected]>
patrickballard added a commit to kunalkshah1/wheelgap that referenced this pull request Nov 21, 2026
CHANGELOG keeps both bullets, this PR's first.

Co-Authored-By: Claude Fable 5.2 <[email protected]>
patrickballard added a commit to kunalkshah1/wheelgap that referenced this pull request Nov 21, 2026
CHANGELOG conflict only: both bullets kept, this PR first.

Co-Authored-By: Claude Fable 5.2 <[email protected]>
patrickballard added a commit to kunalkshah1/wheelgap that referenced this pull request Nov 21, 2026
CHANGELOG conflict only: both bullets kept, this PR first.

Co-Authored-By: Claude Fable 5.2 <[email protected]>
@Dikshant-Neupane

Copy link
Copy Markdown
Contributor Author

Thank you for the reviews and for merging it, and for the extra fixes and the real pip checks on the symlink layouts. I learned a lot from how you handled the cycle check and the annotations. Please let me know if there is another issue I can help with.

patrickballard added a commit to kunalkshah1/wheelgap that referenced this pull request Nov 21, 2026
…s, pin gate through includes

main now has wheelgap#622 (harmless pip flags, -c FILE on the RUN line, the --prefer-binary gate) and wheelgap#618 (a
symlinked file's includes are read from the link's folder). Both PRs rewrote the same block of
dockerfile.py, so this reconciles them rather than taking a side:

- copied_requirements (the wheelgap#622 closure that resolves -r FILE and -c FILE) now finds the file with
  _find_copied_file and verifies its includes with _check_includes, in place of the _has_include refusal.
  That covers -c files too: a -r inside a constraints file is read as requirements, so its packages are
  installed and the file must be the one the image has. `includes` is filled for constraints files as
  well as requirements files.
- The --prefer-binary gate parses the file as load_inputs will, with the line's -c files and through
  every include, so an unpinned requirement in an included file (or in a -r inside a -c file) is refused
  and the message names that file. A requirement that a constraint pins with == counts as pinned.
  --deps is still refused, before anything is parsed.
- dockerfile_requirements takes includes=, constraints= and dependencies=; the CLI passes all three and
  the stderr note lists the requirements file, its includes, each -c file and that file's includes.
- wheelgap#622's test that a -c file with a nested -c is refused now expects the include to be followed through
  the image (refused when it isn't copied), and new tests cover a -r inside a RUN-line -c file,
  --prefer-binary with an unpinned requirement in an included file, and a chain that mixes a RUN-line
  -c with an in-file -c.
- CHANGELOG keeps both bullets; docs/cli.md describes includes and -c files in one paragraph.

Co-Authored-By: Claude Fable 5.2 <[email protected]>
patrickballard added a commit to benjibunbun/wheelgap that referenced this pull request Nov 21, 2026
main gained wheelgap#618, which rewrote the first lines of requirement_lines(): a file is read through the folder it was named in and the already-read set holds resolved paths. The merged scanner keeps this PR's per-role seen (a -r inside a constraints file gives requirements, a constraints file's own lines give none) with that path handling, as sources._read_requirements has both. One test covers the two together: a symlinked requirements file whose includes go -c then -r.

Co-Authored-By: Claude Fable 5.2 <[email protected]>
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.

Requirements files: includes of a symlinked requirements file are read from the link's target folder, not the link's

2 participants