Description
With the release of setuptools >= 82.0.0 (as discussed in pypa/setuptools#5174), the legacy pkg_resources module has been completely removed from current distributions and installations.
Currently, lean-cli relies on pkg_resources for requirement parsing and resource reading. In environments with modern setuptools (including newer python installations and setups), running lean commands raises the following traceback:
ModuleNotFoundError: No module named 'pkg_resources'
Additionally, the distutils module (which was deprecated and removed in Python 3.12) is still referenced in version comparisons.
Proposed Resolution & Justification
Following the official Setuptools Package Discovery and Resource Access Deprecation Guide, the recommended replacements for migrating away from pkg_resources are:
- Requirement and Version Parsing:
- Guideline: "Requirement and version parsing: use
packaging. This includes parsing and evaluating extras and markers via packaging.requirements.Requirement and packaging.markers.Marker."
- Fix: Swap
pkg_resources.Requirement.parse to packaging.requirements.Requirement and swap distutils.version.StrictVersion to packaging.version.Version. We can add packaging explicitly to setup.py's install_requires.
- Resource Access:
- Guideline: "Resource access: use
importlib.resources."
- Fix: Replace
pkg_resources.resource_string with standard library importlib.resources.files (native in Python 3.9+).
Affected Files
I have implemented these fixes locally and verified that they successfully pass the complete unit test suite (2575 passed, 72 skipped). If the maintainers are aligned on this approach, I would be happy to contribute a pull request!
Description
With the release of
setuptools >= 82.0.0(as discussed in pypa/setuptools#5174), the legacypkg_resourcesmodule has been completely removed from current distributions and installations.Currently,
lean-clirelies onpkg_resourcesfor requirement parsing and resource reading. In environments with modern setuptools (including newer python installations and setups), runningleancommands raises the following traceback:ModuleNotFoundError: No module named 'pkg_resources'Additionally, the
distutilsmodule (which was deprecated and removed in Python 3.12) is still referenced in version comparisons.Proposed Resolution & Justification
Following the official Setuptools Package Discovery and Resource Access Deprecation Guide, the recommended replacements for migrating away from
pkg_resourcesare:packaging. This includes parsing and evaluating extras and markers viapackaging.requirements.Requirementandpackaging.markers.Marker."pkg_resources.Requirement.parsetopackaging.requirements.Requirementand swapdistutils.version.StrictVersiontopackaging.version.Version. We can addpackagingexplicitly tosetup.py'sinstall_requires.importlib.resources."pkg_resources.resource_stringwith standard libraryimportlib.resources.files(native in Python 3.9+).Affected Files
pkg_resources.Requirement.parseanddistutils.version.StrictVersion)pkg_resources.Requirement.parse)pkg_resources.Requirement.parse)pkg_resources.resource_string)distutils.version.StrictVersion)setuptoolsas runtime dependency)I have implemented these fixes locally and verified that they successfully pass the complete unit test suite (
2575 passed, 72 skipped). If the maintainers are aligned on this approach, I would be happy to contribute a pull request!