Skip to content

Read pip install flags and constraints from Dockerfile RUN - #622

Merged
patrickballard merged 5 commits into
wheelgap:mainfrom
kunalkshah1:fix/docker-pip-install-flags
Nov 21, 2026
Merged

patrickballard merged 5 commits into
wheelgap:mainfrom
kunalkshah1:fix/docker-pip-install-flags

Conversation

@kunalkshah1

Copy link
Copy Markdown
Contributor

Closes #595

What this changes

Recognize the documented pip diagnostics and cache flags, plus --upgrade and per-RUN constraints, when reading Dockerfile inputs. Follow constraint files through the same COPY and WORKDIR rules as requirements files and pass them to the usual requirements parser. Allow --prefer-binary only when the requirements are exactly pinned and the check does not resolve dependencies.

Tests cover accepted flags, refusal of flags that change resolution, missing and symlinked constraints, and parity with the same constraints specified inside the requirements file.

AI tools used: Codex

Checks

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

…s source, and read -c FILE as -r FILE is read

A requirements file installed with -c FILE was parsed outside load_file, so its source lost its kind and path (--fix and --github-annotations go by both). A symlinked requirements or constraints file named as a COPY source was newly refused (Docker follows it, and main reads it), as was every file when the build context folder itself is a symlink. --root-user-action took any value, though pip exits on one other than warn or ignore. The refusal message now lists the flags read, the stderr note names the -c files, a caller that doesn't take the constraints gets an error instead of unconstrained requirements, and a -r inside a constraints file keeps its packages. Docs mark the new flags 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! The design matches #595: the flags that don't change which files pip picks are read, -c FILE is followed through COPY, --prefer-binary is read only when it can't change the answer, and everything else is refused with its line.

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

  • A requirements file installed with -c is still read as a requirements file, so --fix and --github-annotations work on it.
  • A constraints file is refused in the same cases as a requirements file. A symlinked file named in COPY is read again, as Docker follows it; the new symlink check had started refusing those, and every file when the context folder is itself a link.
  • --root-user-action takes only pip's own values, warn and ignore.
  • The stderr note names the -c files, and the error for an unread flag lists what is read.
  • More tests (flags after the file, = forms, --pre, --user, --target, -e, --upgrade-strategy), docs marked "after 0.13.0", and the CHANGELOG bullet reworded.

This one goes first of your four Dockerfile PRs, since they all change the same block; we'll merge main into the others in turn. It'll merge once a final review passes.

(Review assisted by Claude.)

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

Copy link
Copy Markdown
Collaborator

Merged, thanks @kunalkshah1! The final review ran real pip 26.3 with each accepted flag and got the same install report as a plain -r, and confirmed every other pip option still refuses the line. #621 is next, with this merged in.

(Reply assisted by Claude.)

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 kunalkshah1/wheelgap that referenced this pull request Nov 21, 2026
CHANGELOG.md conflicted with wheelgap#622's bullet: both kept, 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.md conflicted with wheelgap#622's bullet: both kept, 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
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: read pip install with --upgrade, --disable-pip-version-check, --root-user-action=ignore and -c FILE

2 participants