Skip to content

Commit

Permalink
Add a ruff.toml config file for linting python and add ruff to the li…
Browse files Browse the repository at this point in the history
…nting workflow file.
  • Loading branch information
jatkinson1000 committed Nov 25, 2024
1 parent aa8eba2 commit f435781
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 3 deletions.
15 changes: 12 additions & 3 deletions .github/workflows/linting.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ jobs:
. ftorch/bin/activate
pip install torch torchvision --index-url https://download.pytorch.org/whl/cpu
pip install fortitude-lint
pip install ruff
# Run CMake build to get compile commands for clang
- name: FTorch CMake
Expand All @@ -54,7 +55,7 @@ jobs:
# Apply Fortran linter, fortitude
# Configurable using the fortitude.toml file if present
- name: Fortitude Source
- name: fortitude source
if: always()
run: |
cd ${{ github.workspace }}
Expand All @@ -63,7 +64,7 @@ jobs:
# Apply C++ and C linter and formatter, clang
# Configurable using the .clang-format and .clang-tidy config files if present
- name: Clang Source
- name: clang source
if: always()
uses: cpp-linter/cpp-linter-action@v2
id: linter
Expand All @@ -81,9 +82,17 @@ jobs:
run: exit 1

# Apply Fortran linter, fortitude to examples
- name: Fortitude Examples
- name: fortitude examples
if: always()
run: |
cd ${{ github.workspace }}
. ftorch/bin/activate
fortitude check examples
- name: ruff
if: always()
run: |
cd ${{ github.workspace }}
. ftorch/bin/activate
ruff format --diff ./
ruff check --diff ./
24 changes: 24 additions & 0 deletions ruff.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
[format]
docstring-code-format = true

[lint]
# See https://docs.astral.sh/ruff/rules for full details of each ruleset.

# Enable: D: `pydocstyle`, PL: `pylint`, I: `isort`, W: `pycodestyle whitespace`
# NPY: `numpy`, FLY: `flynt`, RUF: `ruff`
# From flake8: "ARG", "SLF", "S", "BLE", "B", "A", "C4", "EM", "ICN",
# "PIE", "Q", "RSE", "SIM", "TID"
select = ["D", "PL", "I", "E", "W", "NPY", "FLY", "RUF",
"ARG", "SLF", "S", "BLE","B", "A", "C4", "EM", "ICN", "PIE", "Q", "RSE",
"SIM", "TID"]

# Enable D417 (Missing argument description) on top of the NumPy convention.
extend-select = ["D417"]

# Ignore SIM108 (use ternary instead of if-else) as it can arguably obscure intent.
# Ignore RUF002 (ambiguous characters) as it does not allow apostrophes in strings.
ignore = ["SIM108", "RUF002"]

[lint.pydocstyle]
# Use NumPy convention for checking docstrings
convention = "numpy"

0 comments on commit f435781

Please sign in to comment.