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
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
18 changes: 18 additions & 0 deletions docs/html/cli/pip_freeze.rst
Original file line number Diff line number Diff line change
Expand Up @@ -72,3 +72,21 @@ Examples

env1\bin\python -m pip freeze > requirements.txt
env2\bin\python -m pip install -r requirements.txt


Fixing "Permission denied:" errors
==================================

The purpose of this section of documentation is to provide practical
suggestions to users seeing a `"Permission denied" error <https://github.com/pypa/pip/issues/8418>`__ on ``pip freeze``.

This error occurs, for instance, when the command is installed only for another
user, and the current user doesn't have the permission to execute the other
user's command.

To solve that issue, you can try one of the followings:

- Install the command for yourself (e.g. in your home directory).
- Ask the system admin to allow this command for all users.
- Check and correct the PATH variable of your own environment.
- Check the `ACL (Access-Control List) <https://en.wikipedia.org/wiki/Access-control_list>`_ for this command.
1 change: 1 addition & 0 deletions news/8418.bugfix.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fix ``pip freeze`` permission denied error in order to display an understandable error message and offer solutions.
1 change: 1 addition & 0 deletions news/8418.doc.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Add a section in the documentation to suggest solutions to the ``pip freeze`` permission denied issue.
12 changes: 12 additions & 0 deletions src/pip/_internal/vcs/versioncontrol.py
Original file line number Diff line number Diff line change
Expand Up @@ -684,6 +684,18 @@ def run_command(
raise BadCommand(
f'Cannot find command {cls.name!r} - do you have '
f'{cls.name!r} installed and in your PATH?')
except PermissionError:
# errno.EACCES = Permission denied
# This error occurs, for instance, when the command is installed
# only for another user. So, the current user don't have
# permission to call the other user command.
raise BadCommand(
f"No permission to execute {cls.name!r} - install it "
f"locally, globally (ask admin), or check your PATH. "
f"See possible solutions at "
f"https://pip.pypa.io/en/latest/reference/pip_freeze/"
f"#fixing-permission-denied."
)

@classmethod
def is_repository_directory(cls, path):
Expand Down
21 changes: 21 additions & 0 deletions tests/unit/test_vcs.py
Original file line number Diff line number Diff line change
Expand Up @@ -303,6 +303,27 @@ def test_version_control__get_url_rev_and_auth__no_revision(url):
assert 'an empty revision (after @)' in str(excinfo.value)


@pytest.mark.parametrize("vcs_cls", [Bazaar, Git, Mercurial, Subversion])
@pytest.mark.parametrize(
"exc_cls, msg_re",
[
(FileNotFoundError, r"Cannot find command '{name}'"),
(PermissionError, r"No permission to execute '{name}'"),
],
ids=["FileNotFoundError", "PermissionError"],
)
def test_version_control__run_command__fails(vcs_cls, exc_cls, msg_re):
"""
Test that ``VersionControl.run_command()`` raises ``BadCommand``
when the command is not found or when the user have no permission
to execute it. The error message must contains the command name.
"""
with patch("pip._internal.vcs.versioncontrol.call_subprocess") as call:
call.side_effect = exc_cls
with pytest.raises(BadCommand, match=msg_re.format(name=vcs_cls.name)):
vcs_cls.run_command([])


@pytest.mark.parametrize('url, expected', [
# Test http.
('bzr+http://bzr.myproject.org/MyProject/trunk/#egg=MyProject',
Expand Down