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

Fix for PIP Inspector not working when pkg_resources package is not available in newer Python versions #1287

Open
wants to merge 5 commits into
base: master
Choose a base branch
from

Conversation

andrian-sevastyanov
Copy link
Contributor

Fix for PIP Inspector not working when pkg_resources package is not available in newer Python versions

Description

Starting with Python version 3.12 the PIP inspector fails out of the box with error ModuleNotFoundError: No module named 'pkg_resources'.

This could have been addressed by suggesting to customers to pre-install the missing package; however, this PR instead attempts to rely on newer importlib.metadata package for the following reasons:

  • pkg_resources is now deprecated
  • this makes it more straightforward for customers to use Detect with PIP Inspector

dependency_node = DependencyNode(metadata["Name"], metadata["Version"])

requirement_names = []
requirements = importlib.metadata.requires(dependency_node.name)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I discovered a problem with this approach of listing dependencies since the requires() function can return packages which are not necessarily installed: in cases when the dependency is an "extra" or condition such as platform_python_implementation != 'PyPy' is evaluated to False.

I am currently exploring possible ways of filtering out such dependencies.

@andrian-sevastyanov andrian-sevastyanov marked this pull request as ready for review November 20, 2024 13:16
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