Skip to content

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