Skip to content

Use of deprecated / removed pkg_resources #1552

@loqs

Description

@loqs

pkg_resources pkg_resources was deprecated in Setuptools v67.5.0. It was removed in Setuptools v82.0.0. It is used in setup.py. There is a pkg_resources migration guide. This causes the build to fail with setuptools 82:

Traceback (most recent call last):
  File "/build/thefuck/src/thefuck/setup.py", line 3, in <module>
    import pkg_resources
ModuleNotFoundError: No module named 'pkg_resources'

Possible replacement

--- a/setup.py
+++ b/setup.py
@@ -1,17 +1,26 @@
 #!/usr/bin/env python
 from setuptools import setup, find_packages
-import pkg_resources
 import sys
 import os
 import fastentrypoints
 
+try:
+    from importlib.metadata import version, PackageNotFoundError
+except ImportError:
+    import pkg_resources
+    def version(package_name):
+        return pkg_resources.get_distribution(package_name).version
+    PackageNotFoundError = pkg_resources.DistributionNotFound
+
 
 try:
-    if int(pkg_resources.get_distribution("pip").version.split('.')[0]) < 6:
+    pip_version = version("pip").split('.')[0]
+    if int(pip_version) < 6:
         print('pip older than 6.0 not supported, please upgrade pip with:\n\n'
               '    pip install -U pip')
         sys.exit(-1)
-except pkg_resources.DistributionNotFound:
+except PackageNotFoundError:
     pass
 
 if os.environ.get('CONVERT_README'):

@felixonmars

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions