Skip to content

Commit

Permalink
Merge pull request #314 from Avasam/Ruff-0.8.0
Browse files Browse the repository at this point in the history
Run Ruff 0.8.0 (automated fixes only)
  • Loading branch information
jaraco authored Dec 26, 2024
2 parents b24919b + 1bae350 commit a9f832b
Show file tree
Hide file tree
Showing 14 changed files with 58 additions and 55 deletions.
3 changes: 1 addition & 2 deletions distutils/command/build_clib.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
6 changes: 2 additions & 4 deletions distutils/command/build_ext.py
Original file line number Diff line number Diff line change
Expand Up @@ -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])
Expand Down Expand Up @@ -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 -----------------------------------------------
Expand Down
5 changes: 1 addition & 4 deletions distutils/command/check.py
Original file line number Diff line number Diff line change
Expand Up @@ -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'),
]
Expand Down
5 changes: 2 additions & 3 deletions distutils/command/install_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)"),
Expand Down
6 changes: 3 additions & 3 deletions distutils/fancy_getopt.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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
Expand Down
5 changes: 1 addition & 4 deletions distutils/filelist.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
)

Expand Down
2 changes: 1 addition & 1 deletion distutils/spawn.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion distutils/tests/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
13 changes: 7 additions & 6 deletions distutils/tests/test_file_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
34 changes: 22 additions & 12 deletions distutils/tests/test_spawn.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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

Expand All @@ -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

Expand Down
13 changes: 6 additions & 7 deletions distutils/tests/test_unixccompiler.py
Original file line number Diff line number Diff line change
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: 6 additions & 6 deletions distutils/tests/test_version.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 = (
Expand All @@ -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}'
)
3 changes: 1 addition & 2 deletions distutils/version.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
)
Expand Down
4 changes: 4 additions & 0 deletions ruff.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down

0 comments on commit a9f832b

Please sign in to comment.