From 22a9da263a1c593cecf3133e572e95d163040636 Mon Sep 17 00:00:00 2001 From: Avasam Date: Tue, 20 Aug 2024 22:29:12 -0400 Subject: [PATCH] Ruff: enable all pyflakes and perf rules --- ruff.toml | 8 +++++--- setuptools/command/easy_install.py | 2 +- setuptools/tests/test_integration.py | 9 +++------ setuptools/tests/test_manifest.py | 8 +------- 4 files changed, 10 insertions(+), 17 deletions(-) diff --git a/ruff.toml b/ruff.toml index b55b4e8067..ddae5009ed 100644 --- a/ruff.toml +++ b/ruff.toml @@ -7,20 +7,22 @@ exclude = [ [lint] extend-select = [ "C901", - "PERF401", "W", # local "ANN2", # missing-return-type-* - "FA", # flake8-future-annotations + "F", # Pyflakes "F404", # late-future-import + "FA", # flake8-future-annotations "I", # isort + "PERF", # Perflint "PYI", # flake8-pyi + "TRY", # tryceratops "UP", # pyupgrade - "TRY", "YTT", # flake8-2020 ] ignore = [ + "PERF203", # try-except-in-loop, micro-optimisation with many false-positive. Worth checking but don't block CI "TRY003", # raise-vanilla-args, avoid multitude of exception classes "TRY301", # raise-within-try, it's handy "UP015", # redundant-open-modes, explicit is preferred diff --git a/setuptools/command/easy_install.py b/setuptools/command/easy_install.py index 54d1e48449..a8c43321d7 100644 --- a/setuptools/command/easy_install.py +++ b/setuptools/command/easy_install.py @@ -2183,7 +2183,7 @@ def get_args(cls, dist, header=None): spec = str(dist.as_requirement()) for type_ in 'console', 'gui': group = type_ + '_scripts' - for name, ep in dist.get_entry_map(group).items(): + for name in dist.get_entry_map(group).keys(): cls._ensure_safe_name(name) script_text = cls.template % locals() args = cls._get_script_args(type_, name, header, script_text) diff --git a/setuptools/tests/test_integration.py b/setuptools/tests/test_integration.py index b0e7d67b5e..ccccf4a2c7 100644 --- a/setuptools/tests/test_integration.py +++ b/setuptools/tests/test_integration.py @@ -7,6 +7,7 @@ import os import sys import urllib.request +from importlib.util import find_spec import pytest @@ -23,12 +24,8 @@ def setup_module(module): packages = 'stevedore', 'virtualenvwrapper', 'pbr', 'novaclient' for pkg in packages: - try: - __import__(pkg) - tmpl = "Integration tests cannot run when {pkg} is installed" - pytest.skip(tmpl.format(**locals())) - except ImportError: - pass + if find_spec(pkg) is not None: + pytest.skip(f"Integration tests cannot run when {pkg} is installed") try: urllib.request.urlopen('https://pypi.python.org/pypi') diff --git a/setuptools/tests/test_manifest.py b/setuptools/tests/test_manifest.py index ae5572b83c..444c7a3689 100644 --- a/setuptools/tests/test_manifest.py +++ b/setuptools/tests/test_manifest.py @@ -485,14 +485,8 @@ def test_process_template_line_invalid(self): 'prune', 'blarg', ): - try: + with pytest.raises(DistutilsTemplateError): file_list.process_template_line(action) - except DistutilsTemplateError: - pass - except Exception: - assert False, "Incorrect error thrown" - else: - assert False, "Should have thrown an error" def test_include(self, caplog): caplog.set_level(logging.DEBUG)