Skip to content

pip-compile breaks when using paths outside of the current directory #2231

@thedoctorjtd

Description

@thedoctorjtd

In commit 809239a the logic for relative/absolute path detection was reworked, however there seem to be some issues with it.

When running pip compile with pip-compile requirements.in the following scenarios will cause errors:

  • Having a -r with a relative path (-r ../otherProject/requirements.in)
  • Having a -r with an absolute path (-r D:\code\otherProject\requirements.in)

Both of these break with the same error:

suffix = file_path.relative_to(pathlib.Path.cwd()).as_posix()
  File "C:\Python310\lib\pathlib.py", line 818, in relative_to
    raise ValueError("{!r} is not in the subpath of {!r}"

I understand why these specificity changes were necessary to prevent possible ambiguity, however there should be a fallback when the preferred path does not exist vs an error.

Environment Versions

  1. OS Type: - Win 11
  2. Python version: Python 3.10.11
  3. pip version: pip 25.2
  4. pip-tools version: pip-compile, version 7.5.0

Steps to replicate

Run pip compile with pip-compile requirements.in with the following scenarios:

  • Having a -r with a relative path (-r ../otherProject/requirements.in)
  • Having a -r with an absolute path (-r D:\code\otherProject\requirements.in)

Expected result

pip-compile would use the files specified since there were not other options which were more preferred.

Actual result

suffix = file_path.relative_to(pathlib.Path.cwd()).as_posix()
  File "C:\Python310\lib\pathlib.py", line 818, in relative_to
    raise ValueError("{!r} is not in the subpath of {!r}"

Metadata

Metadata

Assignees

Labels

Type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions