Repository navigation
Read Docker ignore rules when locating requirements inputs - #626
Conversation
|
Thanks @kunalkshah1, this looks good overall: the Dockerfile-specific ignore file wins over the context's It touches the same parts of CI is green on this commit. #597 is a (Review assisted by Claude.) |
…gainst Moby's table Three cases where the reading could differ from Docker's now raise instead: a pattern that Moby's second clean-and-trim turns into an exception or trims (./!a, ./ a); a backslash, colon or leading // when wheelgap runs on Windows, where Docker's client reads backslash as a separator; and an empty Dockerfile-specific ignore file beside a .dockerignore with rules, where BuildKit's built-in and # syntax= frontends pick different files. Adds Moby's patternmatcher test table and fsutil's exception cases as tests, and says in the docs what is read. Co-Authored-By: Claude Fable 5.2 <[email protected]>
Co-Authored-By: Claude Fable 5.2 <[email protected]>
|
Thanks @kunalkshah1! This is a faithful port of Moby's matcher. We read We've made these changes so it can go in. Each is a case Docker can read differently from the port, so wheelgap now refuses instead of guessing:
We also added Moby's own matcher test table and fsutil's exception cases as tests (they pass on Linux, macOS and Windows), and the docs say what is read, marked "after 0.13.0". It merges third of the four Dockerfile PRs, with main merged in, and gets its final review on that head. (Review assisted by Claude.) |
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]>
…reads as rules Two cases where a file the image doesn't have was read: - A symlink is matched against the ignore rules by its own name, so a link whose target the rules leave out (a linked folder under `COPY . .`, or a linked file a COPY names) was read although it dangles in the image. When the ignore file has rules, a COPY source or a file under a folder COPY that is, or is reached through, a symlink below the build context is now an error. With no ignore file, or one with no rules, nothing changes. - Moby's patternmatcher.New cleans an exception with its ! still on, so `!../../requirements.txt` becomes the rule `requirements.txt`, which excludes. The port kept it as an exception that matches nothing; it is now refused, naming the ignore file's line. Merges main (wheelgap#624); CHANGELOG keeps every bullet once, this PR's first. docs/cli.md says both, and the over-long line is wrapped. Co-Authored-By: Claude Fable 5.2 <[email protected]>
|
Merged, thanks @kunalkshah1! A second read against Two narrow cases from the final review now refuse instead of reading the file:
It went in combined with #621 and #622, so the rules also apply to constraints files and to every included file. (Reply assisted by Claude.) |
…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]>
Closes #597
What this changes
Use the Dockerfile-specific ignore file when present, otherwise the context-root .dockerignore. Interpret Go filepath patterns, **, parent directories and last-match exceptions with BuildKit's pruning rules. When a requirements file would be excluded, identify the COPY and the matching rule.
References: Docker ignore files, Moby patternmatcher, and BuildKit's bundled fsutil.
Compared 11,150 pattern/path cases against the bundled Go matcher and pruning rules with no mismatches. Reversing the rule order in the matcher made four regression tests fail.
AI tools used: Codex
Ruff formatting and lint, mypy, and full pytest passed (5,196 passed, 3 skipped). The Unreleased entry will be added with the PR number.