pkg_resources: Wrong exception raised on parse error
See original GitHub issueDue 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:
- Created 3 years ago
- Reactions:2
- Comments:5 (2 by maintainers)
Top 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 >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Sorry, I should have worded this differently. I think it’s more correct to say, it is not immediately obvious that
setuptools
vendorspackaging
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.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 vendorpip
with https://github.com/pantsbuild/pex.)