Skip to content

refactor: replace pkg_resources with importlib + packaging #11

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

rosasbehoundja
Copy link

This pull request addresses the deprecation of pkg_resources by refactoring check_requirements.py to use importlib.metadata and packaging for checking installed packages and their versions.

Related Issue

No GitHub issue was formally opened, but this change resolves the implicit need to modernize dependency checks in line with current Python best practices.

What this PR does

  • Replaces pkg_resources.require() with:
    • importlib.metadata.version() for retrieving installed versions
    • packaging.requirements.Requirement for parsing requirements
    • packaging.version.Version for comparing installed versions
  • Improves handling of:
    • Missing packages (PackageNotFoundError)
    • Version mismatches with warning messages
    • Skipping empty lines and comments in requirements.txt
  • Ensures the script exits only when a required package is missing

How I tested it

  • Ran the script locally with a sample requirements.txt containing:
    • Installed packages with valid versions
    • Non-installed packages
    • Version mismatches
    • Commented and empty lines
  • Verified that:
    • Missing packages cause the script to exit with an error
    • Version mismatches produce warnings
    • Valid packages pass silently

Additional notes

  • This change assumes that the packaging module is available in the environment. If not, it should be added to the project's requirements.
  • Tested on Python 3.11 and 3.12

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.

1 participant