-
-
Notifications
You must be signed in to change notification settings - Fork 610
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
Fixup relative and absolute path handling #1329
Closed
Closed
Conversation
This file contains 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
This comment has been minimized.
This comment has been minimized.
This was referenced Feb 22, 2021
This comment has been minimized.
This comment has been minimized.
AndydeCleyre
force-pushed
the
bugfix/1107
branch
from
February 23, 2021 08:46
fb0190e
to
b48444c
Compare
3 tasks
AndydeCleyre
force-pushed
the
bugfix/1107
branch
2 times, most recently
from
February 24, 2021 21:40
dde20b5
to
ab47233
Compare
AndydeCleyre
changed the title
[WIP] Rewrite input and output file paths as either absolute or relative to the output
[WIP] Rewrite input file paths as relative to the output file, or as absolutes if using stdout; and extra path fixes
Feb 24, 2021
This comment has been minimized.
This comment has been minimized.
AndydeCleyre
changed the title
[WIP] Rewrite input file paths as relative to the output file, or as absolutes if using stdout; and extra path fixes
Rewrite input file paths as relative to the output file, or as absolutes if using stdout; and extra path fixes
Feb 24, 2021
This comment has been minimized.
This comment has been minimized.
AndydeCleyre
changed the title
Rewrite input file paths as relative to the output file, or as absolutes if using stdout; and extra path fixes
[WIP] Rewrite input file paths as relative to the output file, or as absolutes if using stdout; and extra path fixes
Feb 25, 2021
atugushev
reviewed
Feb 25, 2021
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
AndydeCleyre
force-pushed
the
bugfix/1107
branch
from
March 9, 2021 00:19
ab47233
to
4fae968
Compare
AndydeCleyre
changed the title
[WIP] Rewrite input file paths as relative to the output file, or as absolutes if using stdout; and extra path fixes
Fixup relative and absolute path handling:
Mar 9, 2021
AndydeCleyre
force-pushed
the
bugfix/1107
branch
from
March 9, 2021 00:45
4fae968
to
e246ee9
Compare
AndydeCleyre
changed the title
Fixup relative and absolute path handling:
Fixup relative and absolute path handling
Mar 9, 2021
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
AndydeCleyre
force-pushed
the
bugfix/1107
branch
from
March 9, 2021 01:45
e246ee9
to
da86792
Compare
This comment has been minimized.
This comment has been minimized.
For compatibility with pip<21.1
e.g. ../../rawr#egg=rawr-cli
... to properly set .extras
This fixes false-positive _was_relative assignments for some direct references like: ptrender[yaml] @ file:///home/andy/Code/ptrender
As we always want to set that True
Preserve ireq.constraint and _source_ireqs
At this code point we currently expect the original ireq.extras to be an empty set every time, so this does not change any current behavior. But if in the future ireqs with already parsed extras are passed, it should now preserve those.
AndydeCleyre
force-pushed
the
bugfix/1107
branch
from
June 16, 2022 19:18
1d136d0
to
90a7097
Compare
4 tasks
Closing in favor of #1650 |
AndydeCleyre
added a commit
to AndydeCleyre/pip-tools
that referenced
this pull request
Oct 3, 2022
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.
Initial Summary (Outdated)
Summary, Take 2 (also outdated)
Fixup relative and absolute path handling:
These changes have been made with the general guideline of
storing paths as absolute as soon as we can, and rendering
them as relative or absolute as needed.
--upgrade-package
relative to output fileI think: relative to output file if passed as relative, absolute if passed as absolute, pathless if passed as pathlessgit+file:
ireq from source filepip
doesn't support relative paths in that form)Itemized Changes by File
utils.py
format_requirement
:str
kwargfrom_dir
:from_dir
).path_to_url
for abs paths.Function
abs_ireq
:Context manager
working_dir
:Function
fragment_string
:pip_compat.py
parse_requirements
:str
kwargfrom_dir
toparse_requirements
.If left to its default,
None
, the parent of the source file is used.Either way it's passed to
abs_ireq
, so any yielded local ireqshave absolute
.link
s, and some have._was_relative
.install_req_from_parsed_requirement
is called from a sensible folder,to better resolve relative paths; and try to detect if each ireq was initially relative,
to "manually" mark the resulting (absolute) ireq with
_was_relative
.compile.py
Click
argument type for the output file fromFile
toPath
.When
Click
'sFile
object is initialized with the absolute path,that full path is preserved as the
.name
attribute. So we now instantiatethe output
File
ourselves after resolving its absolute path.src_files
to their absolute paths.ensure it's properly adjacent to the input,
and stay safer and more predictable when the basename has no dot and the path does,
or the input file ends in
.txt
(see Choose an approach for coherent path handling #1067, pip-compile annotations should be relative to file they are in #1107, and tests below).abs_ireq
when collectingupgrade_install_reqs
(--upgrade-package
),passing the invocation dir as
from_dir
.setup.py
install_requires
,given the discussion @ https://discuss.python.org/t/what-is-the-correct-interpretation-of-path-based-pep-508-uri-reference/2815/18
from_dir
is passed toparse_requirements
when parsing from
setup.py
or stdin, which really parses a temp file.This means
setup.py
's parent folder, or the invocation dir if the source is stdin.writer.py
comes_from_line_project_re
pattern for parsing and rewritingcomes_from
str
s that point tosetup.py
s andpyproject.toml
s.strip_comes_from_line_re
:comes_from_line_re
,with named groups for
opts
(-r
/-c
),path
, andline_num
._comes_from_as_string
:str
kwargfrom_dir
.If the
ireq.comes_from
is already astr
andfrom_dir
is passed,in addition to stripping the line number as before, rewrite the path as relative.
comes_from_line_project_re
matches._format_requirement
:ireq
has._was_relative
and the output is a file,pass the output file's parent as
from_dir
toformat_requirement
,ensuring the written path for the
ireq
is relative in that case.from_dir
to_comes_from_as_string
.test_cli_compile.py
test_relative_local_package
file:
or.
.test_input_file_with_txt_extension
.txt
to a separate output file (*.txt.txt
),without overwriting the input file.
test_input_file_without_extension_and_dotted_path
into an input-adjacent file with
.txt
as the extension.test_annotation_relative_paths
reqs.in
files use paths relative to thereqs.txt
.test_local_vcs_package
test_duplicate_reqs_combined
path_to_url
to detect the normalized package path in URL form.test_writer.py
writer
fixture:OutputWriter
,rather than passing the click
ctx
entry (now just aPath
).test_write_header
:writer.click_ctx.params["output_file"]
(now just aPath
), rather thanchecking that for a
.name
.test_iter_lines__hash_missing
:test_iter_lines__no_warn_if_only_unhashable_packages
:test_format_requirement_annotation_source_ireqs
test_utils.py
test_format_requirement_editable_local_path
test_working_dir
test_local_abs_ireq_preserves_source_ireqs
Changelog-friendly one-liners:
file:
,<vcs>+file:
, or.
.Changelog-friendly one-liners:
file:
,<vcs>+file:
, or.
.pip-compile
will interpret relative paths in an input file as relative to that input file, rather than the current folder, if--read-relative-to-input
is passed.pip-compile
will reconstruct relative req paths as relative to the output file, rather than the current folder, if--write-relative-to-output
is passed.pip-sync
will interpret relative paths in an input file as relative to that input file, rather than the current folder, if--read-relative-to-input
is passed.pkg[extra1,extra2]
.Contributor checklist