From 7dbd7cf11ad69f63b41a37f419ca17a648402f89 Mon Sep 17 00:00:00 2001 From: epenet <6771947+epenet@users.noreply.github.com> Date: Tue, 12 Nov 2024 02:29:38 +0100 Subject: [PATCH] ci: replace flake8 with ruff (#917) * ci: replace flake8 with ruff * fix violations * update lock file --- .flake8 | 3 - poetry.lock | 119 +--------------------------------- pyproject.toml | 7 +- src/syrupy/__init__.py | 2 +- src/syrupy/extensions/base.py | 2 +- src/syrupy/utils.py | 8 +-- tasks/lint.py | 3 +- 7 files changed, 11 insertions(+), 133 deletions(-) delete mode 100644 .flake8 diff --git a/.flake8 b/.flake8 deleted file mode 100644 index 91ccc51e..00000000 --- a/.flake8 +++ /dev/null @@ -1,3 +0,0 @@ -[flake8] -max-line-length=88 -ignore=A005,W503 diff --git a/poetry.lock b/poetry.lock index 1882d898..084b62f9 100644 --- a/poetry.lock +++ b/poetry.lock @@ -1,24 +1,5 @@ # This file is automatically @generated by Poetry 1.8.3 and should not be changed by hand. -[[package]] -name = "attrs" -version = "24.2.0" -description = "Classes Without Boilerplate" -optional = false -python-versions = ">=3.7" -files = [ - {file = "attrs-24.2.0-py3-none-any.whl", hash = "sha256:81921eb96de3191c8258c199618104dd27ac608d9366f5e35d011eae1867ede2"}, - {file = "attrs-24.2.0.tar.gz", hash = "sha256:5cfb1b9148b5b086569baec03f20d7b6bf3bcacc9a42bebf87ffaaca362f6346"}, -] - -[package.extras] -benchmark = ["cloudpickle", "hypothesis", "mypy (>=1.11.1)", "pympler", "pytest (>=4.3.0)", "pytest-codspeed", "pytest-mypy-plugins", "pytest-xdist[psutil]"] -cov = ["cloudpickle", "coverage[toml] (>=5.3)", "hypothesis", "mypy (>=1.11.1)", "pympler", "pytest (>=4.3.0)", "pytest-mypy-plugins", "pytest-xdist[psutil]"] -dev = ["cloudpickle", "hypothesis", "mypy (>=1.11.1)", "pre-commit", "pympler", "pytest (>=4.3.0)", "pytest-mypy-plugins", "pytest-xdist[psutil]"] -docs = ["cogapp", "furo", "myst-parser", "sphinx", "sphinx-notfound-page", "sphinxcontrib-towncrier", "towncrier (<24.7)"] -tests = ["cloudpickle", "hypothesis", "mypy (>=1.11.1)", "pympler", "pytest (>=4.3.0)", "pytest-mypy-plugins", "pytest-xdist[psutil]"] -tests-mypy = ["mypy (>=1.11.1)", "pytest-mypy-plugins"] - [[package]] name = "backports-tarfile" version = "1.2.0" @@ -515,71 +496,6 @@ files = [ [package.extras] testing = ["hatch", "pre-commit", "pytest", "tox"] -[[package]] -name = "flake8" -version = "7.1.1" -description = "the modular source code checker: pep8 pyflakes and co" -optional = false -python-versions = ">=3.8.1" -files = [ - {file = "flake8-7.1.1-py2.py3-none-any.whl", hash = "sha256:597477df7860daa5aa0fdd84bf5208a043ab96b8e96ab708770ae0364dd03213"}, - {file = "flake8-7.1.1.tar.gz", hash = "sha256:049d058491e228e03e67b390f311bbf88fce2dbaa8fa673e7aea87b7198b8d38"}, -] - -[package.dependencies] -mccabe = ">=0.7.0,<0.8.0" -pycodestyle = ">=2.12.0,<2.13.0" -pyflakes = ">=3.2.0,<3.3.0" - -[[package]] -name = "flake8-bugbear" -version = "24.8.19" -description = "A plugin for flake8 finding likely bugs and design problems in your program. Contains warnings that don't belong in pyflakes and pycodestyle." -optional = false -python-versions = ">=3.8.1" -files = [ - {file = "flake8_bugbear-24.8.19-py3-none-any.whl", hash = "sha256:25bc3867f7338ee3b3e0916bf8b8a0b743f53a9a5175782ddc4325ed4f386b89"}, - {file = "flake8_bugbear-24.8.19.tar.gz", hash = "sha256:9b77627eceda28c51c27af94560a72b5b2c97c016651bdce45d8f56c180d2d32"}, -] - -[package.dependencies] -attrs = ">=19.2.0" -flake8 = ">=6.0.0" - -[package.extras] -dev = ["coverage", "hypothesis", "hypothesmith (>=0.2)", "pre-commit", "pytest", "tox"] - -[[package]] -name = "flake8-builtins" -version = "2.5.0" -description = "Check for python builtins being used as variables or parameters" -optional = false -python-versions = ">=3.8" -files = [ - {file = "flake8_builtins-2.5.0-py3-none-any.whl", hash = "sha256:8cac7c52c6f0708c0902b46b385bc7e368a9068965083796f1431c0d2e6550cf"}, - {file = "flake8_builtins-2.5.0.tar.gz", hash = "sha256:bdaa3dd823e4f5308c5e712d19fa5f69daa52781ea874f5ea9c3637bcf56faa6"}, -] - -[package.dependencies] -flake8 = "*" - -[package.extras] -test = ["pytest"] - -[[package]] -name = "flake8-comprehensions" -version = "3.15.0" -description = "A flake8 plugin to help you write better list/set/dict comprehensions." -optional = false -python-versions = ">=3.8" -files = [ - {file = "flake8_comprehensions-3.15.0-py3-none-any.whl", hash = "sha256:b7e027bbb52be2ceb779ee12484cdeef52b0ad3c1fcb8846292bdb86d3034681"}, - {file = "flake8_comprehensions-3.15.0.tar.gz", hash = "sha256:923c22603e0310376a6b55b03efebdc09753c69f2d977755cba8bb73458a5d4d"}, -] - -[package.dependencies] -flake8 = ">=3,<3.2 || >3.2" - [[package]] name = "idna" version = "3.7" @@ -769,17 +685,6 @@ profiling = ["gprof2dot"] rtd = ["jupyter_sphinx", "mdit-py-plugins", "myst-parser", "pyyaml", "sphinx", "sphinx-copybutton", "sphinx-design", "sphinx_book_theme"] testing = ["coverage", "pytest", "pytest-cov", "pytest-regressions"] -[[package]] -name = "mccabe" -version = "0.7.0" -description = "McCabe checker, plugin for flake8" -optional = false -python-versions = ">=3.6" -files = [ - {file = "mccabe-0.7.0-py2.py3-none-any.whl", hash = "sha256:6c2d30ab6be0e4a46919781807b4f0d834ebdd6c6e3dca0bda5a15f863427b6e"}, - {file = "mccabe-0.7.0.tar.gz", hash = "sha256:348e0240c33b60bbdf4e523192ef919f28cb2c3d7d5c7794f74009290f236325"}, -] - [[package]] name = "mdurl" version = "0.1.2" @@ -982,17 +887,6 @@ files = [ [package.dependencies] configparser = "*" -[[package]] -name = "pycodestyle" -version = "2.12.1" -description = "Python style guide checker" -optional = false -python-versions = ">=3.8" -files = [ - {file = "pycodestyle-2.12.1-py2.py3-none-any.whl", hash = "sha256:46f0fb92069a7c28ab7bb558f05bfc0110dac69a0cd23c61ea0040283a9d78b3"}, - {file = "pycodestyle-2.12.1.tar.gz", hash = "sha256:6838eae08bbce4f6accd5d5572075c63626a15ee3e6f842df996bf62f6d73521"}, -] - [[package]] name = "pycparser" version = "2.22" @@ -1004,17 +898,6 @@ files = [ {file = "pycparser-2.22.tar.gz", hash = "sha256:491c8be9c040f5390f5bf44a5b07752bd07f56edf992381b05c701439eec10f6"}, ] -[[package]] -name = "pyflakes" -version = "3.2.0" -description = "passive checker of Python programs" -optional = false -python-versions = ">=3.8" -files = [ - {file = "pyflakes-3.2.0-py2.py3-none-any.whl", hash = "sha256:84b5be138a2dfbb40689ca07e2152deb896a65c3a3e24c251c5c62489568074a"}, - {file = "pyflakes-3.2.0.tar.gz", hash = "sha256:1c61603ff154621fb2a9172037d84dca3500def8c8b630657d1701f026f8af3f"}, -] - [[package]] name = "pygments" version = "2.18.0" @@ -1359,4 +1242,4 @@ test = ["big-O", "importlib-resources", "jaraco.functools", "jaraco.itertools", [metadata] lock-version = "2.0" python-versions = ">=3.8.1" -content-hash = "9358f49d64a5a39391dfb17818e79551cbcd4428d6de870263edb8330a41c5e2" +content-hash = "ad78fef382be05656676c4c370fea3929628ea4b985284929e99544b824eb7cf" diff --git a/pyproject.toml b/pyproject.toml index 0d1c17b2..e5aaa5b5 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -42,10 +42,6 @@ pytest-xdist = '^3.1.0' black = '^24.1.0' mypy = '^1.0.1' py-githooks = '^1.1.1' -flake8 = '^7.0.0' -flake8-bugbear = '^24.0.0' -flake8-builtins = '^2.1.0' -flake8-comprehensions = '^3.10.1' twine = '^5.1.1' semver = '^3.0.0' setuptools-scm = '^8.0.0' @@ -91,6 +87,9 @@ exclude_lines = ['pragma: no-cover', 'if TYPE_CHECKING:', '@abstractmethod'] [tool.ruff.lint] extend-select = [ + "A", # flake8-builtins + "B", # flake8-bugbear + "C4", # flake8-comprehensions "I", # isort ] diff --git a/src/syrupy/__init__.py b/src/syrupy/__init__.py index 8f621697..d4c3dc23 100644 --- a/src/syrupy/__init__.py +++ b/src/syrupy/__init__.py @@ -40,7 +40,7 @@ def __import_extension(value: Optional[str]) -> Any: try: return import_module_member(value) except FailedToLoadModuleMember as e: - raise argparse.ArgumentTypeError(e) + raise argparse.ArgumentTypeError(e) from e def pytest_addoption(parser: Any) -> None: diff --git a/src/syrupy/extensions/base.py b/src/syrupy/extensions/base.py index 282f641a..21ac1c39 100644 --- a/src/syrupy/extensions/base.py +++ b/src/syrupy/extensions/base.py @@ -259,7 +259,7 @@ def _count_leading_whitespace(s: str) -> int: return len(s) - len(s.lstrip()) -class SnapshotReporter(ABC): +class SnapshotReporter: _context_line_count = 1 def diff_snapshots( diff --git a/src/syrupy/utils.py b/src/syrupy/utils.py index 9564bfca..97aad842 100644 --- a/src/syrupy/utils.py +++ b/src/syrupy/utils.py @@ -54,20 +54,20 @@ def import_module_member(path: str) -> Any: ) try: module = import_module(module_name) - except ModuleNotFoundError: + except ModuleNotFoundError as e: raise FailedToLoadModuleMember( gettext("Module '{}' does not exist.").format(module_name) - ) + ) from e try: return getattr(module, module_member_name) - except AttributeError: + except AttributeError as e: raise FailedToLoadModuleMember( gettext("Member '{}' not found in module '{}'.").format( module_member_name, module_name, ) - ) + ) from e def get_env_value(env_var_name: str) -> object: diff --git a/tasks/lint.py b/tasks/lint.py index 5b1d44ea..233b2f5e 100644 --- a/tasks/lint.py +++ b/tasks/lint.py @@ -7,7 +7,6 @@ lint_commands = { "black": lambda fix: f"python -m black {'' if fix else '--check'} .", - "flake8": lambda _: "python -m flake8 src tests benchmarks *.py", "mypy": lambda _: "python -m mypy --strict src benchmarks", "ruff": lambda fix: f"python -m ruff check {'--fix' if fix else ''} .", } @@ -19,7 +18,7 @@ def run_lint(ctx, section, fix): @task(default=True) -def all(ctx, fix=False): +def all(ctx, fix=False): # noqa: A001 """ Check and fix syntax using various linters """