From cd0ef12fc236328693c6e4fb10226b92d3bfcb21 Mon Sep 17 00:00:00 2001 From: Avasam Date: Wed, 30 Oct 2024 15:24:36 -0400 Subject: [PATCH] Consistently using `sys.version_info` as a `NamedTuple` --- pkg_resources/__init__.py | 2 +- pkg_resources/tests/test_resources.py | 2 +- setuptools/command/bdist_wheel.py | 4 ++-- setuptools/command/easy_install.py | 9 ++++----- setuptools/command/egg_info.py | 2 +- setuptools/package_index.py | 5 +---- setuptools/tests/test_easy_install.py | 4 +++- setuptools/tests/test_egg_info.py | 4 ++-- 8 files changed, 15 insertions(+), 17 deletions(-) diff --git a/pkg_resources/__init__.py b/pkg_resources/__init__.py index f1f0ef2535..d27b10d4b6 100644 --- a/pkg_resources/__init__.py +++ b/pkg_resources/__init__.py @@ -387,7 +387,7 @@ class UnknownExtra(ResolutionError): _provider_factories: dict[type[_ModuleLike], _ProviderFactoryType] = {} -PY_MAJOR = '{}.{}'.format(*sys.version_info) +PY_MAJOR = f'{sys.version_info.major}.{sys.version_info.minor}' EGG_DIST = 3 BINARY_DIST = 2 SOURCE_DIST = 1 diff --git a/pkg_resources/tests/test_resources.py b/pkg_resources/tests/test_resources.py index f5e793fb90..8bd8a1766a 100644 --- a/pkg_resources/tests/test_resources.py +++ b/pkg_resources/tests/test_resources.py @@ -119,7 +119,7 @@ def testDistroBasics(self): self.checkFooPkg(d) d = Distribution("/some/path") - assert d.py_version == '{}.{}'.format(*sys.version_info) + assert d.py_version == f'{sys.version_info.major}.{sys.version_info.minor}' assert d.platform is None def testDistroParse(self): diff --git a/setuptools/command/bdist_wheel.py b/setuptools/command/bdist_wheel.py index c88753476f..f23caaa09f 100644 --- a/setuptools/command/bdist_wheel.py +++ b/setuptools/command/bdist_wheel.py @@ -64,7 +64,7 @@ def _is_32bit_interpreter() -> bool: def python_tag() -> str: - return f"py{sys.version_info[0]}" + return f"py{sys.version_info.major}" def get_platform(archive_root: str | None) -> str: @@ -483,7 +483,7 @@ def run(self): # Add to 'Distribution.dist_files' so that the "upload" command works getattr(self.distribution, "dist_files", []).append(( "bdist_wheel", - "{}.{}".format(*sys.version_info[:2]), # like 3.7 + f"{sys.version_info.major}.{sys.version_info.minor}", wheel_path, )) diff --git a/setuptools/command/easy_install.py b/setuptools/command/easy_install.py index 6c835db593..5778020ccb 100644 --- a/setuptools/command/easy_install.py +++ b/setuptools/command/easy_install.py @@ -234,10 +234,9 @@ def _render_version(): """ Render the Setuptools version and installation details, then exit. """ - ver = '{}.{}'.format(*sys.version_info) + ver = f'{sys.version_info.major}.{sys.version_info.minor}' dist = get_distribution('setuptools') - tmpl = 'setuptools {dist.version} from {dist.location} (Python {ver})' - print(tmpl.format(**locals())) + print(f'setuptools {dist.version} from {dist.location} (Python {ver})') raise SystemExit def finalize_options(self): # noqa: C901 # is too complex (25) # FIXME @@ -1441,7 +1440,7 @@ def get_site_dirs(): os.path.join( prefix, "lib", - "python{}.{}".format(*sys.version_info), + f"python{sys.version_info.major}.{sys.version_info.minor}", "site-packages", ), os.path.join(prefix, "lib", "site-python"), @@ -1468,7 +1467,7 @@ def get_site_dirs(): home, 'Library', 'Python', - '{}.{}'.format(*sys.version_info), + f'{sys.version_info.major}.{sys.version_info.minor}', 'site-packages', ) sitedirs.append(home_sp) diff --git a/setuptools/command/egg_info.py b/setuptools/command/egg_info.py index 7b9f8f0b72..f9b8c6df71 100644 --- a/setuptools/command/egg_info.py +++ b/setuptools/command/egg_info.py @@ -31,7 +31,7 @@ from distutils.filelist import FileList as _FileList from distutils.util import convert_path -PY_MAJOR = '{}.{}'.format(*sys.version_info) +PY_MAJOR = f'{sys.version_info.major}.{sys.version_info.minor}' def translate_pattern(glob): # noqa: C901 # is too complex (14) # FIXME diff --git a/setuptools/package_index.py b/setuptools/package_index.py index 2a05b35c4f..ef7f41514e 100644 --- a/setuptools/package_index.py +++ b/setuptools/package_index.py @@ -64,10 +64,7 @@ _SOCKET_TIMEOUT = 15 -_tmpl = "setuptools/{setuptools.__version__} Python-urllib/{py_major}" -user_agent = _tmpl.format( - py_major='{}.{}'.format(*sys.version_info), setuptools=setuptools -) +user_agent = f"setuptools/{setuptools.__version__} Python-urllib/{sys.version_info.major}.{sys.version_info.minor}" def parse_requirement_arg(spec): diff --git a/setuptools/tests/test_easy_install.py b/setuptools/tests/test_easy_install.py index bfe1b8da90..60a31e3bf2 100644 --- a/setuptools/tests/test_easy_install.py +++ b/setuptools/tests/test_easy_install.py @@ -859,7 +859,9 @@ def test_setup_requires_with_python_requires(self, monkeypatch, tmpdir): ) dep_2_0_sdist = 'dep-2.0.tar.gz' dep_2_0_url = path_to_url(str(tmpdir / dep_2_0_sdist)) - dep_2_0_python_requires = '!=' + '.'.join(map(str, sys.version_info[:2])) + '.*' + dep_2_0_python_requires = ( + f'!={sys.version_info.major}.{sys.version_info.minor}.*' + ) make_python_requires_sdist( str(tmpdir / dep_2_0_sdist), 'dep', '2.0', dep_2_0_python_requires ) diff --git a/setuptools/tests/test_egg_info.py b/setuptools/tests/test_egg_info.py index 12d6b30a8b..f82d931eba 100644 --- a/setuptools/tests/test_egg_info.py +++ b/setuptools/tests/test_egg_info.py @@ -261,11 +261,11 @@ def _setup_script_with_requires(self, requires, use_setup_cfg=False): }) mismatch_marker = "python_version<'{this_ver}'".format( - this_ver=sys.version_info[0], + this_ver=sys.version_info.major, ) # Alternate equivalent syntax. mismatch_marker_alternate = 'python_version < "{this_ver}"'.format( - this_ver=sys.version_info[0], + this_ver=sys.version_info.major, ) invalid_marker = "<=>++"