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

Impossible to unistall invalid package (with wrong entry point name) #8461

Open
Conchylicultor opened this issue Jun 18, 2020 · 11 comments
Open
Labels
project: vendored dependency Related to a vendored dependency

Comments

@Conchylicultor
Copy link

Conchylicultor commented Jun 18, 2020

Environment

  • pip version: pip 20.1.1
  • Python version: 3.6
  • OS: MacOs

Description

I was experimenting with entry_points and released a test pip package with an invalid "entry-point" name: epot-test:

[tool.poetry.plugins."epot-test.test"]
"abc" = "epot_poetry_test.sub.other:SomeClass"

The pip install failed but pip is now in a bad state. Now it is impossible for me to uninstall the corrupted package.

Expected behavior
I would expect to be able to uninstall invalid packages.

How to Reproduce

pip install epot-poetry-test==0.2.0  # Install the corrupted package

# After the corrupted package is installed, it cannot be uninstalled or replaced:
pip uninstall epot-poetry-test  # Fail
pip epot-poetry-test --upgrade  # Fail

Output

epot-macbookpro% pip3 uninstall epot-poetry-test     
Found existing installation: epot-poetry-test 0.2.0
ERROR: Exception:
Traceback (most recent call last):
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/pip/_vendor/pkg_resources/__init__.py", line 2857, in get_entry_map
    ep_map = self._ep_map
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/pip/_vendor/pkg_resources/__init__.py", line 2815, in __getattr__
    raise AttributeError(attr)
AttributeError: _ep_map

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/pip/_internal/cli/base_command.py", line 188, in _main
    status = self.run(options, args)
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/pip/_internal/commands/uninstall.py", line 86, in run
    auto_confirm=options.yes, verbose=self.verbosity > 0,
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/pip/_internal/req/req_install.py", line 675, in uninstall
    uninstalled_pathset = UninstallPathSet.from_dist(dist)
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/pip/_internal/req/req_uninstall.py", line 571, in from_dist
    console_scripts = dist.get_entry_map(group='console_scripts')
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/pip/_vendor/pkg_resources/__init__.py", line 2860, in get_entry_map
    self._get_metadata('entry_points.txt'), self
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/pip/_vendor/pkg_resources/__init__.py", line 2535, in parse_map
    maps[group] = cls.parse_group(group, lines, dist)
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/pip/_vendor/pkg_resources/__init__.py", line 2510, in parse_group
    raise ValueError("Invalid group name", group)
ValueError: ('Invalid group name', 'epot-test.test')
@triage-new-issues triage-new-issues bot added the S: needs triage Issues/PRs that need to be triaged label Jun 18, 2020
@uranusjr
Copy link
Member

pip can catch the exception, but then it will be unable to remove any entry points from that point on. I think this should be reported and fixed in pypa/setuptools instead.

@uranusjr uranusjr added the project: vendored dependency Related to a vendored dependency label Jun 19, 2020
@triage-new-issues triage-new-issues bot removed the S: needs triage Issues/PRs that need to be triaged label Jun 19, 2020
@Conchylicultor
Copy link
Author

@uranusjr but if the name is invalid, what should setuptools be doing instead of raising an error ?

@uranusjr
Copy link
Member

Maybe ignore the section? That would be the approach that makes sense for pip, but setuptools devs may have other considerations.

@uranusjr
Copy link
Member

Also, how did the invalid section end up in there in the first place? Did pip install it? We should fix that if that’s the case.

@Conchylicultor
Copy link
Author

Also, how did the invalid section end up in there in the first place? Did pip install it? We should fix that if that’s the case.

Yes, the corrupted package was installed by

pip install epot-poetry-test==0.2.0  # Install the corrupted package

It install the package correctly (import seems to work), but the install crashed with a very similar error when installing the entry points.

@Conchylicultor
Copy link
Author

Conchylicultor commented Jun 19, 2020

pip can catch the exception, but then it will be unable to remove any entry points from that point on.

Is it not possible to just delete the lib/python3.6/site-packages/epot_poetry_test-0.3.0.dist-info/entry_point.txt when running pip uninstall ? Why does pip needs to read the file to uninstall entry points ?

To solve the issue, I just manually edited entry_point.txt and then pip uninstall worked correctly. Was there additional side effect that I missed ?

@uranusjr
Copy link
Member

Entry points are also used to generate console_scripts and gui_scripts.

@Conchylicultor
Copy link
Author

Entry points are also used to generate console_scripts and gui_scripts.

But if entry_point.txt crashes during uninstallation, it is also likely that it crashed during installation (it does for this issue), so console_scripts is unlikely to have been installed in the first place.

@jaraco
Copy link
Member

jaraco commented Jul 10, 2020

How did the invalid section end up in there in the first place?

It sounds like Poetry was used to install the entry points, so I'd file an issue with that project that it's allowing installation of entry points in violation of the declared syntax.

@jaraco
Copy link
Member

jaraco commented Jul 10, 2020

In the associated Setuptools ticket, I've also advised that pip should prefer importlib.metadata for reading entry points,and it happens not to be subject to this issue.

@pradyunsg
Copy link
Member

pradyunsg commented Jul 10, 2020

In the associated Setuptools ticket, I've also advised that pip should prefer importlib.metadata for reading entry points,and it happens not to be subject to this issue.

That's a broader task that's a WIP right now (#7413)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
project: vendored dependency Related to a vendored dependency
Projects
None yet
Development

No branches or pull requests

4 participants