Skip to content
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

Fix/8418 permission denied hg #9442

Merged

Conversation

laurent-laporte-pro
Copy link
Contributor

Fix #8418

This change will fix pip freeze permission denied error in order to display an understandable error message and offer solutions.

Add a section in the documentation to suggest solutions to the pip freeze permission denied issue.

Correct the coding-style in VersionControl.run_command() to use f-string instead of .format(**locals()).

@sbidoul
Copy link
Member

sbidoul commented Jan 11, 2021

Thanks for addressing this.

By chance do you know why the issue does not surface in other commands that would attempt to use hg (such as pip install or pip wheel) ? It is somewhat surprising that only pip freeze shows the stack trace in such case.

Regarding the documentation update, it feels somewhat out of place in the pip freeze page, which otherwise does not talk about VCS. The place that talks bout VCS is the pip install page which is not ideal either if the error occurs in pip freeze. Perhaps we should not go that far and consider it is not the purpose of the pip documentation to explain how to resolve VCS installation issues ?

@laurent-laporte-pro
Copy link
Contributor Author

laurent-laporte-pro commented Jan 12, 2021

Why hg fails but not the other commands?

Here's how I got the problem with Mercurial:

The hg command wasn't available on my Mac, so I downloaded SourceTree and installed it locally, in my user account. Then I just added a symbolic link in /usr/local/bin.

Subsequently, I created a new user account on my Mac. On this account, the hg command is accessible because it is a symbolic link installed globally in /usr/local/bin, but the target of the link wasn't. This is why I got the "permission denied" error.

When you download SourceTree, you have a simple ZIP file that you install as you want, there is no installer that would prompt you to install the application globally. I think there are a lot of Mac (or Windows) users who want to "try" Mercurial, and therefore install it locally, not globally.

We don't have this kind of problem with Git or Subversion because these two tools are already installed on Mac, even if the version is a bit old. Regarding Bazaar, I didn't get an error because this command is simply not installed.

As a conclusion, the issue with pip freeze can also happen with bzr (on Mac), or the other commands in Windows since those commands are not pre-installed.

Why pip freeze fails but pip install or pip wheel don't?

Actually, when I posted my pull request I didn't know why pip install and pip wheel work. I quickly tested these commands before posting, and only pip freeze has an issue.

Further analysis shows:

  • that only the freeze.get_requirement_info function calls the VcsSupport.get_backend_for_dir function: this function searches for the VCS that best corresponds to the directory passed as a parameter.
  • the 'pip freeze' and 'pip wheel' functions determine which VCS to use based on the download url. So they use the function VcsSupport.get_backend_for_scheme instead.

Documentation

The documentation update was suggested by Tzu-ping Chung (See message). Since it is a pip freeze-only issue, I decided to write it in docs/man/commands/freeze.rst.

If you prefer, I can move it under Installing from local packages section.

The section Ensuring Repeatability is also a good candidate.

@laurent-laporte-pro
Copy link
Contributor Author

@sbidoul @uranusjr any news about thaïs PR?

@faph
Copy link

faph commented Feb 12, 2021

Could I just check, when is this likely to be released?

@uranusjr
Copy link
Member

The next feature release is scheduled in April, so don't hold your breath for it just yet.

@BrownTruck
Copy link
Contributor

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 master branch into this pull request or rebase this pull request against master then it will be eligible for code review and hopefully merging!

@BrownTruck BrownTruck added the needs rebase or merge PR has conflicts with current master label Feb 21, 2021
@pypa-bot pypa-bot removed the needs rebase or merge PR has conflicts with current master label Feb 26, 2021
@uranusjr
Copy link
Member

uranusjr commented Mar 24, 2021

Oops, the diff seems borked. Try

git fetch origin/master
git checkout fix/8418-permission-denied-hg
git rebase origin/master
git push --force

@BrownTruck
Copy link
Contributor

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 master branch into this pull request or rebase this pull request against master then it will be eligible for code review and hopefully merging!

@BrownTruck BrownTruck added the needs rebase or merge PR has conflicts with current master label Apr 3, 2021
@pypa-bot pypa-bot removed the needs rebase or merge PR has conflicts with current master label Apr 3, 2021
@uranusjr uranusjr merged commit 4e835c0 into pypa:main Apr 3, 2021
@pradyunsg
Copy link
Member

Thanks @laurent-laporte-pro! ^>^

@laurent-laporte-pro laurent-laporte-pro deleted the fix/8418-permission-denied-hg branch April 4, 2021 19:38
@cipri-tom
Copy link

While the new version fixes the problem, I'd like to add another case of when this error occurs:

When the user has a directory that is not-executable to them in their $PATH, then the PermissionError error is raised, instead of FileNotFoundError. This is due to the subprocess.Popen(['hg', 'root']) call in run_command(), which behaves according to this bug: https://bugs.python.org/issue25481

In my case, a faulty installation of cuda has added /usr/local/cuda-10.2/bin to all users $PATH, without making cuda-10.2 nor cuda-10.2/bin executable.

@uranusjr
Copy link
Member

A new issue and accompanying PR would be appreciated.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Sep 29, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

pip freeze returns "Permission denied: 'hg'" after using pip install -e
8 participants