From 905f54f5c06ca58fea93c1a49d5ccffeb3f4065a Mon Sep 17 00:00:00 2001 From: OMEGARAZER <869111+OMEGARAZER@users.noreply.github.com> Date: Fri, 24 Feb 2023 15:10:17 -0500 Subject: [PATCH] Add ruff Adds ruff settings, tests and pre-commit. --- .github/workflows/test.yml | 12 ++++++++---- .gitignore | 5 ++++- .pre-commit-config.yaml | 18 ++++++++---------- docs/CONTRIBUTING.md | 5 ++--- pyproject.toml | 16 ++++++++++++++-- 5 files changed, 36 insertions(+), 20 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 89e9961..80e2122 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -37,7 +37,7 @@ jobs: - name: Install dependencies run: | - python -m pip install --upgrade pip Flake8-pyproject pytest pytest-cov + python -m pip install --upgrade pip pytest pytest-cov ruff pip install . - name: Make configuration for tests @@ -46,16 +46,20 @@ jobs: run: | ./devscripts/configure${{ matrix.ext }} - - name: Lint with flake8 + - name: Critical ruff lint run: | - flake8 . --select=E9,F63,F7,F82 + ruff check --format=github --select=E9,F63,F7,F82 . - name: Test with pytest run: | - pytest -m 'not slow' --verbose --cov=./bdfr/ --cov-report term:skip-covered --cov-report html + pytest -m "not slow" --verbose --cov=./bdfr/ --cov-report term:skip-covered --cov-report html - name: Upload coverage report uses: actions/upload-artifact@v3 with: name: coverage_report path: htmlcov/ + + - name: Full ruff lint + run: | + ruff check --format=github . --exit-zero diff --git a/.gitignore b/.gitignore index 3918aa5..46cdf0f 100644 --- a/.gitignore +++ b/.gitignore @@ -128,6 +128,9 @@ venv.bak/ .dmypy.json dmypy.json +# ruff +.ruff_cache/ + # Pyre type checker .pyre/ @@ -141,4 +144,4 @@ cython_debug/ test_config.cfg .vscode/ -.idea/ \ No newline at end of file +.idea/ diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 0537e57..1bf956c 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -6,31 +6,29 @@ repos: rev: v0.12.1 hooks: - id: validate-pyproject + name: validate-pyproject - repo: https://github.com/psf/black rev: 23.1.0 hooks: - id: black + name: black - - repo: https://github.com/pycqa/isort - rev: 5.12.0 + - repo: https://github.com/charliermarsh/ruff-pre-commit + rev: v0.0.254 hooks: - - id: isort - name: isort (python) - - - repo: https://github.com/pycqa/flake8 - rev: 6.0.0 - hooks: - - id: flake8 - additional_dependencies: [Flake8-pyproject] + - id: ruff + name: ruff - repo: https://github.com/markdownlint/markdownlint rev: v0.12.0 hooks: - id: markdownlint + name: markdownlint - repo: https://github.com/adamchainz/blacken-docs rev: 1.13.0 hooks: - id: blacken-docs + name: blacken-docs additional_dependencies: [black>=23.1.0] diff --git a/docs/CONTRIBUTING.md b/docs/CONTRIBUTING.md index 841204d..1168863 100644 --- a/docs/CONTRIBUTING.md +++ b/docs/CONTRIBUTING.md @@ -73,13 +73,12 @@ python3 -m pip install -e .[dev] The BDFR project uses several tools to manage the code of the project. These include: - [black](https://github.com/psf/black) -- [flake8](https://github.com/john-hen/Flake8-pyproject) -- [isort](https://github.com/PyCQA/isort) - [markdownlint (mdl)](https://github.com/markdownlint/markdownlint) +- [ruff](https://github.com/charliermarsh/ruff) - [tox](https://tox.wiki/en/latest/) - [pre-commit](https://github.com/pre-commit/pre-commit) -The first four tools are formatters. These change the code to the standards expected for the BDFR project. The configuration details for these tools are contained in the [pyproject.toml](../pyproject.toml) file for the project. +The first three tools are formatters. These change the code to the standards expected for the BDFR project. The configuration details for these tools are contained in the [pyproject.toml](../pyproject.toml) file for the project. The tool `tox` is used to run tests and tools on demand and has the following environments: diff --git a/pyproject.toml b/pyproject.toml index d091699..c4d5f08 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -43,10 +43,9 @@ data-files = {"config" = ["bdfr/default_config.cfg",]} [project.optional-dependencies] dev = [ "black>=23.1.0", - "Flake8-pyproject>=1.2.2", - "isort>=5.12.0", "pre-commit>=3.0.4", "pytest>=7.2.1", + "ruff>=0.0.254", "tox>=3.27.1", ] @@ -87,3 +86,16 @@ markers = [ "slow: test is slow to run", "authenticated: test requires an authenticated Reddit instance", ] + +[tool.ruff] +exclude = ["scripts/tests"] +flake8-annotations = {"allow-star-arg-any" = true, "suppress-dummy-args" = true} +flake8-pytest-style = {"parametrize-values-type" = "tuple", "mark-parentheses" = false} +format = "grouped" +ignore = ["ANN101","B904","N818","RET505"] +line-length = 120 +per-file-ignores={"tests/*"=["ANN","S101","S105","S106"], "scripts/*"=["INP","S105","S106"]} +select = ["ANN","B","BLE","E","ERA","F","I","ICN","INP","ISC","N","PT","PTH","Q","RUF","S","TID","UP","W","YTT"] +show-fixes = true +show-source = true +target-version = "py39"