Skip to content

Commit 1c4c4db

Browse files
ianhandyclaude
andcommitted
Replace deprecated pkg_resources with importlib.metadata
pkg_resources (from setuptools) is deprecated and causes issues on Python 3.12+ where it may not be available. Replace all usage with importlib.metadata (stdlib since Python 3.8), with a fallback to the importlib_metadata backport for older Python versions. Fixes #1552 Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent c7e7e1d commit 1c4c4db

File tree

2 files changed

+8
-7
lines changed

2 files changed

+8
-7
lines changed

setup.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,20 @@
11
#!/usr/bin/env python
22
from setuptools import setup, find_packages
3-
import pkg_resources
43
import sys
54
import os
65
import fastentrypoints
76

7+
try:
8+
from importlib.metadata import version, PackageNotFoundError
9+
except ImportError:
10+
from importlib_metadata import version, PackageNotFoundError
811

912
try:
10-
if int(pkg_resources.get_distribution("pip").version.split('.')[0]) < 6:
13+
if int(version("pip").split('.')[0]) < 6:
1114
print('pip older than 6.0 not supported, please upgrade pip with:\n\n'
1215
' pip install -U pip')
1316
sys.exit(-1)
14-
except pkg_resources.DistributionNotFound:
17+
except PackageNotFoundError:
1518
pass
1619

1720
if os.environ.get('CONVERT_README'):

thefuck/utils.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -297,12 +297,10 @@ def wrapper(*args, **kwargs):
297297
def get_installation_version():
298298
try:
299299
from importlib.metadata import version
300-
301-
return version('thefuck')
302300
except ImportError:
303-
import pkg_resources
301+
from importlib_metadata import version
304302

305-
return pkg_resources.require('thefuck')[0].version
303+
return version('thefuck')
306304

307305

308306
def get_alias():

0 commit comments

Comments
 (0)