diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 54cc8303..2768473a 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -1,6 +1,6 @@ repos: - repo: https://github.com/astral-sh/ruff-pre-commit - rev: v0.12.0 + rev: v0.15.12 hooks: - id: ruff-check args: [--fix, --unsafe-fixes] diff --git a/conftest.py b/conftest.py index 578b7aac..cf0327a0 100644 --- a/conftest.py +++ b/conftest.py @@ -48,7 +48,7 @@ def _save_cwd(): @pytest.fixture def distutils_managed_tempdir(request): - from distutils.tests.compat import py39 as os_helper + from test.support import os_helper self = request.instance self.tempdirs = [] diff --git a/distutils/_modified.py b/distutils/_modified.py index f7d2b77c..4033c079 100644 --- a/distutils/_modified.py +++ b/distutils/_modified.py @@ -9,7 +9,6 @@ from jaraco.functools import splat -from .compat.py39 import zip_strict from .errors import DistutilsFileError _SourcesT = TypeVar( @@ -57,7 +56,7 @@ def newer_pairwise( targets) where source is newer than target, according to the semantics of 'newer()'. """ - newer_pairs = filter(splat(newer), zip_strict(sources, targets)) + newer_pairs = filter(splat(newer), zip(sources, targets, strict=True)) return tuple(map(list, zip(*newer_pairs, strict=False))) or ([], []) diff --git a/distutils/compat/py39.py b/distutils/compat/py39.py deleted file mode 100644 index 9fe2c625..00000000 --- a/distutils/compat/py39.py +++ /dev/null @@ -1,66 +0,0 @@ -import functools -import itertools -import platform -import sys - - -def add_ext_suffix_39(vars): - """ - Ensure vars contains 'EXT_SUFFIX'. pypa/distutils#130 - """ - import _imp - - ext_suffix = _imp.extension_suffixes()[0] - vars.update( - EXT_SUFFIX=ext_suffix, - # sysconfig sets SO to match EXT_SUFFIX, so maintain - # that expectation. - # https://github.com/python/cpython/blob/785cc6770588de087d09e89a69110af2542be208/Lib/sysconfig.py#L671-L673 - SO=ext_suffix, - ) - - -needs_ext_suffix = sys.version_info < (3, 10) and platform.system() == 'Windows' -add_ext_suffix = add_ext_suffix_39 if needs_ext_suffix else lambda vars: None - - -# from more_itertools -class UnequalIterablesError(ValueError): - def __init__(self, details=None): - msg = 'Iterables have different lengths' - if details is not None: - msg += (': index 0 has length {}; index {} has length {}').format(*details) - - super().__init__(msg) - - -# from more_itertools -def _zip_equal_generator(iterables): - _marker = object() - for combo in itertools.zip_longest(*iterables, fillvalue=_marker): - for val in combo: - if val is _marker: - raise UnequalIterablesError() - yield combo - - -# from more_itertools -def _zip_equal(*iterables): - # Check whether the iterables are all the same size. - try: - first_size = len(iterables[0]) - for i, it in enumerate(iterables[1:], 1): - size = len(it) - if size != first_size: - raise UnequalIterablesError(details=(first_size, i, size)) - # All sizes are equal, we can use the built-in zip. - return zip(*iterables, strict=False) - # If any one of the iterables didn't have a length, start reading - # them until one runs out. - except TypeError: - return _zip_equal_generator(iterables) - - -zip_strict = ( - _zip_equal if sys.version_info < (3, 10) else functools.partial(zip, strict=True) -) diff --git a/distutils/compilers/C/tests/test_unix.py b/distutils/compilers/C/tests/test_unix.py index 35b6b0e0..0352a83d 100644 --- a/distutils/compilers/C/tests/test_unix.py +++ b/distutils/compilers/C/tests/test_unix.py @@ -7,10 +7,10 @@ from distutils.compat import consolidate_linker_args from distutils.errors import DistutilsPlatformError from distutils.tests import support -from distutils.tests.compat.py39 import EnvironmentVarGuard from distutils.util import _clear_cached_macosx_ver import pytest +from test.support import os_helper from .. import unix @@ -238,7 +238,7 @@ def gcvs(*args, _orig=sysconfig.get_config_vars): sysconfig.get_config_var = gcv sysconfig.get_config_vars = gcvs - with EnvironmentVarGuard() as env: + with os_helper.EnvironmentVarGuard() as env: env['CC'] = 'my_cc' del env['LDSHARED'] sysconfig.customize_compiler(self.cc) @@ -268,7 +268,7 @@ def gcvs(*args, _orig=sysconfig.get_config_vars): mock.patch.object(self.cc, 'spawn', return_value=None) as mock_spawn, mock.patch.object(self.cc, '_need_link', return_value=True), mock.patch.object(self.cc, 'mkpath', return_value=None), - EnvironmentVarGuard() as env, + os_helper.EnvironmentVarGuard() as env, ): # override environment overrides in case they're specified by CI del env['CXX'] @@ -339,7 +339,7 @@ def gcvs(*args, _orig=sysconfig.get_config_vars): mock.patch.object(self.cc, 'spawn', return_value=None) as mock_spawn, mock.patch.object(self.cc, '_need_link', return_value=True), mock.patch.object(self.cc, 'mkpath', return_value=None), - EnvironmentVarGuard() as env, + os_helper.EnvironmentVarGuard() as env, ): env['CC'] = 'ccache my_cc' env['CXX'] = 'my_cxx' @@ -368,7 +368,7 @@ def gcvs(*args, _orig=sysconfig.get_config_vars): sysconfig.get_config_var = gcv sysconfig.get_config_vars = gcvs - with EnvironmentVarGuard() as env: + with os_helper.EnvironmentVarGuard() as env: env['CC'] = 'my_cc' env['LDSHARED'] = 'my_ld -bundle -dynamic' sysconfig.customize_compiler(self.cc) diff --git a/distutils/sysconfig.py b/distutils/sysconfig.py index 7ddc869a..b6fcaf16 100644 --- a/distutils/sysconfig.py +++ b/distutils/sysconfig.py @@ -22,7 +22,6 @@ from jaraco.functools import pass_none from .ccompiler import CCompiler -from .compat import py39 from .errors import DistutilsPlatformError from .util import is_mingw @@ -563,7 +562,6 @@ def get_config_vars(*args: str) -> list[str | int] | dict[str, str | int]: global _config_vars if _config_vars is None: _config_vars = sysconfig.get_config_vars().copy() - py39.add_ext_suffix(_config_vars) return [_config_vars.get(name) for name in args] if args else _config_vars diff --git a/distutils/tests/compat/__init__.py b/distutils/tests/compat/__init__.py deleted file mode 100644 index e69de29b..00000000 diff --git a/distutils/tests/compat/py39.py b/distutils/tests/compat/py39.py deleted file mode 100644 index 76f12637..00000000 --- a/distutils/tests/compat/py39.py +++ /dev/null @@ -1,18 +0,0 @@ -from test.support.import_helper import ( - CleanImport as CleanImport, -) -from test.support.import_helper import ( - DirsOnSysPath as DirsOnSysPath, -) -from test.support.os_helper import ( - EnvironmentVarGuard as EnvironmentVarGuard, -) -from test.support.os_helper import ( - rmtree as rmtree, -) -from test.support.os_helper import ( - skip_unless_symlink as skip_unless_symlink, -) -from test.support.os_helper import ( - unlink as unlink, -) diff --git a/distutils/tests/test_build_ext.py b/distutils/tests/test_build_ext.py index dab0507f..e2780059 100644 --- a/distutils/tests/test_build_ext.py +++ b/distutils/tests/test_build_ext.py @@ -29,8 +29,7 @@ import path import pytest from test import support - -from .compat import py39 as import_helper +from test.support import import_helper @pytest.fixture() diff --git a/distutils/tests/test_filelist.py b/distutils/tests/test_filelist.py index 09966da1..319c9efb 100644 --- a/distutils/tests/test_filelist.py +++ b/distutils/tests/test_filelist.py @@ -10,8 +10,7 @@ import jaraco.path import pytest - -from .compat import py39 as os_helper +from test.support import os_helper MANIFEST_IN = """\ include ok diff --git a/distutils/tests/test_spawn.py b/distutils/tests/test_spawn.py index 3b9fc926..0f05c170 100644 --- a/distutils/tests/test_spawn.py +++ b/distutils/tests/test_spawn.py @@ -10,9 +10,7 @@ import path import pytest -from test.support import unix_shell - -from .compat import py39 as os_helper +from test.support import os_helper, unix_shell class TestSpawn(support.TempdirManager):