From ac548562ccc1633ff69b721a1c0ef084ffb011ac Mon Sep 17 00:00:00 2001 From: Avasam Date: Sun, 24 Nov 2024 15:48:15 -0500 Subject: [PATCH] Remove py38 compat modules --- conftest.py | 2 +- distutils/compat/__init__.py | 4 +-- distutils/compat/py38.py | 34 ------------------ distutils/tests/compat/py38.py | 50 --------------------------- distutils/tests/compat/py39.py | 22 ++++++++++++ distutils/tests/test_bdist_rpm.py | 3 +- distutils/tests/test_build_ext.py | 8 ++--- distutils/tests/test_extension.py | 3 +- distutils/tests/test_filelist.py | 2 +- distutils/tests/test_spawn.py | 2 +- distutils/tests/test_unixccompiler.py | 2 +- distutils/util.py | 12 ++----- ruff.toml | 4 +++ 13 files changed, 37 insertions(+), 111 deletions(-) delete mode 100644 distutils/compat/py38.py delete mode 100644 distutils/tests/compat/py38.py create mode 100644 distutils/tests/compat/py39.py diff --git a/conftest.py b/conftest.py index 98f98d41..3b9444f7 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 py38 as os_helper + from distutils.tests.compat import py39 as os_helper self = request.instance self.tempdirs = [] diff --git a/distutils/compat/__init__.py b/distutils/compat/__init__.py index e12534a3..c715ee9c 100644 --- a/distutils/compat/__init__.py +++ b/distutils/compat/__init__.py @@ -1,7 +1,5 @@ from __future__ import annotations -from .py38 import removeprefix - def consolidate_linker_args(args: list[str]) -> list[str] | str: """ @@ -12,4 +10,4 @@ def consolidate_linker_args(args: list[str]) -> list[str] | str: if not all(arg.startswith('-Wl,') for arg in args): return args - return '-Wl,' + ','.join(removeprefix(arg, '-Wl,') for arg in args) + return '-Wl,' + ','.join(arg.removeprefix('-Wl,') for arg in args) diff --git a/distutils/compat/py38.py b/distutils/compat/py38.py deleted file mode 100644 index 03ec73ef..00000000 --- a/distutils/compat/py38.py +++ /dev/null @@ -1,34 +0,0 @@ -import sys - -if sys.version_info < (3, 9): - - def removesuffix(self, suffix): - # suffix='' should not call self[:-0]. - if suffix and self.endswith(suffix): - return self[: -len(suffix)] - else: - return self[:] - - def removeprefix(self, prefix): - if self.startswith(prefix): - return self[len(prefix) :] - else: - return self[:] - -else: - - def removesuffix(self, suffix): - return self.removesuffix(suffix) - - def removeprefix(self, prefix): - return self.removeprefix(prefix) - - -def aix_platform(osname, version, release): - try: - import _aix_support # type: ignore - - return _aix_support.aix_platform() - except ImportError: - pass - return f"{osname}-{version}.{release}" diff --git a/distutils/tests/compat/py38.py b/distutils/tests/compat/py38.py deleted file mode 100644 index 211d3a6c..00000000 --- a/distutils/tests/compat/py38.py +++ /dev/null @@ -1,50 +0,0 @@ -# flake8: noqa - -import contextlib -import builtins -import sys - -from test.support import requires_zlib -import test.support - - -ModuleNotFoundError = getattr(builtins, 'ModuleNotFoundError', ImportError) - -try: - from test.support.warnings_helper import check_warnings -except (ModuleNotFoundError, ImportError): - from test.support import check_warnings - - -try: - from test.support.os_helper import ( - rmtree, - EnvironmentVarGuard, - unlink, - skip_unless_symlink, - temp_dir, - ) -except (ModuleNotFoundError, ImportError): - from test.support import ( - rmtree, - EnvironmentVarGuard, - unlink, - skip_unless_symlink, - temp_dir, - ) - - -try: - from test.support.import_helper import ( - DirsOnSysPath, - CleanImport, - ) -except (ModuleNotFoundError, ImportError): - from test.support import ( - DirsOnSysPath, - CleanImport, - ) - - -if sys.version_info < (3, 9): - requires_zlib = lambda: test.support.requires_zlib diff --git a/distutils/tests/compat/py39.py b/distutils/tests/compat/py39.py new file mode 100644 index 00000000..82468836 --- /dev/null +++ b/distutils/tests/compat/py39.py @@ -0,0 +1,22 @@ +import sys + +if sys.version_info >= (3, 10): + from test.support.import_helper import ( + CleanImport as CleanImport, + DirsOnSysPath as DirsOnSysPath, + ) + from test.support.os_helper import ( + EnvironmentVarGuard as EnvironmentVarGuard, + rmtree as rmtree, + skip_unless_symlink as skip_unless_symlink, + unlink as unlink, + ) +else: + from test.support import ( + CleanImport as CleanImport, + DirsOnSysPath as DirsOnSysPath, + EnvironmentVarGuard as EnvironmentVarGuard, + rmtree as rmtree, + skip_unless_symlink as skip_unless_symlink, + unlink as unlink, + ) diff --git a/distutils/tests/test_bdist_rpm.py b/distutils/tests/test_bdist_rpm.py index 1109fdf1..75051430 100644 --- a/distutils/tests/test_bdist_rpm.py +++ b/distutils/tests/test_bdist_rpm.py @@ -8,8 +8,7 @@ from distutils.tests import support import pytest - -from .compat.py38 import requires_zlib +from test.support import requires_zlib SETUP_PY = """\ from distutils.core import setup diff --git a/distutils/tests/test_build_ext.py b/distutils/tests/test_build_ext.py index 8bd3cef8..8477c9da 100644 --- a/distutils/tests/test_build_ext.py +++ b/distutils/tests/test_build_ext.py @@ -19,11 +19,7 @@ ) from distutils.extension import Extension from distutils.tests import missing_compiler_executable -from distutils.tests.support import ( - TempdirManager, - copy_xxmodule_c, - fixup_build_ext, -) +from distutils.tests.support import TempdirManager, copy_xxmodule_c, fixup_build_ext from io import StringIO import jaraco.path @@ -31,7 +27,7 @@ import pytest from test import support -from .compat import py38 as import_helper +from .compat import py39 as import_helper @pytest.fixture() diff --git a/distutils/tests/test_extension.py b/distutils/tests/test_extension.py index 41872e04..e51c1cd8 100644 --- a/distutils/tests/test_extension.py +++ b/distutils/tests/test_extension.py @@ -6,8 +6,7 @@ from distutils.extension import Extension, read_setup_file import pytest - -from .compat.py38 import check_warnings +from test.support.warnings_helper import check_warnings class TestExtension: diff --git a/distutils/tests/test_filelist.py b/distutils/tests/test_filelist.py index ec7e5cf3..130e6fb5 100644 --- a/distutils/tests/test_filelist.py +++ b/distutils/tests/test_filelist.py @@ -10,7 +10,7 @@ import jaraco.path import pytest -from .compat import py38 as os_helper +from .compat import py39 as os_helper MANIFEST_IN = """\ include ok diff --git a/distutils/tests/test_spawn.py b/distutils/tests/test_spawn.py index fcbc765e..3b9fc926 100644 --- a/distutils/tests/test_spawn.py +++ b/distutils/tests/test_spawn.py @@ -12,7 +12,7 @@ import pytest from test.support import unix_shell -from .compat import py38 as os_helper +from .compat import py39 as os_helper class TestSpawn(support.TempdirManager): diff --git a/distutils/tests/test_unixccompiler.py b/distutils/tests/test_unixccompiler.py index 16953287..2c2f4aae 100644 --- a/distutils/tests/test_unixccompiler.py +++ b/distutils/tests/test_unixccompiler.py @@ -12,7 +12,7 @@ import pytest from . import support -from .compat.py38 import EnvironmentVarGuard +from .compat.py39 import EnvironmentVarGuard @pytest.fixture(autouse=True) diff --git a/distutils/util.py b/distutils/util.py index 8d8260bc..1334e2f7 100644 --- a/distutils/util.py +++ b/distutils/util.py @@ -25,7 +25,7 @@ from .spawn import spawn -def get_host_platform(): +def get_host_platform() -> str: """ Return a string that identifies the current platform. Use this function to distinguish platform-specific build directories and @@ -34,15 +34,7 @@ def get_host_platform(): # This function initially exposed platforms as defined in Python 3.9 # even with older Python versions when distutils was split out. - # Now it delegates to stdlib sysconfig, but maintains compatibility. - - if sys.version_info < (3, 9): - if os.name == "posix" and hasattr(os, 'uname'): - osname, host, release, version, machine = os.uname() - if osname[:3] == "aix": - from .compat.py38 import aix_platform - - return aix_platform(osname, version, release) + # Now it delegates to stdlib sysconfig. return sysconfig.get_platform() diff --git a/ruff.toml b/ruff.toml index 0cc5b267..b0930827 100644 --- a/ruff.toml +++ b/ruff.toml @@ -47,6 +47,10 @@ ignore = [ "TRY400", ] +[lint.isort] +combine-as-imports = true +split-on-trailing-comma = false + [format] # Enable preview to get hugged parenthesis unwrapping and other nice surprises # See https://github.com/jaraco/skeleton/pull/133#issuecomment-2239538373