question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

pkg_resources: Wrong exception raised on parse error

See original GitHub issue

Due to https://github.com/pypa/setuptools/pull/2137 parse errors raise pkg_resources.extern.packaging.requirements.InvalidRequirement instead of packaging.requirements.InvalidRequirement.

I believe this is happening because pkg_resources imports the vendored packaging.requirements module.

Reproducer:

from pkg_resources import Requirement
from packaging.requirements import InvalidRequirement
from pkg_resources.extern.packaging.requirements import InvalidRequirement as ExternInvalidRequirement

try:
    Requirement.parse(".")
except InvalidRequirement as err:
    print(type(err))
except ExternInvalidRequirement  as err:
    print(type(err))
$ python test.py
<class 'pkg_resources.extern.packaging.requirements.InvalidRequirement'>

Issue Analytics

  • State:open
  • Created 3 years ago
  • Reactions:2
  • Comments:5 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
lkollarcommented, Jul 10, 2020

What makes you think that’s the wrong exception?

Sorry, I should have worded this differently. I think it’s more correct to say, it is not immediately obvious that setuptools vendors packaging and thus the exception type is based on the internal vendoring layout. I think this can surprise users who are not familiar with the fact the all dependencies are vendored. It also exposes an implementation detail on the public API.

I agree that exposing RequirementParseError or some other custom exception would be nicer, but I’m sure I’m missing some history here as @jaraco had a reason not do this in #2137.

0reactions
Eric-Arellanocommented, Jul 10, 2020

The other option I see

The third option, imo, is to restore RequirementParseError. It looks like it was only about 9 lines of code. By restoring it, you may be able to avoid a more complex change to your vendoring setup. (I know vendoring can be tricky - we vendor pip with https://github.com/pantsbuild/pex.)

Read more comments on GitHub >

github_iconTop Results From Across the Web

python - Why am I getting these tracebacks? - Stack Overflow
I noticed in the first traceback a VersionConflict was raised. Does this mean I installed the wrong ParlAi version? Any sort of help...
Read more >
Requirements for custom_component not installing anymore
Hi, I've created an custom components this winter and have been using it since. However some others are tying to install it without...
Read more >
Source code for dagster._core.definitions.utils
_core.errors import DagsterInvalidDefinitionError, ... value except Exception: pass if not valid: raise DagsterInvalidDefinitionError( 'Invalid value for ...
Read more >
pkg_resources Module — Galaxy Code documentation
Return name entry point of group for dist or raise ImportError ... class pkg_resources. ... to an exception instance describing the error that...
Read more >
https://svn.python.org/projects/sandbox/branches/s...
category=DeprecationWarning) return True return False # egg isn't macosx or ... of this exception: manager The resource manager that raised this exception ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found