Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

pip-compile annotations should be relative to file they are in #1107

Open
chaoflow opened this issue Apr 15, 2020 · 5 comments
Open

pip-compile annotations should be relative to file they are in #1107

chaoflow opened this issue Apr 15, 2020 · 5 comments
Labels
annotations Related to packages annotations enhancement Improvements to functionality feature Request for a new feature

Comments

@chaoflow
Copy link
Contributor

When pip-compile adds annotations for packages from files included with -r it uses a path relative to the current directory pip-compile is called from, instead of relative to the file it is writing to.

It should be -r base.in not -r requirements/base.in (see below).

This might be solved by #1067.

Environment Versions

  1. Linux
  2. Python version: 3.7.6
  3. pip version: 20.0.2
  4. pip-tools version: 4.5.1

Steps to replicate

requirements/base.in:

ujson

requirements/extra.in:

-r base.in
  1. pip-compile --annotate --no-header --generate-hashes requirements/extra.in

Expected result

extra.txt:

ujson==1.35 \
    --hash=sha256:f66073e5506e91d204ab0c614a148d5aa938bdbf104751be66f8ad7a222f5f86 \
    # via -r base.in

Actual result

extra.txt:

ujson==1.35 \
    --hash=sha256:f66073e5506e91d204ab0c614a148d5aa938bdbf104751be66f8ad7a222f5f86 \
    # via -r requirements/base.in
@atugushev
Copy link
Member

atugushev commented Apr 21, 2020

Hello @chaoflow,

Thanks for the issue! I think it's impossible since pip-compile parses requirements using pip's API (see parse_requirements() function) and pip resolves paths based on current working dir.

pip-compile could re-resolve paths after the parsing, but this solution looks hacky. Would love to hear any other opinions.

@atugushev atugushev added enhancement Improvements to functionality feature Request for a new feature annotations Related to packages annotations labels Apr 21, 2020
@AndydeCleyre
Copy link
Contributor

Could pip-compile

  1. determine the output file
  2. chdir to the output file's parent
  3. do everything it usually does

?

Looks like it can.

I'll try to put up a WIP PR that does this, and improves path determination (fixing the example problem in #1067).

I think I'll need to change the type of output_file from click.File to click.Path (or str), so we can rewrite the path either as absolute, or relative to our destination folder.

Help is always welcome!

@AndydeCleyre

This comment has been minimized.

@AndydeCleyre

This comment was marked as outdated.

AndydeCleyre added a commit to AndydeCleyre/pip-tools that referenced this issue Jun 16, 2022
AndydeCleyre added a commit to AndydeCleyre/pip-tools that referenced this issue Jun 16, 2022
AndydeCleyre added a commit to AndydeCleyre/pip-tools that referenced this issue Oct 3, 2022
AndydeCleyre added a commit to AndydeCleyre/pip-tools that referenced this issue Oct 3, 2022
@AndydeCleyre
Copy link
Contributor

I'm sorry say that #1650 has been rejected. To reduce the incidence of this issue's particular aspect of the relative path problem I'm thinking my personal wrapper scripts and functions should always change the working directory to the output file's folder before running pip-compile.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
annotations Related to packages annotations enhancement Improvements to functionality feature Request for a new feature
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants