Skip to content

Commit

Permalink
Merge branch 'main' into Ruff-0.8.0-UP031-manual-fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
jaraco authored Dec 27, 2024
2 parents a88eace + c375e92 commit 4aa555d
Show file tree
Hide file tree
Showing 15 changed files with 86 additions and 114 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 distutils.tests.compat import py39 as os_helper

self = request.instance
self.tempdirs = []
Expand Down
17 changes: 16 additions & 1 deletion distutils/cmd.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,20 @@
in the distutils.command package.
"""

from __future__ import annotations

import logging
import os
import re
import sys
from typing import TypeVar, overload

from . import _modified, archive_util, dir_util, file_util, util
from ._log import log
from .errors import DistutilsOptionError

_CommandT = TypeVar("_CommandT", bound="Command")


class Command:
"""Abstract base class for defining command classes, the "worker bees"
Expand Down Expand Up @@ -305,7 +310,17 @@ def get_finalized_command(self, command, create=True):

# XXX rename to 'get_reinitialized_command()'? (should do the
# same in dist.py, if so)
def reinitialize_command(self, command, reinit_subcommands=False):
@overload
def reinitialize_command(
self, command: str, reinit_subcommands: bool = False
) -> Command: ...
@overload
def reinitialize_command(
self, command: _CommandT, reinit_subcommands: bool = False
) -> _CommandT: ...
def reinitialize_command(
self, command: str | Command, reinit_subcommands=False
) -> Command:
return self.distribution.reinitialize_command(command, reinit_subcommands)

def run_command(self, command):
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.

20 changes: 19 additions & 1 deletion distutils/dist.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
being built/installed/distributed.
"""

from __future__ import annotations

import contextlib
import logging
import os
Expand All @@ -13,6 +15,7 @@
import warnings
from collections.abc import Iterable
from email import message_from_file
from typing import TYPE_CHECKING, TypeVar, overload

from packaging.utils import canonicalize_name, canonicalize_version

Expand All @@ -27,6 +30,11 @@
from .fancy_getopt import FancyGetopt, translate_longopt
from .util import check_environ, rfc822_escape, strtobool

if TYPE_CHECKING:
from .cmd import Command

_CommandT = TypeVar("_CommandT", bound="Command")

# Regex to define acceptable Distutils command names. This is not *quite*
# the same as a Python NAME -- I don't allow leading underscores. The fact
# that they're very similar is no coincidence; the default naming scheme is
Expand Down Expand Up @@ -900,7 +908,17 @@ def _set_command_options(self, command_obj, option_dict=None): # noqa: C901
except ValueError as msg:
raise DistutilsOptionError(msg)

def reinitialize_command(self, command, reinit_subcommands=False):
@overload
def reinitialize_command(
self, command: str, reinit_subcommands: bool = False
) -> Command: ...
@overload
def reinitialize_command(
self, command: _CommandT, reinit_subcommands: bool = False
) -> _CommandT: ...
def reinitialize_command(
self, command: str | Command, reinit_subcommands=False
) -> Command:
"""Reinitializes a command to the state it was in when first
returned by 'get_command_obj()': ie., initialized but not yet
finalized. This provides the opportunity to sneak option
Expand Down
50 changes: 0 additions & 50 deletions distutils/tests/compat/py38.py

This file was deleted.

40 changes: 40 additions & 0 deletions distutils/tests/compat/py39.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import sys

if sys.version_info >= (3, 10):
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,
)
else:
from test.support import (
CleanImport as CleanImport,
)
from test.support import (
DirsOnSysPath as DirsOnSysPath,
)
from test.support import (
EnvironmentVarGuard as EnvironmentVarGuard,
)
from test.support import (
rmtree as rmtree,
)
from test.support import (
skip_unless_symlink as skip_unless_symlink,
)
from test.support import (
unlink as unlink,
)
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
8 changes: 2 additions & 6 deletions distutils/tests/test_build_ext.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,19 +19,15 @@
)
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
import path
import pytest
from test import support

from .compat import py38 as import_helper
from .compat import py39 as 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
2 changes: 1 addition & 1 deletion distutils/tests/test_filelist.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion distutils/tests/test_spawn.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
2 changes: 1 addition & 1 deletion distutils/tests/test_unixccompiler.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
import pytest

from . import support
from .compat.py38 import EnvironmentVarGuard
from .compat.py39 import EnvironmentVarGuard


@pytest.fixture(autouse=True)
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
1 change: 0 additions & 1 deletion ruff.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ extend-select = [
ignore = [
# TODO: Fix these new violations in Ruff 0.8.0
"UP031",
"UP036",

# https://docs.astral.sh/ruff/formatter/#conflicting-lint-rules
"W191",
Expand Down

0 comments on commit 4aa555d

Please sign in to comment.