From d9d6f2782c583ee4c2438d5cc3a2bdab4cd107a9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bern=C3=A1t=20G=C3=A1bor?= Date: Mon, 3 Jul 2023 16:14:53 -0700 Subject: [PATCH] Fix MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Bernát Gábor --- docs/render_cli.py | 4 +--- src/virtualenv/create/creator.py | 2 +- src/virtualenv/discovery/builtin.py | 4 ++-- src/virtualenv/discovery/windows/pep514.py | 6 ++---- .../seed/embed/via_app_data/pip_install/symlink.py | 2 +- src/virtualenv/seed/embed/via_app_data/via_app_data.py | 2 +- src/virtualenv/seed/wheels/periodic_update.py | 2 +- src/virtualenv/seed/wheels/util.py | 2 +- src/virtualenv/util/path/_permission.py | 2 +- tasks/make_zipapp.py | 10 +++++----- tasks/upgrade_wheels.py | 4 ++-- tests/conftest.py | 2 +- tests/unit/seed/wheels/test_periodic_update.py | 4 ++-- tests/unit/test_util.py | 6 ++---- 14 files changed, 23 insertions(+), 29 deletions(-) diff --git a/docs/render_cli.py b/docs/render_cli.py index 557bb80d6..71e79ab68 100644 --- a/docs/render_cli.py +++ b/docs/render_cli.py @@ -34,9 +34,7 @@ def run(self): core_result = parse_parser(parser_creator()) core_result["action_groups"] = [i for i in core_result["action_groups"] if i["title"] not in CUSTOM] - content = [] - for i in core_result["action_groups"]: - content.append(self._build_table(i["options"], i["title"], i["description"])) + content = [self._build_table(i["options"], i["title"], i["description"]) for i in core_result["action_groups"]] for key, name_to_class in CUSTOM.items(): section = n.section("", ids=[f"section-{key}"]) title = n.title("", key) diff --git a/src/virtualenv/create/creator.py b/src/virtualenv/create/creator.py index 8ff54166e..06f9d39ba 100644 --- a/src/virtualenv/create/creator.py +++ b/src/virtualenv/create/creator.py @@ -121,7 +121,7 @@ def non_write_able(dest, value): if trip == char: continue raise ValueError(trip) # noqa: TRY301 - except ValueError: + except ValueError: # noqa: PERF203 refused[char] = None if refused: bad = "".join(refused.keys()) diff --git a/src/virtualenv/discovery/builtin.py b/src/virtualenv/discovery/builtin.py index 92d96a91b..1285b82dc 100644 --- a/src/virtualenv/discovery/builtin.py +++ b/src/virtualenv/discovery/builtin.py @@ -77,7 +77,7 @@ def propose_interpreters(spec, try_first_with, app_data, env=None): # noqa: C90 path = os.path.abspath(py_exe) try: os.lstat(path) # Windows Store Python does not work with os.path.exists, but does for os.lstat - except OSError: + except OSError: # noqa: PERF203 pass else: yield PythonInfo.from_exe(os.path.abspath(path), app_data, env=env), True @@ -145,7 +145,7 @@ def __repr__(self) -> str: file_path = os.path.join(self.path, file_name) if os.path.isdir(file_path) or not os.access(file_path, os.X_OK): continue - except OSError: + except OSError: # noqa: PERF203 pass content += " " content += file_name diff --git a/src/virtualenv/discovery/windows/pep514.py b/src/virtualenv/discovery/windows/pep514.py index ff1d7c169..05b4f2c30 100644 --- a/src/virtualenv/discovery/windows/pep514.py +++ b/src/virtualenv/discovery/windows/pep514.py @@ -15,7 +15,7 @@ def enum_keys(key): while True: try: yield winreg.EnumKey(key, at) - except OSError: + except OSError: # noqa: PERF203 break at += 1 @@ -144,9 +144,7 @@ def msg(path, what): def _run(): basicConfig() - interpreters = [] - for spec in discover_pythons(): - interpreters.append(repr(spec)) + interpreters = [repr(spec) for spec in discover_pythons()] print("\n".join(sorted(interpreters))) # noqa: T201 diff --git a/src/virtualenv/seed/embed/via_app_data/pip_install/symlink.py b/src/virtualenv/seed/embed/via_app_data/pip_install/symlink.py index 6bc5e51c0..5f8509c8d 100644 --- a/src/virtualenv/seed/embed/via_app_data/pip_install/symlink.py +++ b/src/virtualenv/seed/embed/via_app_data/pip_install/symlink.py @@ -32,7 +32,7 @@ def _generate_new_files(self): rel = file.relative_to(self._image_dir) if len(rel.parts) > 1: continue - except ValueError: + except ValueError: # noqa: PERF203 pass new_files.add(file) return new_files diff --git a/src/virtualenv/seed/embed/via_app_data/via_app_data.py b/src/virtualenv/seed/embed/via_app_data/via_app_data.py index 7e58bfc6e..6e6162e94 100644 --- a/src/virtualenv/seed/embed/via_app_data/via_app_data.py +++ b/src/virtualenv/seed/embed/via_app_data/via_app_data.py @@ -93,7 +93,7 @@ def _get(distribution, version): ) if result is not None: break - except Exception as exception: + except Exception as exception: # noqa: PERF203 logging.exception("fail") failure = exception if failure: diff --git a/src/virtualenv/seed/wheels/periodic_update.py b/src/virtualenv/seed/wheels/periodic_update.py index 911d5e3ba..7d743540f 100644 --- a/src/virtualenv/seed/wheels/periodic_update.py +++ b/src/virtualenv/seed/wheels/periodic_update.py @@ -350,7 +350,7 @@ def _pypi_get_distribution_info(distribution): with urlopen(url, context=context) as file_handler: # noqa: S310 content = json.load(file_handler) break - except URLError as exception: + except URLError as exception: # noqa: PERF203 logging.error("failed to access %s because %r", url, exception) # noqa: TRY400 except Exception as exception: # noqa: BLE001 logging.error("failed to access %s because %r", url, exception) # noqa: TRY400 diff --git a/src/virtualenv/seed/wheels/util.py b/src/virtualenv/seed/wheels/util.py index cfe537ea5..cfc0098a9 100644 --- a/src/virtualenv/seed/wheels/util.py +++ b/src/virtualenv/seed/wheels/util.py @@ -35,7 +35,7 @@ def as_version_tuple(version): for part in version.split(".")[0:3]: try: result.append(int(part)) - except ValueError: + except ValueError: # noqa: PERF203 break if not result: raise ValueError(version) diff --git a/src/virtualenv/util/path/_permission.py b/src/virtualenv/util/path/_permission.py index 8dcad0ce9..f3e9b625c 100644 --- a/src/virtualenv/util/path/_permission.py +++ b/src/virtualenv/util/path/_permission.py @@ -14,7 +14,7 @@ def make_exe(filename): mode |= level filename.chmod(mode) break - except OSError: + except OSError: # noqa: PERF203 continue diff --git a/tasks/make_zipapp.py b/tasks/make_zipapp.py index 40f435165..117382912 100644 --- a/tasks/make_zipapp.py +++ b/tasks/make_zipapp.py @@ -188,11 +188,11 @@ def get_dependencies(whl, version): @staticmethod def _marker_at(markers, key): - positions = [] - for i, m in enumerate(markers): - if isinstance(m, tuple) and len(m) == 3 and m[0].value == key: # noqa: PLR2004 - positions.append(i) - return positions + return [ + i + for i, m in enumerate(markers) + if isinstance(m, tuple) and len(m) == 3 and m[0].value == key # noqa: PLR2004 + ] @staticmethod def _del_marker_at(markers, at): diff --git a/tasks/upgrade_wheels.py b/tasks/upgrade_wheels.py index daa289424..126c35614 100644 --- a/tasks/upgrade_wheels.py +++ b/tasks/upgrade_wheels.py @@ -77,7 +77,7 @@ def run(): # noqa: C901 del removed[key] lines.append(text) for key, versions in removed.items(): - lines.append(f"Removed {key} of {fmt_version(versions)}") + lines.append(f"Removed {key} of {fmt_version(versions)}") # noqa: PERF401 lines.append("") changelog = "\n".join(lines) print(changelog) # noqa: T201 @@ -87,7 +87,7 @@ def run(): # noqa: C901 for package in sorted(new_batch.keys()): for folder, version in sorted(folders.items()): if (folder / package).exists(): - support_table[version].append(package) + support_table[version].append(package) # noqa: PERF401 support_table = {k: OrderedDict((i.split("-")[0], i) for i in v) for k, v in support_table.items()} bundle = ",".join( f"{v!r}: {{ {','.join(f'{p!r}: {f!r}' for p, f in line.items())} }}" for v, line in support_table.items() diff --git a/tests/conftest.py b/tests/conftest.py index a7aca5668..1175aa952 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -285,7 +285,7 @@ def special_char_name(): trip = char.encode(encoding, errors="strict").decode(encoding) if char == trip: result += char - except ValueError: + except ValueError: # noqa: PERF203 continue assert result return result diff --git a/tests/unit/seed/wheels/test_periodic_update.py b/tests/unit/seed/wheels/test_periodic_update.py index fe563a232..736c70c8f 100644 --- a/tests/unit/seed/wheels/test_periodic_update.py +++ b/tests/unit/seed/wheels/test_periodic_update.py @@ -70,8 +70,8 @@ def _do_update( # noqa: PLR0913 assert " new entries found:\n" in caplog.text assert "\tNewVersion(" in caplog.text packages = defaultdict(list) - for i in do_update_mock.call_args_list: - packages[i[1]["distribution"]].append(i[1]["for_py_version"]) + for args in do_update_mock.call_args_list: + packages[args[1]["distribution"]].append(args[1]["for_py_version"]) # noqa: PERF401 packages = {key: sorted(value) for key, value in packages.items()} versions = sorted(BUNDLE_SUPPORT.keys()) expected = {"setuptools": versions, "wheel": versions, "pip": versions} diff --git a/tests/unit/test_util.py b/tests/unit/test_util.py index 2ad1d8f4c..b83c247a2 100644 --- a/tests/unit/test_util.py +++ b/tests/unit/test_util.py @@ -27,12 +27,10 @@ def recreate_target_file(): target_file.touch() with concurrent.futures.ThreadPoolExecutor() as executor: - tasks = [] - for _ in range(4): - tasks.append(executor.submit(recreate_target_file)) + tasks = [executor.submit(recreate_target_file) for _ in range(4)] concurrent.futures.wait(tasks) for task in tasks: try: task.result() - except Exception: # noqa: BLE001 + except Exception: # noqa: BLE001, PERF203 pytest.fail(traceback.format_exc())