From 487afacc7a513fcb8267d808f1ced00e4673cf65 Mon Sep 17 00:00:00 2001 From: Gulshan Singh Date: Thu, 4 May 2023 00:42:40 -0700 Subject: [PATCH] Switch from flake8 to ruff (#1696) --- DEVELOPING.md | 2 +- dev-requirements.txt | 11 ++++------ lint.sh | 4 ++-- pyproject.toml | 41 ++++++++++++++++++++++++++++++++++++ setup.cfg | 50 -------------------------------------------- 5 files changed, 48 insertions(+), 60 deletions(-) delete mode 100644 setup.cfg diff --git a/DEVELOPING.md b/DEVELOPING.md index 31952f010..864b68f02 100644 --- a/DEVELOPING.md +++ b/DEVELOPING.md @@ -60,7 +60,7 @@ Note that in the test, we can access `pwndbg` library code like `pwndbg.gdblib.r ## Linting -The `lint.sh` script runs `isort`, `black`, `flake8`, `shfmt`, and `vermin`. `isort` and `black` are able to automatically fix any issues they detect, and you can enable this by running `./lint.sh -f`. You can find the configuration files for these tools in `setup.cfg` and `pyproject.toml`. +The `lint.sh` script runs `isort`, `black`, `ruff`, `shfmt`, and `vermin`. `isort` and `black` are able to automatically fix any issues they detect, and you can enable this by running `./lint.sh -f`. You can find the configuration files for these tools in `setup.cfg` and `pyproject.toml`. When submitting a PR, the CI job defined in `.github/workflows/lint.yml` will verify that running `./lint.sh` succeeds, otherwise the job will fail and we won't be able to merge your PR. diff --git a/dev-requirements.txt b/dev-requirements.txt index fa0c1b1a8..34e064baa 100644 --- a/dev-requirements.txt +++ b/dev-requirements.txt @@ -2,21 +2,18 @@ black==22.8.0; python_version < '3.7' black==22.12.0; python_version >= '3.7' coverage==6.2; python_version < '3.7' coverage==7.0.1; python_version >= '3.7' -flake8==5.0.4; python_version < '3.9' -flake8==6.0.0; python_version >= '3.9' -flake8-builtins==2.0.0; python_version < '3.7' -flake8-builtins==2.1.0; python_version >= '3.7' mypy==0.991; python_version >= '3.7' -testresources==2.0.1 isort==5.10.1; python_version < '3.7' isort==5.11.4; python_version >= '3.7' pytest==7.0.1; python_version < '3.7' pytest==7.2.0; python_version >= '3.7' +rich==12.6.0; python_version < '3.7' +rich==13.3.1; python_version >= '3.7' +ruff==0.0.264; python_version >= '3.7' +testresources==2.0.1 types-gdb==12.1.4.1 types-psutil==5.9.5 types-Pygments==2.12.1 types-tabulate==0.9.0.0 types-requests==2.28.11.17 vermin==1.5.1 -rich==12.6.0; python_version < '3.7' -rich==13.3.1; python_version >= '3.7' diff --git a/lint.sh b/lint.sh index 7791288a2..4427f9aa3 100755 --- a/lint.sh +++ b/lint.sh @@ -29,7 +29,7 @@ done set -o xtrace LINT_FILES="pwndbg tests *.py" -LINT_TOOLS="isort black flake8 vermin" +LINT_TOOLS="isort black ruff vermin" if ! type ${LINT_TOOLS} &> /dev/null; then PIP_CMD="pip install -Ur dev-requirements.txt" @@ -58,7 +58,7 @@ fi # Checking minimum python version vermin -vvv --no-tips -q -t=3.6 --violations ./pwndbg/ -flake8 --show-source ${LINT_FILES} +ruff check --show-source ${LINT_FILES} if [ -x "$(command -v mypy)" ]; then mypy pwndbg diff --git a/pyproject.toml b/pyproject.toml index 188c16c20..bdf17c854 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -2,6 +2,47 @@ line-length = 100 extend-exclude = "gdb-pt-dump" +[tool.ruff] +exclude = ["gdb-pt-dump"] +ignore = [ + "A003", + "E402", + "E501", + "E731", + "F405", + "F811", + "F821", + "F841", + "W505", +] +line-length = 100 +select = [ + "A", + "E", + "F", + "W", +] + +[tool.ruff.flake8-builtins] +builtins-ignorelist = [ + "all", + "bin", + "breakpoint", + "copyright", + "dir", + "exit", + "format", + "hex", + "map", + "max", + "min", + "next", + "type", +] + +[tool.ruff.per-file-ignores] +"__init__.py" = ["F401"] + [tool.mypy] strict_optional = false check_untyped_defs = true diff --git a/setup.cfg b/setup.cfg deleted file mode 100644 index a6c14562e..000000000 --- a/setup.cfg +++ /dev/null @@ -1,50 +0,0 @@ -[flake8] -ignore = - # whitespace before ‘:’ - E203, - # too many leading '#' for block comment - E266, - # block comment should start with ‘# ‘ - E265, - # module level import not at top of file - E402, - # line too long (82 > 79 characters) - E501, - # do not assign a lambda expression, use a def - E731 - # line break before binary operator (default) - W503, - # doc line too long (82 > 79 characters) (default) - W505, - # name may be undefined, or defined from star imports: module - F405, - # redefinition of unused name from line n - F811, - # undefined name name - F821, - # local variable name is assigned to but never used - F841, - # class attribute is shadowing a python builtin - A003 - -per-file-ignores = - # Unused imports in __init__.py are fine - __init__.py:F401 - -max-line-length = 100 -exclude = gdb-pt-dump - -# flake8-builtins should allow these builtins to be shadowed -builtins-ignorelist = - all, - breakpoint, - copyright, - dir, - exit, - format, - hex, - map, - max, - min, - next, - type