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

Better error message for missing RECORD file #8954

Closed
frenzymadness opened this issue Oct 5, 2020 · 6 comments · Fixed by #9949
Closed

Better error message for missing RECORD file #8954

frenzymadness opened this issue Oct 5, 2020 · 6 comments · Fixed by #9949
Labels
C: error messages Improving error messages state: awaiting PR Feature discussed, PR is needed type: bug A confirmed bug or unintended behavior

Comments

@frenzymadness
Copy link
Contributor

What's the problem this feature will solve?
According to PEP 627, the RECORD file is now optional and its absence indicates that a package should not be uninstalled/upgraded by pip or another tool that relies on its content (see the last paragraph in docs). In Fedora, when you install an RPM package without .dist-info/RECORD file and then you try to uninstall it via pip, you'll get a traceback like this:

# pip uninstall django
Found existing installation: Django 3.0.7
ERROR: Exception:
Traceback (most recent call last):
  File "/usr/lib/python3.9/site-packages/pip/_internal/cli/base_command.py", line 216, in _main
    status = self.run(options, args)
  File "/usr/lib/python3.9/site-packages/pip/_internal/commands/uninstall.py", line 89, in run
    uninstall_pathset = req.uninstall(
  File "/usr/lib/python3.9/site-packages/pip/_internal/req/req_install.py", line 685, in uninstall
    uninstalled_pathset = UninstallPathSet.from_dist(dist)
  File "/usr/lib/python3.9/site-packages/pip/_internal/req/req_uninstall.py", line 535, in from_dist
    for path in uninstallation_paths(dist):
  File "/usr/lib/python3.9/site-packages/pip/_internal/req/req_uninstall.py", line 67, in unique
    for item in fn(*args, **kw):
  File "/usr/lib/python3.9/site-packages/pip/_internal/req/req_uninstall.py", line 85, in uninstallation_paths
    r = csv.reader(FakeFile(dist.get_metadata_lines('RECORD')))
  File "/usr/lib/python3.9/site-packages/pip/_vendor/pkg_resources/__init__.py", line 1432, in get_metadata_lines
    return yield_lines(self.get_metadata(name))
  File "/usr/lib/python3.9/site-packages/pip/_vendor/pkg_resources/__init__.py", line 1420, in get_metadata
    value = self._get(path)
  File "/usr/lib/python3.9/site-packages/pip/_vendor/pkg_resources/__init__.py", line 1616, in _get
    with open(path, 'rb') as stream:
FileNotFoundError: [Errno 2] No such file or directory: '/usr/lib/python3.9/site-packages/Django-3.0.7.dist-info/RECORD'

Describe the solution you'd like
It would be nice to produce a better error message for cases like the one described above. It'd be also nice to use .dist-info/INSTALLER file (if exists) to indicate which tool a user should use to work with the package. Note that the INSTALLER file is also optional according to the PEP.

Additional context
PEP 627: https://www.python.org/dev/peps/pep-0627/
Related to: #8156
Packaging docs: https://packaging.python.org/specifications/recording-installed-packages/

Cc: @hroncok

@uranusjr
Copy link
Member

uranusjr commented Oct 5, 2020

Since pkg_resources is a part of setuptools, this should be done in pypa/setuptools first, and pip will upgrade the vendored copy when it drops Python 2 support (in 21.0), or manually apply the patch for 20.3.

@uranusjr uranusjr added the project: vendored dependency Related to a vendored dependency label Oct 5, 2020
@encukou
Copy link
Contributor

encukou commented Dec 2, 2020

Shouldn't refusing to uninstall/upgrade a package with no RECORD be done in pip?
I think pkg_resources.get_metadata_lines is very correct to report FileNotFoundError if the file is not found.

@encukou
Copy link
Contributor

encukou commented Mar 24, 2021

@uranusjr : could you reconsider the "vendored dependency" label? ISTM that pkg_resources.get_metadata_lines is working correctly.

@uranusjr
Copy link
Member

You’re right, I misidentified the cause. pip should anticipate the RECORD file may be missing on its own.

@uranusjr uranusjr added C: error messages Improving error messages state: awaiting PR Feature discussed, PR is needed type: bug A confirmed bug or unintended behavior and removed project: vendored dependency Related to a vendored dependency labels Mar 24, 2021
@hroncok
Copy link
Contributor

hroncok commented May 5, 2021

I will work on a PR.

@hroncok
Copy link
Contributor

hroncok commented May 5, 2021

Here: #9949

hroncok added a commit to hroncok/pip that referenced this issue May 10, 2021
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Sep 27, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
C: error messages Improving error messages state: awaiting PR Feature discussed, PR is needed type: bug A confirmed bug or unintended behavior
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants