-
-
Notifications
You must be signed in to change notification settings - Fork 611
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
PEP 440 Direct Reference support #1392
PEP 440 Direct Reference support #1392
Conversation
FYI I installed
And |
Codecov Report
@@ Coverage Diff @@
## master #1392 +/- ##
=======================================
Coverage 99.67% 99.67%
=======================================
Files 33 33
Lines 3037 3044 +7
Branches 327 330 +3
=======================================
+ Hits 3027 3034 +7
Misses 5 5
Partials 5 5
Continue to review full report at Codecov.
|
To help you understand this fix/enhancement, from the master branch, try the following tests: Test 1In "requests @ git+git://github.com/psf/[email protected]" In print(out.stderr)
assert "requests @ git+git://github.com/psf/[email protected]" in out.stderr This test will fail because it is missing the direct reference, inside the output there is:
Also, note that there is no Test 2In def test_combine_install_requirements_direct_ref(repository, from_line):
first_dep = from_line("git+ssh://****@bitbucket.org/private-bucket/[email protected]", comes_from="-r requirements.in")
second_dep = from_line("git+ssh://****@bitbucket.org/private-bucket/[email protected]", comes_from="-r dev-requirements.in")
combined = combine_install_requirements(repository, [first_dep, second_dep])
assert combined.comes_from == first_dep.comes_from # shortest string
assert set(combined._source_ireqs) == {first_dep, second_dep}
assert str(combined.req.specifier) == "" This is failing because both git URLs are missing a specifier. You can make the test pass by specifying a direct reference or an egg:
For example this works: def test_combine_install_requirements_direct_ref(repository, from_line):
first_dep = from_line("enums @ git+ssh://****@bitbucket.org/private-bucket/[email protected]", comes_from="-r requirements.in")
second_dep = from_line("git+ssh://****@bitbucket.org/private-bucket/[email protected]#egg=enums", comes_from="-r dev-requirements.in")
combined = combine_install_requirements(repository, [first_dep, second_dep])
assert combined.comes_from == first_dep.comes_from # shortest string
assert set(combined._source_ireqs) == {first_dep, second_dep}
assert str(combined.req.specifier) == "" Conclusion
Because
I hope this helps to make it clearer and I am looking forward to reading your feedback! |
Hey, you reached out last week over at #1329, and today I was able to start looking at this. It's possible that, aside from changes to tests, all that's needed on top of my WIP PR is: diff --git a/piptools/utils.py b/piptools/utils.py
index 4f15729..2f81af1 100644
--- a/piptools/utils.py
+++ b/piptools/utils.py
@@ -1,6 +1,7 @@
import collections
import itertools
import os
+import re
import shlex
from contextlib import contextmanager, suppress
from typing import (
@@ -137,6 +138,8 @@ def format_requirement(
ireq.local_file_path, from_dir
).replace(os.path.sep, "/")
ireq_url = f"{path_url}{fragment_string(ireq)}"
+ if not re.match(r"^#(|.*&)egg=.*", fragment_string(ireq)) and ireq.name:
+ ireq_url = f"{ireq.name} @ {ireq_url}"
line = f"-e {ireq_url}" if ireq.editable else ireq_url
if marker: I'll leave this diff right here, and if #1329 is ever done this will help me merge. |
@AndydeCleyre Thanks for your suggestion. Yeah it looks like that would work, the tests I've added will help you find out. :) |
@FlorentJeannot I guess that's necessary to include these four test cases to ensure this continues to work in the future. Anyway looks good to me. (A github archive The output should be the same as the input:
|
Hey @luzfcb, this PR would definitely fix your issue! :) Concerning your suggestion, I think the existing tests are enough. Could you explain your point of view? @atugushev Do you know when this PR will be reviewed? Thanks! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for addressing suggestions 👍
As a side note, this transformation feels confusing:
example @ https://example.com/example.zip#egg=example
→
https://example.com/example.zip#egg=example
I'd prefer the opposed instead:
https://example.com/example.zip#egg=example
→
example @ https://example.com/example.zip
AFAIK egg fragment appears to be discouraged for direct references. However, pip is going to refactor this within pypa/pip#1289, so it would make sense to address that later, as soon as the issue is resolved.
Hello @atugushev, Thank you for your feedback and your approval for this PR. Regarding your side note, I agree with you and I'll happily provide a PR for this when pypa/pip#1289 will be resolved. |
We should also support extras, see #1450 for details. Would you like to address it here or in a following up PR? |
I will do it in another PR since this one has been approved. Also I have another question. It seems that |
Thanks for the PR! Awesome job 👍🏻
Could you elaborate on how code in |
@atugushev Thanks 👍 Happy to contribute to this project 😄 So I believe So for example if you do this: Even though it was specified with an egg, the output of
|
Ideally, we should. Feel free to shoot a PR if you think it's doable. |
Will do! Edit: @atugushev Done! #1455 |
This PR adds PEP 440 Direct References support to fix #1391.
pip
can support direct references, so the egg can be omitted inside the URL (see the code from pip).In my projects which have git repositories specified as dependencies, without a direct reference or an egg, pip was not able to determine the package name, which was causing an issue during
pip-sync
(inside the merge, comparing two identical requirements from two different files).Also, inside
setup.py
,install_requires
must be written with a direct reference (pip
fails to install the dependencies if it is not using a direct reference).pip-tools
was ignoring the direct reference, so it was not generating therequirements.txt
correctly. See my example:Changelog-friendly one-liner: PEP 440 Direct References support
Contributor checklist