Skip to content

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

Closed

Description

@patrickballard

pip resolves a relative -r against the folder of the file as it was named. wheelgap resolves symlinks first, so it reads from the folder the link points into. When the two folders have different files, wheelgap checks other packages than pip installs:

$ ls -l link/
base.txt
reqs.txt -> ../real/reqs.txt
$ cat real/reqs.txt
-r base.txt
$ cat real/base.txt
psycopg2==2.9.11
$ cat link/base.txt
idna==3.11
$ pip install --dry-run -r link/reqs.txt
Would install idna-3.11
$ wheelgap link/reqs.txt -p 3.14 -t linux-x86_64
package   version  linux-x86_64
psycopg2  2.9.11   ● source

This layout is real: a shared reqs.txt linked into several service folders, each with its own base.txt or constraints.

pip's rule

_parse_and_recurse() joins the include onto os.path.dirname(filename) and calls os.path.abspath, which doesn't follow symlinks:
https://github.com/pypa/pip/blob/26.3/src/pip/_internal/req/req_file.py#L373-L381

Where

_read_requirements() in src/wheelgap/sources.py: path = path.resolve() at the top, then path.parent / include. Other code relies on the resolved path: the seen and stack sets, needs() in the tracker's site/check/driver.py (it reads e.filename of a missing include), and _copied_file() in dockerfile.py, which refuses symlinks in a build context.

What to do

  • Resolve an include against the including file's folder as named (os.path.abspath, no symlink resolution), as pip does.
  • Keep a separate identity for the loop and "already read" checks. pip uses the abspath for that too; say in the PR which you chose and why.
  • --dockerfile-inputs must keep refusing symlinks in the build context. --github-annotations must annotate the file pip reads.
  • Check the tracker's tests/test_check_driver.py against your branch (uvx --with /path/to/wheelgap pytest tests/test_check_driver.py tests/test_check_parity.py in the tracker repo) and say in the PR whether the missing-include path still works.

Done when:

  • Tests in tests/test_sources.py (skipped where symlinks can't be made, as other symlink tests here are) cover: the layout above (wheelgap reads link/base.txt), a symlinked folder, a -c include, and a link whose own folder lacks the include (the error names the path pip would open).
  • The existing symlink tests in tests/test_dockerfile.py pass unchanged.
  • A CHANGELOG line goes under ## Unreleased.

Activity

  1. added
    bug
    help wanted
    on Nov 21, 2026
  2. Dikshant-Neupane commented on Nov 21, 2026

    @Dikshant-Neupane
    Contributor

    I'd like to take this

  3. patrickballard commented on Nov 21, 2026

    @patrickballard
    CollaboratorAuthor

    Go for it, @Dikshant-Neupane! I've assigned this to you.

    Assignments hold for 18 hours: open a PR (a draft is fine) by 23:14 UTC on 21 Nov to keep it. If there's no PR by then, the issue opens up again and the first PR to arrive is the one we merge.

    (Reply assisted by Claude.)

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

Metadata

Metadata

Labels

bughelp wanted

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions