Skip to content

Commit

Permalink
Remove py38 compat modules
Browse files Browse the repository at this point in the history
  • Loading branch information
Avasam committed Nov 24, 2024
1 parent 2517976 commit 713814e
Show file tree
Hide file tree
Showing 12 changed files with 38 additions and 129 deletions.
2 changes: 1 addition & 1 deletion conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ def _save_cwd():

@pytest.fixture
def distutils_managed_tempdir(request):
from distutils.tests.compat import py38 as os_helper
from test.support import os_helper

self = request.instance
self.tempdirs = []
Expand Down
4 changes: 1 addition & 3 deletions distutils/compat/__init__.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
from __future__ import annotations

from .py38 import removeprefix


def consolidate_linker_args(args: list[str]) -> list[str] | str:
"""
Expand All @@ -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)
34 changes: 0 additions & 34 deletions distutils/compat/py38.py

This file was deleted.

Empty file removed distutils/tests/compat/__init__.py
Empty file.
50 changes: 0 additions & 50 deletions distutils/tests/compat/py38.py

This file was deleted.

3 changes: 1 addition & 2 deletions distutils/tests/test_bdist_rpm.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 1 addition & 2 deletions distutils/tests/test_build_ext.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,7 @@
import path
import pytest
from test import support

from .compat import py38 as import_helper
from test.support import import_helper


@pytest.fixture()
Expand Down
3 changes: 1 addition & 2 deletions distutils/tests/test_extension.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
3 changes: 1 addition & 2 deletions distutils/tests/test_filelist.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,7 @@

import jaraco.path
import pytest

from .compat import py38 as os_helper
from test.support import os_helper

MANIFEST_IN = """\
include ok
Expand Down
38 changes: 23 additions & 15 deletions distutils/tests/test_spawn.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,7 @@

import path
import pytest
from test.support import unix_shell

from .compat import py38 as os_helper
from test.support import os_helper, unix_shell


class TestSpawn(support.TempdirManager):
Expand Down Expand Up @@ -73,9 +71,12 @@ def test_find_executable(self, tmp_path):
# PATH='': no match, except in the current directory
with os_helper.EnvironmentVarGuard() as env:
env['PATH'] = ''
with mock.patch(
'distutils.spawn.os.confstr', return_value=tmp_dir, create=True
), mock.patch('distutils.spawn.os.defpath', tmp_dir):
with (
mock.patch(
'distutils.spawn.os.confstr', return_value=tmp_dir, create=True
),
mock.patch('distutils.spawn.os.defpath', tmp_dir),
):
rv = find_executable(program)
assert rv is None

Expand All @@ -87,9 +88,10 @@ def test_find_executable(self, tmp_path):
# PATH=':': explicitly looks in the current directory
with os_helper.EnvironmentVarGuard() as env:
env['PATH'] = os.pathsep
with mock.patch(
'distutils.spawn.os.confstr', return_value='', create=True
), mock.patch('distutils.spawn.os.defpath', ''):
with (
mock.patch('distutils.spawn.os.confstr', return_value='', create=True),
mock.patch('distutils.spawn.os.defpath', ''),
):
rv = find_executable(program)
assert rv is None

Expand All @@ -103,16 +105,22 @@ def test_find_executable(self, tmp_path):
env.pop('PATH', None)

# without confstr
with mock.patch(
'distutils.spawn.os.confstr', side_effect=ValueError, create=True
), mock.patch('distutils.spawn.os.defpath', tmp_dir):
with (
mock.patch(
'distutils.spawn.os.confstr', side_effect=ValueError, create=True
),
mock.patch('distutils.spawn.os.defpath', tmp_dir),
):
rv = find_executable(program)
assert rv == filename

# with confstr
with mock.patch(
'distutils.spawn.os.confstr', return_value=tmp_dir, create=True
), mock.patch('distutils.spawn.os.defpath', ''):
with (
mock.patch(
'distutils.spawn.os.confstr', return_value=tmp_dir, create=True
),
mock.patch('distutils.spawn.os.defpath', ''),
):
rv = find_executable(program)
assert rv == filename

Expand Down
15 changes: 7 additions & 8 deletions distutils/tests/test_unixccompiler.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@
from distutils.util import _clear_cached_macosx_ver

import pytest
from test.support.os_helper import EnvironmentVarGuard

from . import support
from .compat.py38 import EnvironmentVarGuard


@pytest.fixture(autouse=True)
Expand Down Expand Up @@ -272,13 +272,12 @@ def gcvs(*args, _orig=sysconfig.get_config_vars):

sysconfig.get_config_var = gcv
sysconfig.get_config_vars = gcvs
with 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:
with (
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,
):
env['CC'] = 'ccache my_cc'
env['CXX'] = 'my_cxx'
del env['LDSHARED']
Expand Down
12 changes: 2 additions & 10 deletions distutils/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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()

Expand Down

0 comments on commit 713814e

Please sign in to comment.