jazzband / pip-tools

A set of tools to keep your pinned Python dependencies fresh.
https://pip-tools.rtfd.io
BSD 3-Clause "New" or "Revised" License
7.69k stars 610 forks source link

Expose option to use relative paths when converting -e modules from .in to .txt #1968

Closed theahura closed 1 year ago

theahura commented 1 year ago

What's the problem this feature will solve?

My requirements.in file has an editable install, -e ../../foo/bar. When this gets converted to requirements.txt with piptools, it turns into -e file:///home/theahura/path/to/foo/bar.

The issue is that if anyone else on my team wants to use this requirements.txt, it will break; and if they recompile, the requirements.txt gets an unnecessary update.

Describe the solution you'd like

Turns out that relative path editable installs work just fine in a requirements.txt. It's possible to just have -e ../../foo/bar in the requirements.txt AND the requirements.in. So one option would be:

pip-compile requirements.in --relative_editable_installs=true

which would output the relative path to requirements.txt instead of the absolute one.

Alternative Solutions

Currently I hardcode any relative editable paths in my requirements.txt, which works fine from a pip-install perspective. Unfortunately, pip-tools will then go and update it back to the absolute path whenever a recompile occurs

atugushev commented 1 year ago

Does -e file:../../foo/bar work for you? See also https://github.com/jazzband/pip-tools/issues/204.

theahura commented 1 year ago

fantastic! that works great, thank you for the quick turnaround!

AndydeCleyre commented 1 year ago

FWIW the original form (-e ../../foo/bar) works in my feature/relpaths-post-6.8.0 branch, which can be tested for example with pipx:

$ pipx run --spec 'pip-tools @ git+https://github.com/AndydeCleyre/pip-tools@feature/relpaths-post-6.8.0' pip-compile