Skip to content

Commit

Permalink
fixup! Provide a better error message when uninstalling packages with…
Browse files Browse the repository at this point in the history
…out dist-info/RECORD
  • Loading branch information
hroncok committed May 10, 2021
1 parent 565dd13 commit 2203bc8
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 6 deletions.
2 changes: 1 addition & 1 deletion news/8954.feature.rst
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ When pip is asked to uninstall a project without the dist-info/RECORD file
it will no longer traceback with FileNotFoundError,
but it will provide a better error message instead, such as::

ERROR: Cannot uninstall foobar 0.1, RECORD file not found. You might be able to recover from this via: `pip install --force-reinstall --no-deps foobar==0.1`.
ERROR: Cannot uninstall foobar 0.1, RECORD file not found. You might be able to recover from this via: 'pip install --force-reinstall --no-deps foobar==0.1'.

When dist-info/INSTALLER is present and contains some useful information, the info is included in the error message instead::

Expand Down
4 changes: 2 additions & 2 deletions src/pip/_internal/req/req_uninstall.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,8 +90,8 @@ def uninstallation_paths(dist):
raise ValueError()
except (OSError, StopIteration, ValueError):
dep = '{}=={}'.format(dist.project_name, dist.version)
msg += (' You might be able to recover from this via: '
'`pip install --force-reinstall --no-deps {}`.'.format(dep))
msg += (" You might be able to recover from this via: "
"'pip install --force-reinstall --no-deps {}'.".format(dep))
else:
msg += ' Hint: The package was installed by {}.'.format(installer)
raise UninstallationError(msg) from missing_record_exception
Expand Down
6 changes: 3 additions & 3 deletions tests/functional/test_uninstall.py
Original file line number Diff line number Diff line change
Expand Up @@ -511,9 +511,9 @@ def test_uninstall_without_record_fails(script, data, installer):
expected_error_message = ('ERROR: Cannot uninstall simple.dist 0.1, '
'RECORD file not found.')
if not isinstance(installer, str) or not installer.strip() or installer == 'pip':
expected_error_message += (' You might be able to recover from this via: '
'`pip install --force-reinstall --no-deps '
'simple.dist==0.1`.')
expected_error_message += (" You might be able to recover from this via: "
"'pip install --force-reinstall --no-deps "
"simple.dist==0.1'.")
elif installer:
expected_error_message += (' Hint: The package was installed by '
'{}.'.format(installer))
Expand Down

0 comments on commit 2203bc8

Please sign in to comment.