豆豆友情提示:这是一个非官方 GitHub 代理镜像,主要用于网络测试或访问加速。请勿在此进行登录、注册或处理任何敏感信息。进行这些操作请务必访问官方网站 github.com。 Raw 内容也通过此代理提供。
Skip to content

[python][pip-compile] Fix constraint files (-c) in .in files not being fetched#14588

Merged
thavaahariharangit merged 6 commits intomainfrom
copilot/fix-pip-compile-constraint-fetch
Mar 31, 2026
Merged

[python][pip-compile] Fix constraint files (-c) in .in files not being fetched#14588
thavaahariharangit merged 6 commits intomainfrom
copilot/fix-pip-compile-constraint-fetch

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Mar 31, 2026

What are you trying to accomplish?

This fixes: #14392

When a requirements.in file 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:

InstallationError("Could not open requirements file: [Errno 2] No such file or directory: 'dependabot_tmp_dir/src/model-requirements.txt'")

Two gaps in SharedFileFetcher caused this:

  1. fetch_child_requirement_files only followed -r references, not -c
  2. constraints_files only scanned .txt files for -c directives, never .in files

Anything you want to highlight for special attention from reviewers?

Two complementary fixes applied to shared_file_fetcher.rb:

Option Bfetch_child_requirement_files now scans both regex patterns, enabling recursive constraint resolution:

paths = content.scan(CHILD_REQUIREMENT_REGEX).flatten +
        content.scan(CONSTRAINT_REGEX).flatten

Option Aconstraints_files now includes .in files in its scan set:

all_requirement_files = requirements_txt_files +
                        child_requirement_txt_files +
                        requirements_in_files

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_files is the authoritative gather point.

To avoid duplicate fetch_file_from_host calls that would result from Option B already fetching constraint files into child_requirement_files and Option A scanning the same paths again, constraints_files now filters out any paths already present in child_requirement_files before fetching:

already_fetched_names = child_requirement_files.map(&:name)
constraints_paths
  .reject { |path| already_fetched_names.include?(path) }
  .map { |path| fetch_file_from_host(path) }

Note: this only fully resolves the issue when at least one .txt file exists (the standard pip-compile workflow), since requirement_files (which calls constraints_files) is gated on requirements_txt_files.any?.

How will you know you've accomplished your goal?

Two new test cases added to file_fetcher_spec.rb covering the scenario where requirements.in contains a -c reference:

  • Verifies the constraint file is included in the fetched file set
  • Verifies DependencyFileNotFound is raised when the constraint file is missing

Checklist

  • I have run the complete test suite to ensure all tests and linters pass.
  • I have thoroughly tested my code changes to ensure they work as expected, including adding additional tests for new functionality.
  • I have written clear and descriptive commit messages.
  • I have provided a detailed description of the changes in the pull request, including the problem it addresses, how it fixes the problem, and any relevant details about the implementation.
  • I have ensured that the code is well-documented and easy to understand.

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
@thavaahariharangit thavaahariharangit marked this pull request as ready for review March 31, 2026 13:47
@thavaahariharangit thavaahariharangit requested a review from a team as a code owner March 31, 2026 13:47
Copilot AI review requested due to automatic review settings March 31, 2026 13:47
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 -c constraint directives.
  • Expand constraints_files discovery to scan .in files in addition to .txt.
  • Add specs + fixtures to cover fetching (and missing) constraint files referenced from .in files.

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.

Comment thread python/lib/dependabot/python/shared_file_fetcher.rb
…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>
@thavaahariharangit thavaahariharangit merged commit e8d0300 into main Mar 31, 2026
124 of 125 checks passed
@thavaahariharangit thavaahariharangit deleted the copilot/fix-pip-compile-constraint-fetch branch March 31, 2026 17:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[python][pip-compile] Constraint files (-c) in .in files are not fetched by file fetcher

4 participants