Skip to content

Follow verified requirements includes in Dockerfile inputs - #621

Merged
patrickballard merged 7 commits into
wheelgap:mainfrom
kunalkshah1:fix/docker-input-includes
Nov 21, 2026
Merged

patrickballard merged 7 commits into
wheelgap:mainfrom
kunalkshah1:fix/docker-input-includes

Conversation

@kunalkshah1

Copy link
Copy Markdown
Contributor

Closes #598

What this changes

Follow local requirements and constraints includes only when the Docker image and host-side requirements parser resolve them to the same build-context file. Reuse the requirements include parser, refuse missing or overwritten copies and ambiguous includes, and list the files read in the RUN diagnostic.

Tests compare the Dockerfile result with a direct requirements check and exercise nested requirements, constraints, missing copies, overwritten copies, URL and variable includes, and editable ambiguity.

AI tools used: Codex

Checks

Ruff formatting and lint, mypy, and full pytest on macOS with Python 3.14 (5,187 passed, 3 skipped). The Unreleased entry will be added with the PR number.

@patrickballard

Copy link
Copy Markdown
Collaborator

Thanks @kunalkshah1, this looks good overall: a nested -r or -c is followed only when a COPY puts the same build-context file at the path pip would read in the image, and anything else (a missing or overwritten copy, a URL, a variable, an abbreviated option) is still refused with its line, never guessed. The tests compare the Dockerfile result with a direct requirements check, which is the right way to pin it.

It touches the same parts of dockerfile.py and cli.py as your other --dockerfile-inputs PRs (#621, #622, #625, #626, #630), so Patrick will sort out the merge order and any conflicts between them.

CI is green on this commit.

#598 is a help wanted issue, so Patrick will review and merge this one himself. Nothing more needed from you for now.

(Review assisted by Claude.)

patrickballard and others added 2 commits November 21, 2026 10:49
…te or sub/../ includes by name

The symlink check ran on every file, so a symlinked requirements file named as a COPY source (Docker follows it, and main reads it) and every file under a symlinked build context folder were newly refused. It now applies to a file that has includes and to every included file, where the image and the reader can disagree, and never to the context folder itself. An absolute include gets its own message, sub/../base.txt is refused (pip opens it through sub/, which the image may not have), and a reader error no longer repeats the file name. Docs mark the change as after 0.13.0.

Co-Authored-By: Claude Fable 5.2 <[email protected]>
CHANGELOG.md: both sides' bullets kept, this PR's first.

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

Copy link
Copy Markdown
Collaborator

Thanks @kunalkshah1! This is the careful way to do #598: each include is resolved inside the image, mapped back through COPY, and must be the same context file the reader will open, so nothing is read that the image wouldn't have.

We've made these changes so it can go in:

  • Symlinks are refused only in include chains. A plain symlinked requirements file and a symlinked context folder are read as before.
  • -r sub/../base.txt is refused (pip opens it through sub/, which the image may not have), and an absolute include gets its own clear message.
  • A reader error no longer repeats the file name.
  • More tests (absolute include, cycle, .., a subfolder include with -c ../constraints.txt, the symlink cases), docs marked "after 0.13.0", and the CHANGELOG bullet reworded.

It merges after #622, with main merged in, and gets its final review on that combined head.

(Review assisted by Claude.)

patrickballard and others added 3 commits November 21, 2026 11:09
…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
patrickballard merged commit 1d0e035 into wheelgap:main Nov 21, 2026
13 checks passed
@patrickballard

Copy link
Copy Markdown
Collaborator

Merged, thanks @kunalkshah1! The final review traced every include route against real pip 26.3 and found no case where wheelgap reads a file the image would not have. It went in combined with #622, so a constraints file named on the RUN line has its own includes verified too.

(Reply assisted by Claude.)

patrickballard added a commit to kunalkshah1/wheelgap that referenced this pull request Nov 21, 2026
main gained wheelgap#622 (pip flags, -c FILE on the RUN line, the --prefer-binary
gate), wheelgap#621 (verified -r/-c includes) and wheelgap#630 since this branch was written.

dockerfile.py: main moved the COPY lookup into _find_copied_file, called by
the copied_requirements closure and by _check_includes. The ignore rules are
now a required argument of _find_copied_file and _check_includes and reach
_copied_file from both, so a file that .dockerignore leaves out under a folder
COPY is refused with the rule named whether it is the installed file, a -c
file on the RUN line, or a -r/-c inside either. Without this an excluded
include would have been read from disk although the image doesn't have it.
The old "a .dockerignore is refused" loop stays deleted (main still had it),
and the merged docstring no longer lists a .dockerignore among the refusals.

tests: both sides' new tests are kept; the nested-includes test keeps wheelgap#621's
assertions and this branch's removal of its .dockerignore tail. New tests for
the interaction: an excluded include (one and two levels down), an excluded
-c file, an excluded -r inside the -c file, the same under --prefer-binary,
an include a later ! rule puts back (and a later rule takes out again), a
file COPY naming an excluded source, and the CLI looking nothing up.

docs/cli.md: the ignore-file paragraph says included and constraints files
are covered. CHANGELOG: every bullet once, 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
…t be pinned

main gained -c FILE and harmless pip flags (wheelgap#622), verified includes (wheelgap#621),
.dockerignore rules (wheelgap#626), install provenance (wheelgap#630), uv's Requires-Python
lower-bound rule (wheelgap#623) and MCP wording (wheelgap#624) since this branch was written.

_pip_install_files returns (files, constraints, prefer_binary, uv) and has one
flag loop with the uv branch first. On a uv line only uv's own flags are read:
--system, -r/--requirements, -c/--constraints, --no-cache, --no-cache-dir,
--upgrade/-U and --quiet/-q (checked against `uv pip install --help`, 0.13.1).
pip's --no-input, --root-user-action and --prefer-binary don't exist in uv, and
--disable-pip-version-check only warns there, so they are refused.

A uv line's files are found by the same copied_requirements closure as pip's,
so the ignore rules and the include checks apply. Three things are uv's own:
- every requirement must be pinned with == (through includes; a pin from a
  constraints file counts), using the gate --prefer-binary already had, and
  --deps is refused: wheelgap resolves a range as pip does, and uv can pick
  another release;
- a -r inside a constraints file is refused: pip installs what it names and uv
  only constrains with it (uv 0.13.1 against pip 26.2);
- included and -c files must be named *.txt or *.in, like the -r file.
A file installed by pip on one line and uv on another is refused, and a caller
that doesn't pass uv_installs gets an error rather than pip's answer.

cli.py: the stderr note keeps main's list of every file read and says which
installer ran; uv-installed files get restore_uv_python_files, as a uv.lock
with --online does, so the pip_refuses note is main's.

docs/cli.md has one paragraph for uv; CHANGELOG keeps every bullet once, this
PR's first, reworded.

Co-Authored-By: Claude Fable 5.2 <[email protected]>
@patrickballard patrickballard mentioned this pull request Nov 23, 2026
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.

--dockerfile-inputs: follow a -r or -c inside the requirements file the Dockerfile installs

2 participants