From c2a67ef100377c889602da93f23e0e2bd678cf01 Mon Sep 17 00:00:00 2001 From: Miro <200482516+Mirochill@users.noreply.github.com> Date: Sun, 24 May 2026 19:04:02 +0200 Subject: [PATCH] Remove setup.py pkg_resources dependency --- pyproject.toml | 2 +- setup.py | 33 +++++++++++++++++++++++++-------- 2 files changed, 26 insertions(+), 9 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index 22be18b1..ddb4c53f 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,5 +1,5 @@ [build-system] -requires = ["setuptools>=42,<=81.0.0", "wheel"] +requires = ["setuptools>=42", "wheel"] build-backend = "setuptools.build_meta" [project] diff --git a/setup.py b/setup.py index aff5ab6e..1d078ab1 100644 --- a/setup.py +++ b/setup.py @@ -1,6 +1,23 @@ -import setuptools +import re import sys -import pkg_resources + +import setuptools + + +def version_at_least(version, minimum): + def normalize(value): + return [ + (0, int(part)) if part.isdigit() else (1, part.lower()) + for part in re.split(r"[._+-]", value) + if part + ] + + version_parts = normalize(version) + minimum_parts = normalize(minimum) + length = max(len(version_parts), len(minimum_parts)) + version_parts += [(0, 0)] * (length - len(version_parts)) + minimum_parts += [(0, 0)] * (length - len(minimum_parts)) + return version_parts >= minimum_parts def get_version_by_import(): @@ -16,21 +33,21 @@ def get_version_by_import(): # Get setuptools version # We control it when installing from pyproject.toml, but not when installing from setup.py / setup.cfg # Check setuptools version -current_setuptools_version = pkg_resources.parse_version(pkg_resources.get_distribution("setuptools").version) +current_setuptools_version = setuptools.__version__ # Set the version requirement for setuptools_scm, depending on the combination of Python and setuptools version version_file_path = 'eessi/testsuite/_version.py' scm_dict = {'write_to': version_file_path} -if python_version >= (3, 8) and current_setuptools_version >= pkg_resources.parse_version("61.0.0"): +if python_version >= (3, 8) and version_at_least(current_setuptools_version, "61.0.0"): setuptools_scm_requirement = 'setuptools_scm>8.0.0,<=8.1.0' scm_dict = {'version_file': version_file_path} -elif python_version >= (3, 7) and current_setuptools_version >= pkg_resources.parse_version("45.0.0"): +elif python_version >= (3, 7) and version_at_least(current_setuptools_version, "45.0.0"): setuptools_scm_requirement = 'setuptools_scm>7.0.0,<=7.1.0' -elif python_version >= (3, 6) and current_setuptools_version >= pkg_resources.parse_version("45.0.0"): +elif python_version >= (3, 6) and version_at_least(current_setuptools_version, "45.0.0"): setuptools_scm_requirement = 'setuptools_scm>=6.0.0,<=6.4.2' -elif python_version >= (3, 6) and current_setuptools_version >= pkg_resources.parse_version("42.0.0"): +elif python_version >= (3, 6) and version_at_least(current_setuptools_version, "42.0.0"): setuptools_scm_requirement = 'setuptools_scm>=5.0.0,<=5.0.2' -elif python_version >= (3, 6) and current_setuptools_version >= pkg_resources.parse_version("34.4.0"): +elif python_version >= (3, 6) and version_at_least(current_setuptools_version, "34.4.0"): setuptools_scm_requirement = 'setuptools_scm>=4.0.0,<=4.1.2' # Set the fallback_version for scm based on what eessi.testsuite.__version__ returns