From 70ea46108acf9517e43333b6f09d16854114371b Mon Sep 17 00:00:00 2001 From: Henry Schreiner Date: Mon, 14 Jun 2021 14:50:39 -0400 Subject: [PATCH] chore: add pyupgrade --- .pre-commit-config.yaml | 5 +++++ scripts/convert_to_generic_platform_wheel.py | 3 +-- scripts/update_cmake_version.py | 10 +++++----- src/cmake/_version.py | 9 ++++----- tests/__init__.py | 1 - tests/test_cmake.py | 1 - tests/test_distribution.py | 3 +-- versioneer.py | 15 +++++++-------- 8 files changed, 23 insertions(+), 24 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index a9eeae64..d030b907 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -13,6 +13,11 @@ repos: - id: requirements-txt-fixer - id: trailing-whitespace +- repo: https://github.com/asottile/pyupgrade + rev: v2.19.1 + hooks: + - id: pyupgrade + - repo: https://gitlab.com/pycqa/flake8 rev: 3.9.2 hooks: diff --git a/scripts/convert_to_generic_platform_wheel.py b/scripts/convert_to_generic_platform_wheel.py index dc75e030..06741ad3 100644 --- a/scripts/convert_to_generic_platform_wheel.py +++ b/scripts/convert_to_generic_platform_wheel.py @@ -1,4 +1,3 @@ - import argparse import logging import os @@ -94,7 +93,7 @@ def _convert_to_generic_platform_wheel(wheel_ctx, py2_py3, additional_platforms) logger.debug('Previous pyver tags: %s', ', '.join(original_pyver_tags)) pyver_tags = _to_generic_pyver(original_pyver_tags) if py2_py3: - if len(set(["py2", "py3"]) & set(pyver_tags)) == 0: + if len({"py2", "py3"} & set(pyver_tags)) == 0: raise ValueError("pyver_tags does not contain py2 nor py3") pyver_tags = list(sorted(set(pyver_tags + ["py2", "py3"]))) if pyver_tags != original_pyver_tags: diff --git a/scripts/update_cmake_version.py b/scripts/update_cmake_version.py index 76defeb9..6e277759 100755 --- a/scripts/update_cmake_version.py +++ b/scripts/update_cmake_version.py @@ -84,19 +84,19 @@ def get_cmake_archive_urls_and_sha256s(version, verbose=False): for identifier in set(expected_files.values()) - set(urls.keys()): missing_files.append(expected_files_by_identifier[identifier]) raise RuntimeError( - "Couldn't find %s at %s" % (missing_files, files_base_url) + "Couldn't find {} at {}".format(missing_files, files_base_url) ) # combine the URLs and SHA256s into a single dictionary zipped = {} for value in expected_files.values(): - print("[%s]\n%s\n%s\n" % (value, urls[value], shas[value])) + print("[{}]\n{}\n{}\n".format(value, urls[value], shas[value])) zipped[value] = (urls[value], shas[value]) assert len(zipped) == len(expected_files) if verbose: for identifier, (url, sha256) in zipped.items(): - print("[%s]\n%s\n%s\n" % (identifier, url, sha256)) + print("[{}]\n{}\n{}\n".format(identifier, url, sha256)) return zipped @@ -147,7 +147,7 @@ def update_cmake_urls_script(version): cmake_urls_filename = "CMakeUrls.cmake" cmake_urls_filepath = os.path.join(ROOT_DIR, cmake_urls_filename) - msg = "Updating '%s' with CMake version %s" % (cmake_urls_filename, version) + msg = "Updating '{}' with CMake version {}".format(cmake_urls_filename, version) with _log(msg), open(cmake_urls_filepath, "w") as cmake_file: cmake_file.write(content) @@ -169,7 +169,7 @@ def update_docs(version): pattern = re.compile( r"CMake \d.(\d)+.\d " ) - replacement = "CMake %s " % ( + replacement = "CMake {} ".format( version, _major_minor(version), ) diff --git a/src/cmake/_version.py b/src/cmake/_version.py index e1b47b21..141cb067 100644 --- a/src/cmake/_version.py +++ b/src/cmake/_version.py @@ -1,4 +1,3 @@ - # This file helps to compute a version number in source trees obtained from # git-archive tarball (such as those provided by githubs download-from-tag # feature). Distribution tarballs (built by setup.py sdist) and build @@ -91,7 +90,7 @@ def run_command(commands, args, cwd=None, verbose=False, hide_stderr=False, return None, None else: if verbose: - print("unable to find command, tried %s" % (commands,)) + print("unable to find command, tried {}".format(commands)) return None, None stdout = p.communicate()[0].strip() if sys.version_info[0] >= 3: @@ -177,11 +176,11 @@ def git_versions_from_keywords(keywords, tag_prefix, verbose): if verbose: print("keywords are unexpanded, not using") raise NotThisMethod("unexpanded keywords, not a git-archive tarball") - refs = set([r.strip() for r in refnames.strip("()").split(",")]) + refs = {r.strip() for r in refnames.strip("()").split(",")} # starting in git-1.8.3, tags are listed as "tag: foo-1.0" instead of # just "foo-1.0". If we see a "tag: " prefix, prefer those. TAG = "tag: " - tags = set([r[len(TAG):] for r in refs if r.startswith(TAG)]) + tags = {r[len(TAG):] for r in refs if r.startswith(TAG)} if not tags: # Either we're using git < 1.8.3, or there really are no tags. We use # a heuristic: assume all version tags have a digit. The old git %d @@ -190,7 +189,7 @@ def git_versions_from_keywords(keywords, tag_prefix, verbose): # between branches and tags. By ignoring refnames without digits, we # filter out many common branch names like "release" and # "stabilization", as well as "HEAD" and "master". - tags = set([r for r in refs if re.search(r'\d', r)]) + tags = {r for r in refs if re.search(r'\d', r)} if verbose: print("discarding '%s', no digits" % ",".join(refs - tags)) if verbose: diff --git a/tests/__init__.py b/tests/__init__.py index c22fd812..fd1659ac 100644 --- a/tests/__init__.py +++ b/tests/__init__.py @@ -1,4 +1,3 @@ - import sys from contextlib import contextmanager diff --git a/tests/test_cmake.py b/tests/test_cmake.py index 42a32342..6f0c7d76 100644 --- a/tests/test_cmake.py +++ b/tests/test_cmake.py @@ -1,4 +1,3 @@ - import pytest import textwrap diff --git a/tests/test_distribution.py b/tests/test_distribution.py index 88f37864..614b718c 100644 --- a/tests/test_distribution.py +++ b/tests/test_distribution.py @@ -1,4 +1,3 @@ - import os import pytest import textwrap @@ -14,7 +13,7 @@ def _check_cmake_install(virtualenv, tmpdir): for executable_name in ["cmake", "cpack", "ctest"]: output = virtualenv.run( "%s --version" % executable_name, capture=True).splitlines()[0] - assert output == "%s version %s" % (executable_name, expected_version) + assert output == "{} version {}".format(executable_name, expected_version) test_script = tmpdir.join("test_cmake.cmake") test_script.write(textwrap.dedent(r""" diff --git a/versioneer.py b/versioneer.py index 1e28dbff..3d0c438f 100644 --- a/versioneer.py +++ b/versioneer.py @@ -1,4 +1,3 @@ - # Version: 0.17 """The Versioneer - like a rocketeer, but for versions. @@ -404,7 +403,7 @@ def run_command(commands, args, cwd=None, verbose=False, hide_stderr=False, return None, None else: if verbose: - print("unable to find command, tried %s" % (commands,)) + print("unable to find command, tried {}".format(commands)) return None, None stdout = p.communicate()[0].strip() if sys.version_info[0] >= 3: @@ -415,7 +414,7 @@ def run_command(commands, args, cwd=None, verbose=False, hide_stderr=False, print("stdout was %s" % stdout) return None, p.returncode return stdout, p.returncode -LONG_VERSION_PY['git'] = ''' +LONG_VERSION_PY['git'] = r''' # This file helps to compute a version number in source trees obtained from # git-archive tarball (such as those provided by githubs download-from-tag # feature). Distribution tarballs (built by setup.py sdist) and build @@ -986,11 +985,11 @@ def git_versions_from_keywords(keywords, tag_prefix, verbose): if verbose: print("keywords are unexpanded, not using") raise NotThisMethod("unexpanded keywords, not a git-archive tarball") - refs = set([r.strip() for r in refnames.strip("()").split(",")]) + refs = {r.strip() for r in refnames.strip("()").split(",")} # starting in git-1.8.3, tags are listed as "tag: foo-1.0" instead of # just "foo-1.0". If we see a "tag: " prefix, prefer those. TAG = "tag: " - tags = set([r[len(TAG):] for r in refs if r.startswith(TAG)]) + tags = {r[len(TAG):] for r in refs if r.startswith(TAG)} if not tags: # Either we're using git < 1.8.3, or there really are no tags. We use # a heuristic: assume all version tags have a digit. The old git %d @@ -999,7 +998,7 @@ def git_versions_from_keywords(keywords, tag_prefix, verbose): # between branches and tags. By ignoring refnames without digits, we # filter out many common branch names like "release" and # "stabilization", as well as "HEAD" and "master". - tags = set([r for r in refs if re.search(r'\d', r)]) + tags = {r for r in refs if re.search(r'\d', r)} if verbose: print("discarding '%s', no digits" % ",".join(refs - tags)) if verbose: @@ -1219,7 +1218,7 @@ def write_to_version_file(filename, versions): with open(filename, "w") as f: f.write(SHORT_VERSION_PY % contents) - print("set %s to '%s'" % (filename, versions["version"])) + print("set {} to '{}'".format(filename, versions["version"])) def plus_or_dot(pieces): @@ -1453,7 +1452,7 @@ def get_versions(verbose=False): try: ver = versions_from_file(versionfile_abs) if verbose: - print("got version from file %s %s" % (versionfile_abs, ver)) + print("got version from file {} {}".format(versionfile_abs, ver)) return ver except NotThisMethod: pass