Skip to content

Commit

Permalink
👹 Feed the hobgoblins (delint).
Browse files Browse the repository at this point in the history
  • Loading branch information
jaraco committed Dec 23, 2024
1 parent 49e362c commit 3e0a130
Show file tree
Hide file tree
Showing 13 changed files with 53 additions and 53 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 @@ -444,8 +444,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 @@ -673,8 +672,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
3 changes: 1 addition & 2 deletions distutils/command/install_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
3 changes: 1 addition & 2 deletions distutils/fancy_getopt.py
Original file line number Diff line number Diff line change
Expand Up @@ -167,8 +167,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
5 changes: 3 additions & 2 deletions distutils/tests/test_dir_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,8 +106,9 @@ def test_copy_tree_exception_in_listdir(self):
"""
An exception in listdir should raise a DistutilsFileError
"""
with mock.patch("os.listdir", side_effect=OSError()), pytest.raises(
errors.DistutilsFileError
with (
mock.patch("os.listdir", side_effect=OSError()),
pytest.raises(errors.DistutilsFileError),
):
src = self.tempdirs[-1]
dir_util.copy_tree(src, None)
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}'
)
1 change: 1 addition & 0 deletions distutils/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -504,6 +504,7 @@ def is_mingw():
"""
return sys.platform == 'win32' and get_platform().startswith('mingw')


def is_freethreaded():
"""Return True if the Python interpreter is built with free threading support."""
return bool(sysconfig.get_config_var('Py_GIL_DISABLED'))
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

0 comments on commit 3e0a130

Please sign in to comment.