From 1fe258de2a91944bfe4dd0747dcf262240eab36c Mon Sep 17 00:00:00 2001 From: in03 Date: Mon, 13 Mar 2023 12:43:50 +1000 Subject: [PATCH] ci(precommit): Replace flake8 with Ruff These opinionated bugbear rules are not implemented in Ruff yet: - B950 (line too long), using equivalent: E501. - B902 (invalid first arg for method), using equivalent: N804, N805 See: https://github.com/charliermarsh/ruff/issues/2954 These pycodestyle rules are not implemented in Ruff yet and have no equivalent rules: - E303 (too many blank lines), - E302 (Expected 2 blank lines, found 0) - E301 (Expected 1 blank line, found 0) Previously ignored for "pydavinci/wrappers/settings/components.py". Since they don't exist, we don't need to ignore them, but this will apply package wide. Black should handle formatting these correctly anyway. --- .flake8 | 7 ------- .pre-commit-config.yaml | 24 +++++++++++------------- pyproject.toml | 7 +++++++ ruff.toml | 34 ++++++++++++++++++++++++++++++++++ 4 files changed, 52 insertions(+), 20 deletions(-) delete mode 100644 .flake8 create mode 100644 ruff.toml diff --git a/.flake8 b/.flake8 deleted file mode 100644 index 768b339..0000000 --- a/.flake8 +++ /dev/null @@ -1,7 +0,0 @@ -[flake8] -extend-ignore = F403, E501, B950, E266, B902 -max-line-length = 100 -max-complexity = 18 -select = B,C,E,F,W,T4,B9 -per-file-ignores= - pydavinci/wrappers/settings/components.py:E303,E302, W293 diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 5ecac9f..1fd39a4 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -18,21 +18,19 @@ repos: hooks: - id: black # By default, this ignores pyi files, though black supports them -# Flake8 also supports pre-commit natively (same author) -- repo: https://github.com/pycqa/isort - rev: 5.10.1 +# Ruff supports flake8, bugbear rules +- repo: https://github.com/charliermarsh/ruff-pre-commit + rev: 'v0.0.254' hooks: - - id: isort - name: isort (python) - args: ["--profile", "black"] -- repo: https://gitlab.com/pycqa/flake8 - rev: 3.9.2 - hooks: - - id: flake8 - args: ['--ignore=F403,E501,B950,E266'] - additional_dependencies: [flake8-bugbear, pep8-naming] - exclude: ^(docs/.*|tools/.*|tests/.*)$ + - id: ruff + - repo: https://github.com/pre-commit/mirrors-mypy rev: v0.940 # Use the sha / tag you want to point at hooks: - id: mypy + exclude: ^tests/ + +- repo: https://github.com/asottile/pyupgrade + rev: v3.3.1 + hooks: + - id: pyupgrade diff --git a/pyproject.toml b/pyproject.toml index b15e42b..49e32b8 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -23,6 +23,13 @@ dependencies = [ "typing_extensions>=4.1.1", ] +[project.optional-dependencies] +dev = [ + "mypy", + "black", + "flake8", + "pre-commit", +] [project.urls] Homepage = "https://github.com/pedrolabonia/pydavinci" Source = "https://github.com/pedrolabonia/pydavinci" diff --git a/ruff.toml b/ruff.toml new file mode 100644 index 0000000..4c1acd2 --- /dev/null +++ b/ruff.toml @@ -0,0 +1,34 @@ + +# Enable flake8-bugbear (`B`) rules. +select = [ + "B", + "C", + "F", + "W", + "TCH", + "B9", +] + +# Never enforce `E501` (line length violations). +ignore = [ + "E501", + "F403", + "E501", + "F403", + "E501", + "N805", + "N804", + "W293", +] + +src = ["src"] + +# Avoid trying to fix flake8-bugbear (`B`) violations. +unfixable = ["B"] + +[mccabe] +max-complexity = 18 + +# Ignore `E402` (import violations) in all `__init__.py` files. +[per-file-ignores] +"__init__.py" = ["E402"]