-
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
Conversation
Fixes issue #4759 |
tests/functional/test_install_vcs.py
Outdated
@@ -241,21 +241,6 @@ def test_git_with_ambiguous_revs(script): | |||
|
|||
|
|||
@pytest.mark.network | |||
def test_git_works_with_editable_non_origin_repo(script): |
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.
Why has this test been removed?
If there's a behaviour change, it would be wiser to update this test.
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.
Because this test is asserting the (IMO) broken behavior that an error is raised if using an editable install against git repo with no remotes. I updated the test that asserts proper behavior to include the no git remote situation.
This shouldn't be an error (IMO) and therefore we shouldn't have a test asserting that there is an error.
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.
Cool. :)
tests/functional/test_freeze.py
Outdated
""" | ||
).format(remote='file://' + repo_dir).strip() | ||
_check_output(result.stdout, expected) | ||
# check when there are no remotes. Should report local file path. |
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'd like it if you removed this line. :)
news/4759.bugfix
Outdated
@@ -0,0 +1,2 @@ | |||
Rather than report an error for git repositories with no remotes in |
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.
pip freeze now reports URL based on file system location for git repositories with no remotes.
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.
As noted above.
src/pip/_internal/vcs/git.py
Outdated
found_remote = remote | ||
break | ||
url = found_remote.split(' ')[1] | ||
except InstallationError: |
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.
It seems like this try-except should be more tightly bound -- like just around run_command()
.
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.
Also, one thing I'm wondering about is if this PR can possibly mask other issues, since the absence of remotes isn't the only thing that can cause an InstallationError
(non-zero exit status). I'm wondering if there might be a tighter condition than catching all non-zero exit statuses.
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.
Ya we can more tightly scope the error checking. As for masking errors, I'm not sure if git config will return a variety of error codes we can check. But even if it does would it be invalid to report a local path in that case?
src/pip/_internal/vcs/git.py
Outdated
except InstallationError: | ||
# If the above command fails we have no git remotes. 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 comment
The reason will be displayed to describe this comment to others. Learn more.
Does this need to be escaped? I would check elsewhere in the code for how this is done. There seem to be helper functions around this.
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.
We pass location to cwd as is without any escaping. If its good enough for the subprocess execution I'm hoping it is good enough for this string, but I may be missing something important.
@cboylan do you plan to keep working on this one ? |
Yes, I will pick this back up again. Sorry have been mostly away from my computer due to travel and things. Will try to address some of these comments in the near future. |
tests/functional/test_freeze.py
Outdated
...-e git+{remote}@...#egg=version_pkg | ||
... | ||
""" | ||
).format(remote='file://' + repo_dir).strip() |
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.
You'd want to wrap repo_dir with os.path.normcase
here.
news/4759.bugfix
Outdated
@@ -0,0 +1,2 @@ | |||
Pip freeze now reports URL based on file system location for git |
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.
nit: pip is a noun. Use lowercase here. :P
It would be great to get this fixed as we see message like this in our build log: full installed: ----------------------------------------,Error when trying to get requirement for VCS system Command "git config --get-regexp remote..*.url" failed with error code 1 in /opt/stack/new/tempest, falling back to uneditable format,Could not determine repository location of /opt/stack/new/tempest,asn1crypto==0.22.0,Babel==2.3.4,bcrypt==3.1.3,cffi==1.10.0,cliff==2.8.0,cmd2==0.7.5,cryptography==2.0.2,debtcollector==1.17.1,enum34==1.1.6,extras==1.0.0,fasteners==0.14.1,fixtures==3.0.0,funcsigs==1.0.2,functools32==3.2.3.post2,future==0.16.0,idna==2.5,ipaddress==1.0.18,iso8601==0.1.11,jsonschema==2.6.0,linecache2==1.0.0,monotonic==1.3,msgpack-python==0.4.8,netaddr==0.7.19,netifaces==0.10.6,os-testr==0.8.2,oslo.concurrency==3.21.1,oslo.config==4.11.1,oslo.context==2.17.1,oslo.i18n==3.17.1,oslo.log==3.30.1,oslo.serialization==2.20.1,oslo.utils==3.28.1,paramiko==2.2.1,pbr==3.1.1,positional==1.1.2,prettytable==0.7.2,pyasn1==0.3.1,pycparser==2.18,pyinotify==0.9.6,PyNaCl==1.1.2,pyparsing==2.2.0,pyperclip==1.5.27,python-dateutil==2.6.1,python-mimeparse==1.6.0,python-subunit==1.2.0,pytz==2017.2,PyYAML==3.12,rfc3986==1.1.0,six==1.10.0,stestr==1.1.0,stevedore==1.25.1,## !! Could not determine repository location,tempest==17.2.1.dev58,testrepository==0.0.20,testtools==2.3.0,traceback2==1.4.0,unicodecsv==0.14.1,unittest2==1.1.0,urllib3==1.22,wrapt==1.10.10 |
Hello! I am an automated bot and I have noticed that this pull request is not currently able to be merged. If you are able to either merge the |
Rather than report an error for git repositories with no remotes in pip freeze output report the filesystem location with a file:// url. Fixes issue 4759
Reduce scope of try/except when determining git remotes, reword bugfix information, and clean up an unnecessary comment.
This was caught by linting, remove unused exception as e variable in exception handler.
Handle case insensitive filesystems when checking the local path used when git repo has no remotes during testing. Correct case of 'pip' from 'Pip' in the news update.
I made a comment about escaping the URL that doesn't seem to have been addressed: |
To elaborate on my previous comment, I referenced a comment from 8 months ago in which I said the following in reference to escaping paths used in URLs:
I searched the code, and here is an example of one of the helper functions I was referring to-- pip/src/pip/_internal/download.py Lines 474 to 481 in 4ba6769
|
@@ -203,17 +203,24 @@ def obtain(self, dest): | |||
|
|||
def get_url(self, location): | |||
"""Return URL of the first remote encountered.""" |
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.
['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 comment
The 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 git remote -v
be used? That command still has exit status 0 (and so won't result in an InstallationError
) even in the case of no remotes.
# 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 comment
The reason will be displayed to describe this comment to others. Learn more.
See my comment here for another previous review comment, regarding escaping characters.
Hello! I am an automated bot and I have noticed that this pull request is not currently able to be merged. If you are able to either merge the |
When merge? |
When all reviews are addressed. |
I see there are only minor changes required and it could be that the person has already abandoned this pull request/moved on or is simply too busy to work on it. Since the changes are minor, why not simply apply them on your own and just merge it? |
Speaking for myself, when I made review comments, I didn't mean to suggest that if those were addressed, I would be okay with the patch. The comments I made were just the biggest things that popped out at me. There are other things I see, too, now. But if the first things aren't addressed, then I'm not sure it makes sense to add even more things. |
Indeed, that is an option and someone probably will do that if they find the time to do so. |
@pradyunsg @Alexander-Shukaev Can we try to me more effective and do our best to fix this bug? I am not sure if @cboylan still have the energy (and hope) to see this PR merged. On GitHub project members can edit PRs and fix them regardless whom raised the PR in the first place. |
FYI, I posted another PR to address this issue: #6095. It addresses some issues I raised here and takes advantage of some more recent changes to the code (e.g. the new |
Closing as this was addressed by PR #6095 referenced above (now merged). |
Thank @cboylan for this PR! :) |
This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs. |
Rather than report an error for git repositories with no remotes in
pip freeze output report the filesystem location with a file:// url.
Edit by @pradyunsg: Fixes #4759