Skip to content

Compatibility with setuptools >= 82.0.0 (ModuleNotFoundError: No module named 'pkg_resources') #648

@hsm207

Description

@hsm207

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:

  1. 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.
  2. 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!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions