Skip to content

Commit

Permalink
added ruff linter, pre-commit etc.. similar to TPTBox
Browse files Browse the repository at this point in the history
  • Loading branch information
Hendrik-code committed Feb 6, 2024
1 parent 9d62d1d commit f3c3199
Show file tree
Hide file tree
Showing 3 changed files with 193 additions and 0 deletions.
24 changes: 24 additions & 0 deletions .github/workflows/linter.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
name: ruff linter

on:
push:
branches: [ main ]
pull_request:
branches: [ main ]

jobs:
ruff:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/setup-python@v3
- run: pip install ruff
- run: ruff check . #--fix
#- uses: chartboost/ruff-action@v1
# with:
# fix_args: --fix
# with:
# args: --check .
- uses: stefanzweifel/git-auto-commit-action@v4
with:
commit_message: 'style fixes by ruff'
19 changes: 19 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# See https://pre-commit.com for more information
# See https://pre-commit.com/hooks.html for more hooks
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v3.2.0
hooks:
- id: trailing-whitespace
- id: end-of-file-fixer
- id: check-yaml
- id: check-added-large-files

- repo: https://github.com/astral-sh/ruff-pre-commit
# Ruff version.
rev: v0.2.0
hooks:
# Run the linter.
- id: ruff
# Run the formatter.
- id: ruff-format
150 changes: 150 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -35,3 +35,153 @@ antspyx = "*"

[tool.poetry-dynamic-versioning]
enable = true


[tool.ruff]
namespace-packages = ["datagen"]
exclude = [
".bzr",
".direnv",
".eggs",
".git",
".git-rewrite",
".hg",
".mypy_cache",
".nox",
".pants.d",
".pytype",
".ruff_cache",
".svn",
".tox",
".venv",
"__pypackages__",
"_build",
"buck-out",
"build",
"dist",
"node_modules",
"venv",
".toml",
]
line-length = 140
indent-width = 4
target-version = "py310"

[tool.ruff.lint]
## Enable Pyflakes (`F`) and a subset of the pycodestyle (`E`) codes by default.
## Unlike Flake8, Ruff doesn't enable pycodestyle warnings (`W`) or
## McCabe complexity (`C901`) by default.
#
select = [
"E",
"F",
"W",
"C901",
"I",
"N",
"UP",
"ASYNC",
"BLE",
"B",
"A",
"C4",
"ICN",
"G",
"INP",
"PIE",
"PYI",
#"RET",
"SIM",
"TID",
"INT",
"ARG",
"PTH",
"TD005",
"FIX003",
"FIX004",
#"ERA", For clean up
#"D", Dockstring For clean up
#"ANN", Annoation For clean up
"PD",
"PGH",
"PL",
"TRY",
"FLY",
"NPY",
"AIR",
"PERF",
"FURB",
"RUF",
]


ignore = [
"F401",
"BLE001",
"E501",
"N801",
"PD002",
"PERF203",
"PTH123",
"PGH003",
"PLR0911",
"PLR0912",
"PLR0913",
"PLR0915",
"PLR2004",
"SIM105",
"TRY003",
"UP038",
"N999","E741",
"SIM118", # dictionay keys
"N802", # function name lowercase
]

# Allow fix for all enabled rules (when `--fix`) is provided.
fixable = ["ALL"]
unfixable = []
ignore-init-module-imports = true
extend-safe-fixes = ["RUF015", "C419", "C408", "B006"]
#unnecessary-iterable-allocation-for-first-element = true


# Allow unused variables when underscore-prefixed.
dummy-variable-rgx = "^(_+|(_+[a-zA-Z0-9_]*[a-zA-Z0-9]+?))$"

[tool.ruff.lint.mccabe]
# Flag errors (`C901`) whenever the complexity level exceeds 5.
max-complexity = 20


[tool.ruff.format]
# Like Black, use double quotes for strings.
quote-style = "double"

# Like Black, indent with spaces, rather than tabs.
indent-style = "space"

# Like Black, respect magic trailing commas.
skip-magic-trailing-comma = false

# Enable reformatting of code snippets in docstrings.
docstring-code-format = true



# Like Black, automatically detect the appropriate line ending.
line-ending = "auto"
# Add this to your setting.json (user)
# Ctrl+shift+P settings json
#"[python]": {
# "editor.formatOnSave": true,
# "editor.defaultFormatter": "charliermarsh.ruff",
# "editor.codeActionsOnSave": {
# "source.fixAll": "explicit",
# "source.organizeImports": "never"
# }
# },
# "notebook.formatOnSave.enabled": true,
# "notebook.codeActionsOnSave": {
# "source.fixAll": false,
# "source.organizeImports": false
# },

0 comments on commit f3c3199

Please sign in to comment.