-
-
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
Make editable requirements use relative paths where appropriate. #507
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,6 +2,7 @@ | |
from __future__ import (absolute_import, division, print_function, | ||
unicode_literals) | ||
|
||
import os | ||
import sys | ||
from itertools import chain, groupby | ||
from collections import OrderedDict | ||
|
@@ -61,13 +62,30 @@ def make_install_requirement(name, version, extras, constraint=False): | |
return InstallRequirement.from_line('{}{}=={}'.format(name, extras_string, str(version)), constraint=constraint) | ||
|
||
|
||
def is_subdirectory(base, directory): | ||
""" | ||
Return True if directory is a child directory of base | ||
""" | ||
base = os.path.join(os.path.realpath(base), '') | ||
directory = os.path.join(os.path.realpath(directory), '') | ||
|
||
return os.path.commonprefix([base, directory]) == base | ||
|
||
|
||
def format_requirement(ireq, marker=None): | ||
""" | ||
Generic formatter for pretty printing InstallRequirements to the terminal | ||
in a less verbose way than using its `__str__` method. | ||
""" | ||
if ireq.editable: | ||
line = '-e {}'.format(ireq.link) | ||
path = ireq.link.path | ||
if ireq.link.scheme == 'file' and is_subdirectory(os.getcwd(), path): | ||
# If the ireq.link is relative to the current directory then output a relative path | ||
path = 'file:' + os.path.join('.', os.path.relpath(path)) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think that there are Windows idiosyncrasies that would be taken care of if you used pathname2url (like in the original pip code you pointed at:
this should also help the failing Windows build. |
||
else: | ||
path = ireq.link | ||
|
||
line = '-e {}'.format(path) | ||
else: | ||
line = str(ireq.req).lower() | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
import json | ||
import os | ||
from functools import partial | ||
|
||
from pip._vendor.packaging.version import Version | ||
|
@@ -106,3 +107,18 @@ def from_line(): | |
@fixture | ||
def from_editable(): | ||
return InstallRequirement.from_editable | ||
|
||
|
||
@fixture | ||
def fake_package_dir(): | ||
return os.path.join(os.path.split(__file__)[0], 'fixtures', 'fake_package') | ||
|
||
|
||
@fixture | ||
def small_fake_package_dir(): | ||
return os.path.join(os.path.split(__file__)[0], 'fixtures', 'small_fake_package') | ||
|
||
|
||
@fixture | ||
def minimal_wheels_dir(): | ||
return os.path.join(os.path.split(__file__)[0], 'fixtures', 'minimal_wheels') | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. perfect |
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.
I'm not certain that cwd is a correct base here. I could call pip-compile outside of the directory which contains the requirement file, and that would leave us with a non installable compiled requirements.txt. Am I mistaken in thinking that the base should always be relative to the directory of the input file ?