Skip to content

Commit 1bdfa48

Browse files
authored
Bump Python requirement to 3.8 and replace usage of pkg_resources (#48)
Before this patch, LNT would use the pkg_resources package to extract metadata about the current installation. However, that package has been deprecated in recent Python versions, which produces a warning. Fixing this either requires switching to the recommended alternative, or pinning the setuptools dependency to a version < 81. This patch switches to the recommended alternative (importlib.metadata) and bumps the Python requirement to 3.8, which is when importlib.metadata was introduced. This version bump is fairly gentle and makes us match the Python requirement used by the rest of LLVM (which is IMO overdue for a bump as well), so I think it's reasonable.
1 parent ab46fce commit 1bdfa48

File tree

2 files changed

+12
-15
lines changed

2 files changed

+12
-15
lines changed

lnt/lnttool/main.py

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -466,20 +466,17 @@ def _version_check():
466466
when the version number changes (which may involve changing package
467467
requirements).
468468
"""
469-
import pkg_resources
469+
import importlib.metadata
470470
import lnt
471471

472472
# Get the current distribution.
473-
installed_dist = pkg_resources.get_distribution("LNT")
474-
if installed_dist.project_name.lower() != lnt.__name__ or \
475-
pkg_resources.parse_version(installed_dist.version) != \
476-
pkg_resources.parse_version(lnt.__version__):
477-
raise SystemExit("""\
478-
error: installed distribution %s %s is not current (%s %s), you may need to reinstall
479-
LNT or rerun 'setup.py develop' if using development mode.""" % (
480-
installed_dist.project_name,
481-
installed_dist.version,
482-
lnt.__name__, lnt.__version__))
473+
meta = importlib.metadata.metadata("LNT")
474+
if meta['Name'].lower() != lnt.__name__ or meta['Version'] != lnt.__version__:
475+
installed = "{} {}".format(meta['Name'], meta['Version'])
476+
current = "{} {}".format(lnt.__name__, lnt.__version__)
477+
raise SystemExit(f"""\
478+
error: installed distribution {installed} is not current ({current}), you may need to reinstall
479+
LNT or rerun 'setup.py develop' if using development mode.""")
483480

484481

485482
def show_version(ctx, param, value):

setup.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@
44
import sys
55
from setuptools import setup, find_packages, Extension
66

7-
if sys.version_info < (3, 6):
8-
raise RuntimeError("Python 3.6 or higher required.")
7+
if sys.version_info < (3, 8):
8+
raise RuntimeError("Python 3.8 or higher required.")
99

1010
cflags = []
1111

@@ -80,7 +80,7 @@
8080
'License :: OSI Approved :: Apache-2.0 with LLVM exception',
8181
'Natural Language :: English',
8282
'Operating System :: OS Independent',
83-
'Programming Language :: Python :: 3',
83+
'Programming Language :: Python :: 3.8',
8484
'Topic :: Software Development :: Quality Assurance',
8585
'Topic :: Software Development :: Testing',
8686
],
@@ -138,5 +138,5 @@
138138

139139
ext_modules=[cPerf],
140140

141-
python_requires='>=3.6',
141+
python_requires='>=3.8',
142142
)

0 commit comments

Comments
 (0)