From 6e9dac2a44b5357eb93c49104ec3490343583809 Mon Sep 17 00:00:00 2001 From: Michael Hanke Date: Fri, 20 Sep 2024 10:53:44 +0200 Subject: [PATCH] ci: add workflow and setup to ensure compliance with ruff-enforced style The idea being that we let a machine decide how code needs to look like, and we tell the machine how we like that via configuration. The configuration is in `pyproject.toml` (`tools.ruff`). Hatch users can also run ``` hatch fmt [--check] ``` --- .github/workflows/ruff.yml | 17 +++++++++++++++++ pyproject.toml | 22 ++++++++++++++++++++++ 2 files changed, 39 insertions(+) create mode 100644 .github/workflows/ruff.yml diff --git a/.github/workflows/ruff.yml b/.github/workflows/ruff.yml new file mode 100644 index 0000000..a171d09 --- /dev/null +++ b/.github/workflows/ruff.yml @@ -0,0 +1,17 @@ +name: Ruff +on: [push, pull_request] +jobs: + ruff: + runs-on: ubuntu-latest + steps: + - name: Setup Python + uses: actions/setup-python@v5 + with: + # run on a "fresh" python + python-version: 3.12 + - name: Checkout + uses: actions/checkout@v4 + - name: Install hatch + run: python -m pip install hatch + - name: Check code + run: hatch fmt --check diff --git a/pyproject.toml b/pyproject.toml index dee9f84..3b9a0f3 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -101,6 +101,28 @@ exclude_lines = [ "raise NotImplementedError", ] +[tool.ruff] +exclude = [ + # sphinx + "docs", +] +line-length = 88 +indent-width = 4 +target-version = "py39" +[tool.ruff.format] +# Prefer single quotes over double quotes. +quote-style = "single" +[tool.ruff.lint.per-file-ignores] +"**/test_*" = [ + # permit assert statements in tests + "S101", + # permit relative import in tests + "TID252", + # permit versatile function names in tests + "N802", +] +# permit relative import in subpackage root +"datalad_core/*/__init__.py" = ["TID252"] [tool.commitizen] name = "cz_customize"