Skip to content

Commit

Permalink
Consistently using sys.version_info as a NamedTuple
Browse files Browse the repository at this point in the history
  • Loading branch information
Avasam committed Oct 30, 2024
1 parent fcdaf02 commit cd0ef12
Show file tree
Hide file tree
Showing 8 changed files with 15 additions and 17 deletions.
2 changes: 1 addition & 1 deletion pkg_resources/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion pkg_resources/tests/test_resources.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
4 changes: 2 additions & 2 deletions setuptools/command/bdist_wheel.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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,
))

Expand Down
9 changes: 4 additions & 5 deletions setuptools/command/easy_install.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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"),
Expand All @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion setuptools/command/egg_info.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 1 addition & 4 deletions setuptools/package_index.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
4 changes: 3 additions & 1 deletion setuptools/tests/test_easy_install.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
)
Expand Down
4 changes: 2 additions & 2 deletions setuptools/tests/test_egg_info.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 = "<=>++"

Expand Down

0 comments on commit cd0ef12

Please sign in to comment.