From 19e867583623d0a40a9d13b851736e52115daf90 Mon Sep 17 00:00:00 2001 From: Louis Dionne Date: Fri, 3 Oct 2025 10:50:53 -0400 Subject: [PATCH] Bump Python requirement to 3.8 and replace usage of pkg_resources 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. --- lnt/lnttool/main.py | 19 ++++++++----------- setup.py | 8 ++++---- 2 files changed, 12 insertions(+), 15 deletions(-) diff --git a/lnt/lnttool/main.py b/lnt/lnttool/main.py index 3d112a9c..ee13be54 100644 --- a/lnt/lnttool/main.py +++ b/lnt/lnttool/main.py @@ -466,20 +466,17 @@ def _version_check(): when the version number changes (which may involve changing package requirements). """ - import pkg_resources + import importlib.metadata import lnt # Get the current distribution. - installed_dist = pkg_resources.get_distribution("LNT") - if installed_dist.project_name.lower() != lnt.__name__ or \ - pkg_resources.parse_version(installed_dist.version) != \ - pkg_resources.parse_version(lnt.__version__): - raise SystemExit("""\ -error: installed distribution %s %s is not current (%s %s), you may need to reinstall -LNT or rerun 'setup.py develop' if using development mode.""" % ( - installed_dist.project_name, - installed_dist.version, - lnt.__name__, lnt.__version__)) + meta = importlib.metadata.metadata("LNT") + if meta['Name'].lower() != lnt.__name__ or meta['Version'] != lnt.__version__: + installed = "{} {}".format(meta['Name'], meta['Version']) + current = "{} {}".format(lnt.__name__, lnt.__version__) + raise SystemExit(f"""\ +error: installed distribution {installed} is not current ({current}), you may need to reinstall +LNT or rerun 'setup.py develop' if using development mode.""") def show_version(ctx, param, value): diff --git a/setup.py b/setup.py index ecf7dd01..b8326a42 100644 --- a/setup.py +++ b/setup.py @@ -4,8 +4,8 @@ import sys from setuptools import setup, find_packages, Extension -if sys.version_info < (3, 6): - raise RuntimeError("Python 3.6 or higher required.") +if sys.version_info < (3, 8): + raise RuntimeError("Python 3.8 or higher required.") cflags = [] @@ -80,7 +80,7 @@ 'License :: OSI Approved :: Apache-2.0 with LLVM exception', 'Natural Language :: English', 'Operating System :: OS Independent', - 'Programming Language :: Python :: 3', + 'Programming Language :: Python :: 3.8', 'Topic :: Software Development :: Quality Assurance', 'Topic :: Software Development :: Testing', ], @@ -138,5 +138,5 @@ ext_modules=[cPerf], - python_requires='>=3.6', + python_requires='>=3.8', )