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

Replace pkg_resources dependency with packaging.requirement #445

Merged
merged 3 commits into from
Jul 23, 2024

Conversation

jherland
Copy link
Member

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 the packaging.requirements.Requirement class seems to encapsulate the equivalent logic the pkg_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 and pyproject.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 in requirements.txt files ourselves)
  • pip_requirements_parser does not include a good API for parsing requirements strings that are not part of a full requirements.txt file (requires writing a temp file as seen here: https://github.com/nexB/pip-requirements-parser/pull/19/files)

Commits:

  • Add packaging as a core dependency
  • Replace pkg_resources.Requirement with packaging.requirements.Requirement
  • Remove setuptools (and types-setuptools) as a FawltyDeps dependency

We're about to replace our dependency on pkg_resources (from setuptools)
with packaging.requirements instead.

Coincidentally, packaging is already a transitive dependency of ours
(via pip-requirements-parser), so this does not add any additional bloat
when installing FawltyDeps.

We require >=24.0 of this package even though there already exists a
later 24.1 release. The reason for this is that 24.0 is the last release
to support Python v3.7.
We no longer use the pkg_resources module, and that allows us to drop
our dependency on setuptools. With that gone, we also no longer need the
types-setuptools package available to help type-checking.
@jherland jherland self-assigned this Jul 23, 2024
@jherland jherland linked an issue Jul 23, 2024 that may be closed by this pull request
Copy link

@obscurerichard obscurerichard left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍🏻 :shipit:

@jherland jherland merged commit de3dbb9 into main Jul 23, 2024
63 checks passed
@jherland jherland deleted the jherland/remove_setuptools branch July 23, 2024 17:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Migrate away from pkg_resources
2 participants