diff --git a/distutils/command/build_clib.py b/distutils/command/build_clib.py index a600d093..1305d5bb 100644 --- a/distutils/command/build_clib.py +++ b/distutils/command/build_clib.py @@ -138,8 +138,7 @@ def check_library_list(self, libraries): if '/' in name or (os.sep != '/' and os.sep in name): raise DistutilsSetupError( - f"bad library name '{lib[0]}': " - "may not contain directory separators" + f"bad library name '{lib[0]}': may not contain directory separators" ) if not isinstance(build_info, dict): diff --git a/distutils/command/build_ext.py b/distutils/command/build_ext.py index 82c0e9f5..cf60bd0a 100644 --- a/distutils/command/build_ext.py +++ b/distutils/command/build_ext.py @@ -443,8 +443,7 @@ def check_extensions_list(self, extensions): # noqa: C901 for macro in macros: if not (isinstance(macro, tuple) and len(macro) in (1, 2)): raise DistutilsSetupError( - "'macros' element of build info dict " - "must be 1- or 2-tuple" + "'macros' element of build info dict must be 1- or 2-tuple" ) if len(macro) == 1: ext.undef_macros.append(macro[0]) @@ -672,8 +671,7 @@ def find_swig(self): return "swig.exe" else: raise DistutilsPlatformError( - "I don't know how to find (much less run) SWIG " - f"on platform '{os.name}'" + f"I don't know how to find (much less run) SWIG on platform '{os.name}'" ) # -- Name generators ----------------------------------------------- diff --git a/distutils/command/check.py b/distutils/command/check.py index 93d754e7..1375028e 100644 --- a/distutils/command/check.py +++ b/distutils/command/check.py @@ -46,10 +46,7 @@ class check(Command): ( 'restructuredtext', 'r', - ( - 'Checks if long string meta-data syntax ' - 'are reStructuredText-compliant' - ), + 'Checks if long string meta-data syntax are reStructuredText-compliant', ), ('strict', 's', 'Will exit with an error if a check fails'), ] diff --git a/distutils/command/install_data.py b/distutils/command/install_data.py index a90ec3b4..36f5bcc8 100644 --- a/distutils/command/install_data.py +++ b/distutils/command/install_data.py @@ -9,7 +9,7 @@ import functools import os -from typing import Iterable +from collections.abc import Iterable from ..core import Command from ..util import change_root, convert_path @@ -22,8 +22,7 @@ class install_data(Command): ( 'install-dir=', 'd', - "base directory for installing data files " - "[default: installation base dir]", + "base directory for installing data files [default: installation base dir]", ), ('root=', None, "install everything relative to this alternate root directory"), ('force', 'f', "force installation (overwrite existing files)"), diff --git a/distutils/fancy_getopt.py b/distutils/fancy_getopt.py index 907cc2b7..4ea89603 100644 --- a/distutils/fancy_getopt.py +++ b/distutils/fancy_getopt.py @@ -12,7 +12,8 @@ import re import string import sys -from typing import Any, Sequence +from collections.abc import Sequence +from typing import Any from .errors import DistutilsArgError, DistutilsGetoptError @@ -167,8 +168,7 @@ def _grok_option_table(self): # noqa: C901 if not ((short is None) or (isinstance(short, str) and len(short) == 1)): raise DistutilsGetoptError( - f"invalid short option '{short}': " - "must a single character or None" + f"invalid short option '{short}': must a single character or None" ) self.repeat[long] = repeat diff --git a/distutils/filelist.py b/distutils/filelist.py index 44ae9e67..9857b195 100644 --- a/distutils/filelist.py +++ b/distutils/filelist.py @@ -127,10 +127,7 @@ def process_template_line(self, line): # noqa: C901 for pattern in patterns: if not self.exclude_pattern(pattern, anchor=True): log.warning( - ( - "warning: no previously-included files " - "found matching '%s'" - ), + "warning: no previously-included files found matching '%s'", pattern, ) diff --git a/distutils/spawn.py b/distutils/spawn.py index 107b0113..ba280334 100644 --- a/distutils/spawn.py +++ b/distutils/spawn.py @@ -12,7 +12,7 @@ import subprocess import sys import warnings -from typing import Mapping +from collections.abc import Mapping from ._log import log from .debug import DEBUG diff --git a/distutils/tests/__init__.py b/distutils/tests/__init__.py index 93fbf490..5a8ab061 100644 --- a/distutils/tests/__init__.py +++ b/distutils/tests/__init__.py @@ -8,7 +8,7 @@ """ import shutil -from typing import Sequence +from collections.abc import Sequence def missing_compiler_executable(cmd_names: Sequence[str] = []): # pragma: no cover diff --git a/distutils/tests/test_file_util.py b/distutils/tests/test_file_util.py index 85ac2136..a75d4a03 100644 --- a/distutils/tests/test_file_util.py +++ b/distutils/tests/test_file_util.py @@ -44,18 +44,19 @@ def test_move_file_verbosity(self, caplog): def test_move_file_exception_unpacking_rename(self): # see issue 22182 - with mock.patch("os.rename", side_effect=OSError("wrong", 1)), pytest.raises( - DistutilsFileError + with ( + mock.patch("os.rename", side_effect=OSError("wrong", 1)), + pytest.raises(DistutilsFileError), ): jaraco.path.build({self.source: 'spam eggs'}) move_file(self.source, self.target, verbose=False) def test_move_file_exception_unpacking_unlink(self): # see issue 22182 - with mock.patch( - "os.rename", side_effect=OSError(errno.EXDEV, "wrong") - ), mock.patch("os.unlink", side_effect=OSError("wrong", 1)), pytest.raises( - DistutilsFileError + with ( + mock.patch("os.rename", side_effect=OSError(errno.EXDEV, "wrong")), + mock.patch("os.unlink", side_effect=OSError("wrong", 1)), + pytest.raises(DistutilsFileError), ): jaraco.path.build({self.source: 'spam eggs'}) move_file(self.source, self.target, verbose=False) diff --git a/distutils/tests/test_spawn.py b/distutils/tests/test_spawn.py index fd7b669c..fcbc765e 100644 --- a/distutils/tests/test_spawn.py +++ b/distutils/tests/test_spawn.py @@ -73,9 +73,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 @@ -87,9 +90,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 @@ -103,16 +107,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 diff --git a/distutils/tests/test_unixccompiler.py b/distutils/tests/test_unixccompiler.py index 50b66544..16953287 100644 --- a/distutils/tests/test_unixccompiler.py +++ b/distutils/tests/test_unixccompiler.py @@ -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'] diff --git a/distutils/tests/test_version.py b/distutils/tests/test_version.py index 1508e1cc..b68f0977 100644 --- a/distutils/tests/test_version.py +++ b/distutils/tests/test_version.py @@ -53,9 +53,9 @@ def test_cmp_strict(self): res = StrictVersion(v1)._cmp(v2) assert res == wanted, f'cmp({v1}, {v2}) should be {wanted}, got {res}' res = StrictVersion(v1)._cmp(object()) - assert ( - res is NotImplemented - ), f'cmp({v1}, {v2}) should be NotImplemented, got {res}' + assert res is NotImplemented, ( + f'cmp({v1}, {v2}) should be NotImplemented, got {res}' + ) def test_cmp(self): versions = ( @@ -75,6 +75,6 @@ def test_cmp(self): res = LooseVersion(v1)._cmp(v2) assert res == wanted, f'cmp({v1}, {v2}) should be {wanted}, got {res}' res = LooseVersion(v1)._cmp(object()) - assert ( - res is NotImplemented - ), f'cmp({v1}, {v2}) should be NotImplemented, got {res}' + assert res is NotImplemented, ( + f'cmp({v1}, {v2}) should be NotImplemented, got {res}' + ) diff --git a/distutils/version.py b/distutils/version.py index 942b56bf..2223ee9c 100644 --- a/distutils/version.py +++ b/distutils/version.py @@ -53,8 +53,7 @@ def __init__(self, vstring=None): if vstring: self.parse(vstring) warnings.warn( - "distutils Version classes are deprecated. " - "Use packaging.version instead.", + "distutils Version classes are deprecated. Use packaging.version instead.", DeprecationWarning, stacklevel=2, ) diff --git a/ruff.toml b/ruff.toml index 9c780183..0cc5b267 100644 --- a/ruff.toml +++ b/ruff.toml @@ -19,6 +19,10 @@ extend-select = [ "YTT", ] ignore = [ + # TODO: Fix these new violations in Ruff 0.8.0 + "UP031", + "UP036", + # https://docs.astral.sh/ruff/formatter/#conflicting-lint-rules "W191", "E111",