diff --git a/distutils/command/build_ext.py b/distutils/command/build_ext.py index df623d7e..3f2f1eb8 100644 --- a/distutils/command/build_ext.py +++ b/distutils/command/build_ext.py @@ -669,8 +669,7 @@ def find_swig(self): fn = os.path.join(f"c:\\swig{vers}", "swig.exe") if os.path.isfile(fn): return fn - else: - return "swig.exe" + return "swig.exe" else: raise DistutilsPlatformError( f"I don't know how to find (much less run) SWIG on platform '{os.name}'" diff --git a/distutils/command/build_py.py b/distutils/command/build_py.py index d6ec7d10..c3fc3ad0 100644 --- a/distutils/command/build_py.py +++ b/distutils/command/build_py.py @@ -167,22 +167,21 @@ def get_package_dir(self, package): else: tail.insert(0, pdir) return os.path.join(*tail) + # Oops, got all the way through 'path' without finding a + # match in package_dir. If package_dir defines a directory + # for the root (nameless) package, then fallback on it; + # otherwise, we might as well have not consulted + # package_dir at all, as we just use the directory implied + # by 'tail' (which should be the same as the original value + # of 'path' at this point). + pdir = self.package_dir.get('') + if pdir is not None: + tail.insert(0, pdir) + + if tail: + return os.path.join(*tail) else: - # Oops, got all the way through 'path' without finding a - # match in package_dir. If package_dir defines a directory - # for the root (nameless) package, then fallback on it; - # otherwise, we might as well have not consulted - # package_dir at all, as we just use the directory implied - # by 'tail' (which should be the same as the original value - # of 'path' at this point). - pdir = self.package_dir.get('') - if pdir is not None: - tail.insert(0, pdir) - - if tail: - return os.path.join(*tail) - else: - return '' + return '' def check_package(self, package, package_dir): # Empty dir name means current directory, which we can probably diff --git a/distutils/command/config.py b/distutils/command/config.py index 9818418f..c8f37029 100644 --- a/distutils/command/config.py +++ b/distutils/command/config.py @@ -103,8 +103,7 @@ def _gen_temp_sourcefile(self, body, headers, lang): filename = "_configtest" + LANG_EXT[lang] with open(filename, "w", encoding='utf-8') as file: if headers: - for header in headers: - file.write(f"#include <{header}>\n") + file.writelines(f"#include <{header}>\n" for header in headers) file.write("\n") file.write(body) if body[-1] != "\n": diff --git a/distutils/command/sdist.py b/distutils/command/sdist.py index e64cc829..0bfd16f1 100644 --- a/distutils/command/sdist.py +++ b/distutils/command/sdist.py @@ -76,7 +76,7 @@ def checking_metadata(self) -> bool: ( 'keep-temp', 'k', - "keep the distribution tree around after creating " + "archive file(s)", + "keep the distribution tree around after creating archive file(s)", ), ( 'dist-dir=', @@ -206,8 +206,7 @@ def get_file_list(self) -> None: if not template_exists: self.warn( - ("manifest template '%s' does not exist " + "(using default file list)") - % self.template + f"manifest template '{self.template}' does not exist (using default file list)" ) self.filelist.findall() diff --git a/distutils/compilers/C/base.py b/distutils/compilers/C/base.py index 4159feae..ef267466 100644 --- a/distutils/compilers/C/base.py +++ b/distutils/compilers/C/base.py @@ -191,12 +191,12 @@ class (via the 'executables' class attribute), but most will have: # discovered at run-time, since there are many different ways to do # basically the same things with Unix C compilers. - for key in kwargs: + for key, value in kwargs.items(): if key not in self.executables: raise ValueError( f"unknown executable '{key}' for class {self.__class__.__name__}" ) - self.set_executable(key, kwargs[key]) + self.set_executable(key, value) def set_executable(self, key, value): if isinstance(value, str): @@ -205,11 +205,9 @@ def set_executable(self, key, value): setattr(self, key, value) def _find_macro(self, name): - i = 0 - for defn in self.macros: + for i, defn in enumerate(self.macros): if defn[0] == name: return i - i += 1 return None def _check_macro_definitions(self, definitions): @@ -1013,10 +1011,10 @@ def object_filenames( ) -> list[str]: if output_dir is None: output_dir = '' - return list( + return [ self._make_out_path(output_dir, strip_dir, src_name) for src_name in source_filenames - ) + ] @property def out_extensions(self): diff --git a/distutils/compilers/C/msvc.py b/distutils/compilers/C/msvc.py index 1f50fa50..82dad25c 100644 --- a/distutils/compilers/C/msvc.py +++ b/distutils/compilers/C/msvc.py @@ -609,6 +609,5 @@ def find_library_file(self, dirs, lib, debug=False): libfile = os.path.join(dir, self.library_filename(name)) if os.path.isfile(libfile): return libfile - else: - # Oops, didn't find it in *any* of 'dirs' - return None + # Oops, didn't find it in *any* of 'dirs' + return None diff --git a/distutils/compilers/C/unix.py b/distutils/compilers/C/unix.py index 85810d75..05490d98 100644 --- a/distutils/compilers/C/unix.py +++ b/distutils/compilers/C/unix.py @@ -409,7 +409,7 @@ def find_library_file(self, dirs, lib, debug=False): """ lib_names = ( self.library_filename(lib, lib_type=type) - for type in 'dylib xcode_stub shared static'.split() + for type in ('dylib', 'xcode_stub', 'shared', 'static') ) roots = map(self._library_root, dirs) diff --git a/distutils/core.py b/distutils/core.py index bd62546b..b023fea9 100644 --- a/distutils/core.py +++ b/distutils/core.py @@ -213,7 +213,7 @@ def run_commands(dist): if DEBUG: raise else: - raise SystemExit("error: " + str(msg)) + raise SystemExit(f"error: {msg}") return dist diff --git a/distutils/dist.py b/distutils/dist.py index d2b257b2..646981fd 100644 --- a/distutils/dist.py +++ b/distutils/dist.py @@ -492,7 +492,7 @@ def parse_command_line(self): parser.set_aliases({'licence': 'license'}) args = parser.getopt(args=self.script_args, object=self) option_order = parser.get_option_order() - logging.getLogger().setLevel(logging.WARN - 10 * self.verbose) + logging.getLogger().setLevel(logging.WARNING - 10 * self.verbose) # for display options we return immediately if self.handle_display_options(option_order): diff --git a/distutils/log.py b/distutils/log.py index 8abb09cf..b2ca0e39 100644 --- a/distutils/log.py +++ b/distutils/log.py @@ -11,7 +11,7 @@ DEBUG = logging.DEBUG INFO = logging.INFO -WARN = logging.WARN +WARN = logging.WARNING ERROR = logging.ERROR FATAL = logging.FATAL @@ -31,7 +31,7 @@ def set_threshold(level): def set_verbosity(v): if v <= 0: - set_threshold(logging.WARN) + set_threshold(logging.WARNING) elif v == 1: set_threshold(logging.INFO) elif v >= 2: diff --git a/distutils/tests/test_core.py b/distutils/tests/test_core.py index bad3fb7e..2f83162e 100644 --- a/distutils/tests/test_core.py +++ b/distutils/tests/test_core.py @@ -101,8 +101,7 @@ def test_run_setup_uses_current_dir(self, tmp_path): distutils.core.run_setup(setup_py) output = sys.stdout.getvalue() - if output.endswith("\n"): - output = output[:-1] + output = output.removesuffix("\n") assert cwd == output def test_run_setup_within_if_main(self, temp_file): diff --git a/distutils/versionpredicate.py b/distutils/versionpredicate.py index fe31b0ed..12c95c67 100644 --- a/distutils/versionpredicate.py +++ b/distutils/versionpredicate.py @@ -129,7 +129,7 @@ def __init__(self, versionPredicateStr): def __str__(self): if self.pred: - seq = [cond + " " + str(ver) for cond, ver in self.pred] + seq = [f"{cond} {ver}" for cond, ver in self.pred] return self.name + " (" + ", ".join(seq) + ")" else: return self.name