landscapeio / prospector

Inspects Python source files and provides information about type and location of classes, methods etc
GNU General Public License v2.0
1.94k stars 171 forks source link

Fix pkg resources import #647

Closed ldallmayr closed 10 months ago

ldallmayr commented 10 months ago

Description

The use of pkg_resources is deprecated in favor of its importlib equivalents. Running the pre-commit hook with Python 3.12 fails because pkg_resources cannot be found.

ModuleNotFoundError: No module named 'pkg_resources'

Related Issue

https://github.com/landscapeio/prospector/issues/646

Motivation and Context

This pull request fixes the error ModuleNotFoundError: No module named 'pkg_resources' when ran by pre-commit

How Has This Been Tested?

Ran all tests with pytest locally

Failed tests

FAILED tests/profiles/test_profile.py::TestProfileInheritance::test_module_file_inheritance - prospector.profiles.exceptions.ProfileNotFound
FAILED tests/profiles/test_profile.py::TestProfileInheritance::test_module_inheritance - prospector.profiles.exceptions.ProfileNotFound
FAILED tests/tools/pyroma/test_pyroma_tool.py::test_forced_include - assert 12 == 10

Types of changes

Checklist:

ldallmayr commented 10 months ago

The resources.files api was introduced in Python 3.9, therefore I had to use the function resources.read_text. This function has been marked deprecated since Python 3.11. As soon as the minimum requirement for prospector is Python 3.9 one could change to the resources.files api.

ldallmayr commented 10 months ago

importlib.metadata was introduced in Python 3.8, so either the backports of those tools have to be used or this change has to be postponed until the minimum requirement is greater than Python 3.8

Pierre-Sassoulas commented 10 months ago

Python 3.9 is not yet EOL, we should probably use both with a if sys.version_info(...) guard until then.