-
Notifications
You must be signed in to change notification settings - Fork 3.1k
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 freeze of editable git repos reports repo path #4760
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 |
---|---|---|
@@ -0,0 +1,2 @@ | ||
pip freeze now reports URL based on file system location for git | ||
repositories with no remotes. |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,7 +9,7 @@ | |
from pip._vendor.six.moves.urllib import request as urllib_request | ||
|
||
from pip._internal.compat import samefile | ||
from pip._internal.exceptions import BadCommand | ||
from pip._internal.exceptions import BadCommand, InstallationError | ||
from pip._internal.utils.misc import display_path | ||
from pip._internal.utils.temp_dir import TempDirectory | ||
from pip._internal.vcs import VersionControl, vcs | ||
|
@@ -203,17 +203,24 @@ def obtain(self, dest): | |
|
||
def get_url(self, location): | ||
"""Return URL of the first remote encountered.""" | ||
remotes = self.run_command( | ||
['config', '--get-regexp', r'remote\..*\.url'], | ||
show_stdout=False, cwd=location, | ||
) | ||
remotes = remotes.splitlines() | ||
found_remote = remotes[0] | ||
for remote in remotes: | ||
if remote.startswith('remote.origin.url '): | ||
found_remote = remote | ||
break | ||
url = found_remote.split(' ')[1] | ||
try: | ||
remotes = self.run_command( | ||
['config', '--get-regexp', r'remote\..*\.url'], | ||
show_stdout=False, cwd=location, | ||
) | ||
except InstallationError: | ||
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. In a previous review comment here, I made the suggestion that the "file" case not be handled simply by catching any command error. The reason is that this can result in masking various errors and bugs. It would be better if a more targeted approach can be used. Is there a different Git command that can be used that can list the remotes (even if there are 0) without erroring out with a non-zero exit status? For example, why can't the output of |
||
# If the above command fails we have no git remotes or cannot | ||
# determine what they are. Just use the local repo path in that | ||
# case instead. | ||
url = 'file://' + location | ||
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. See my comment here for another previous review comment, regarding escaping characters. |
||
else: | ||
remotes = remotes.splitlines() | ||
found_remote = remotes[0] | ||
for remote in remotes: | ||
if remote.startswith('remote.origin.url '): | ||
found_remote = remote | ||
break | ||
url = found_remote.split(' ')[1] | ||
return url.strip() | ||
|
||
def get_revision(self, location): | ||
|
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.
This docstring should be updated to reflect the new behavior.