[python][pip-compile] Fix constraint files (-c) in .in files not being fetched#14588
Merged
thavaahariharangit merged 6 commits intomainfrom Mar 31, 2026
Merged
Conversation
Closed
1 task
Add two complementary fixes to SharedFileFetcher: 1. Option B: Have `fetch_child_requirement_files` also follow `-c` (CONSTRAINT_REGEX) references in addition to `-r` (CHILD_REQUIREMENT_REGEX) references. This enables recursive constraint fetching from any .in or .txt file. 2. Option A: Have `constraints_files` also scan `.in` files (requirements_in_files) for `-c` references, in addition to `.txt` files. Together these ensure that constraint files referenced via `-c` in `.in` files are fetched before pip-compile runs, preventing the "Could not open requirements file" installation error. Also adds: - Fixture: requirements_in_with_constraint.json (a .in file with -c reference) - Fixture: contents_python_requirements_with_in_file.json (directory with both requirements.in and requirements.txt) - Tests: Two new test cases covering fetchable and unfetchable constraint file referenced from a .in file Agent-Logs-Url: https://github.com/dependabot/dependabot-core/sessions/a6f20d7d-2fab-4f11-b7ca-85b342d6a6d8 Co-authored-by: thavaahariharangit <164553783+thavaahariharangit@users.noreply.github.com>
Copilot
AI
changed the title
[WIP] Fix constraint files in .in files not fetched by file fetcher
[python][pip-compile] Fix constraint files (-c) in .in files not being fetched
Mar 31, 2026
Contributor
There was a problem hiding this comment.
Pull request overview
Fixes a pip-compile update failure where constraint files referenced from requirements.in via -c were not being fetched by the Python file fetcher, causing missing-file errors at update time.
Changes:
- Extend recursive child requirement resolution to also follow
-cconstraint directives. - Expand
constraints_filesdiscovery to scan.infiles in addition to.txt. - Add specs + fixtures to cover fetching (and missing) constraint files referenced from
.infiles.
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| python/lib/dependabot/python/shared_file_fetcher.rb | Teach shared fetcher to discover/fetch -c constraints from .in files (and recursively). |
| python/spec/dependabot/python/file_fetcher_spec.rb | Add test coverage for -c constraint references in requirements.in. |
| python/spec/fixtures/github/requirements_in_with_constraint.json | Fixture for a requirements.in that references a constraint file via -c. |
| python/spec/fixtures/github/contents_python_requirements_with_in_file.json | Repo-contents fixture including a requirements.in alongside requirements.txt. |
…ched files Since fetch_child_requirement_files now also follows -c directives, constraint files referenced from .in files are already present in child_requirement_files. Filter those out in constraints_files before calling fetch_file_from_host to avoid redundant API calls. Agent-Logs-Url: https://github.com/dependabot/dependabot-core/sessions/12a1f4b1-9847-4bd7-b193-5b9573df1565 Co-authored-by: thavaahariharangit <164553783+thavaahariharangit@users.noreply.github.com>
kbukum1
approved these changes
Mar 31, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What are you trying to accomplish?
This fixes: #14392
When a
requirements.infile references a constraint file via-c(e.g.,-c src/model-requirements.txt), the file fetcher never fetches that constraint file. This causes pip-compile to fail at update time with:Two gaps in
SharedFileFetchercaused this:fetch_child_requirement_filesonly followed-rreferences, not-cconstraints_filesonly scanned.txtfiles for-cdirectives, never.infilesAnything you want to highlight for special attention from reviewers?
Two complementary fixes applied to
shared_file_fetcher.rb:Option B —
fetch_child_requirement_filesnow scans both regex patterns, enabling recursive constraint resolution:Option A —
constraints_filesnow includes.infiles in its scan set:Option B alone handles recursive/transitive constraint references. Option A ensures explicit coverage when building the final constraint file list. Both are needed for full correctness: Option B covers the case where constraints are transitively reachable; Option A covers the case where
constraints_filesis the authoritative gather point.To avoid duplicate
fetch_file_from_hostcalls that would result from Option B already fetching constraint files intochild_requirement_filesand Option A scanning the same paths again,constraints_filesnow filters out any paths already present inchild_requirement_filesbefore fetching:Note: this only fully resolves the issue when at least one
.txtfile exists (the standard pip-compile workflow), sincerequirement_files(which callsconstraints_files) is gated onrequirements_txt_files.any?.How will you know you've accomplished your goal?
Two new test cases added to
file_fetcher_spec.rbcovering the scenario whererequirements.incontains a-creference:DependencyFileNotFoundis raised when the constraint file is missingChecklist