Replace pkg_resources dependency with packaging.requirement #445
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Fixes issue #443.
Getting away from our use of
pkg_resources
turns out to be relatively easy:The
packaging
package from the Python Packaging Authority is probably as close as we can get to an official and authoritative upstream for this kind of logic, and thepackaging.requirements.Requirement
class seems to encapsulate the equivalent logic thepkg_resources.Requirement
class that we have used for this purpose until now.At least, our test suite seems to pass with no further adjustments after this change. :-)
Note that this only concerns the parsing of single requirement strings as they occur in
setup.py
andpyproject.toml
files.For parsing full
requirements.txt
files we still rely on pip-requirements-parser.The reason for this is two-fold:
packaging.requirements
does not include functionality to parse complete files (and we don't want to have to deal with fiddly details like line continuations inrequirements.txt
files ourselves)pip_requirements_parser
does not include a good API for parsing requirements strings that are not part of a fullrequirements.txt
file (requires writing a temp file as seen here: https://github.com/nexB/pip-requirements-parser/pull/19/files)Commits:
packaging
as a core dependencypkg_resources.Requirement
withpackaging.requirements.Requirement
setuptools
(andtypes-setuptools
) as a FawltyDeps dependency