Skip to content

Commit fcf16db

Browse files
authored
Merge pull request #403 from ialarmedalien/add_automation_for_formatting_linting
Add in automation for ruff code formatting and linting.
2 parents faac277 + 15bf863 commit fcf16db

File tree

4 files changed

+153
-20
lines changed

4 files changed

+153
-20
lines changed

.github/workflows/main.yaml

Lines changed: 28 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,32 @@ on:
1313
workflow_dispatch:
1414

1515
jobs:
16+
17+
quality-checks:
18+
runs-on: ubuntu-latest
19+
steps:
20+
- uses: actions/checkout@v4.2.2
21+
- name: Install Poetry
22+
run: |
23+
pipx install poetry
24+
pipx inject poetry poetry-dynamic-versioning
25+
- uses: actions/setup-python@v5.6.0
26+
with:
27+
python-version: 3.13
28+
- name: Check pyproject.toml and poetry.lock
29+
run: poetry check
30+
- name: Install tox
31+
run: python -m pip install tox
32+
- name: Run codespell
33+
run: tox -e codespell
34+
- name: Run code format checks
35+
run: tox -e format_check
36+
37+
1638
test:
39+
# TODO: uncomment when ruff format has been run over the codebase
40+
# needs:
41+
# - quality-checks
1742
strategy:
1843
fail-fast: false
1944
matrix:
@@ -54,14 +79,14 @@ jobs:
5479
cache: 'poetry'
5580

5681
#----------------------------------------------
57-
# install your root project, if required
58-
#----------------------------------------------
82+
# install your root project, if required
83+
#----------------------------------------------
5984
- name: Install library
6085
run: |
6186
poetry install --no-interaction
6287
6388
#----------------------------------------------
64-
# coverage report
89+
# coverage report
6590
#----------------------------------------------
6691
- name: Generate coverage results
6792
# Set bash shell to fail correctly on Windows https://github.com/actions/runner-images/issues/6668

.github/workflows/test-upstream.yaml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@
22
name: Test with upstream linkml
33
on:
44
pull_request:
5-
branches:
6-
- main
75
workflow_dispatch:
86
inputs:
97
upstream_repo:

pyproject.toml

Lines changed: 125 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -75,19 +75,139 @@ style = "pep440"
7575
coverage = "^6.2"
7676
requests-cache = "^1.2.0"
7777

78+
# https://docs.astral.sh/ruff/settings/
7879
[tool.ruff]
80+
extend-exclude = []
81+
force-exclude = true
7982
line-length = 120
83+
# Assume Python 3.9
8084
target-version = "py39"
8185

8286
[tool.ruff.lint]
87+
8388
select = [
84-
"F401",
85-
"UP"
89+
# core
90+
"F", # Pyflakes
91+
"E", # pycodestyle errors
92+
"W", # pycodestyle warnings
93+
"C90", # mccabe +
94+
"I", # isort
95+
"N", # pep8-naming
96+
# "D", # pydocstyle
97+
"UP", # pyupgrade
98+
# extensions
99+
# "YTT", # flake8-2020
100+
# "ANN", # flake8-annotations
101+
# "ASYNC", # flake8-async
102+
# "S", # flake8-bandit
103+
# "BLE", # flake8-blind-except
104+
# "FBT", # flake8-boolean-trap
105+
# "B", # flake8-bugbear
106+
# "A", # flake8-builtins
107+
# "COM", # flake8-commas
108+
# "CPY", # flake8-copyright
109+
# "C4", # flake8-comprehensions
110+
# "DTZ", # flake8-datetimez
111+
# "T10", # flake8-debugger
112+
# "DJ", # flake8-django
113+
# "EM", # flake8-errmsg
114+
# "EXE", # flake8-executable
115+
# "FA", # flake8-future-annotations
116+
# "ISC", # flake8-implicit-str-concat
117+
# "ICN", # flake8-import-conventions
118+
# "G", # flake8-logging-format
119+
# "INP", # flake8-no-pep420
120+
# "PIE", # flake8-pie
121+
# "T20", # flake8-print
122+
# "PYI", # flake8-pyi
123+
# "PT", # flake8-pytest-style
124+
# "Q", # flake8-quotes
125+
# "RSE", # flake8-raise
126+
# "RET", # flake8-return
127+
# "SLF", # flake8-self
128+
# "SLOT", # flake8-slots
129+
# "SIM", # flake8-simplify
130+
# "TID", # flake8-tidy-imports
131+
# "TCH", # flake8-type-checking
132+
# "INT", # flake8-gettext
133+
# "ARG", # flake8-unused-arguments
134+
# "PTH", # flake8-use-pathlib
135+
# "TD", # flake8-todos
136+
# "FIX", # flake8-fixme
137+
# "ERA", # eradicate
138+
# "PD", # pandas-vet
139+
# "PGH", # pygrep-hooks
140+
# "PL", # Pylint
141+
# "TRY", # tryceratops
142+
# "FLY", # flynt
143+
# "NPY", # NumPy-specific rules
144+
# "AIR", # Airflow
145+
# "PERF", # Perflint
146+
# "FURB", # refurb
147+
# "LOG", # flake8-logging
148+
# "RUF", # Ruff-specific rules
86149
]
150+
151+
# Allow autofix for all enabled rules (when `--fix`) is provided.
152+
fixable = ["ALL"]
153+
unfixable = []
154+
155+
# D203: one-blank-line-before-class (conflicts with D211)
156+
# D212: multi-line-summary-first-line (conflicts with D213)
157+
# E203: whitespace before ',', ';', or ':'
158+
# E501: line length
159+
# ISC001: conflicts with Ruff's formatter
87160
ignore = [
88-
# Until 3.9 is dropped
89-
"UP007",
161+
"D203",
162+
"D213",
163+
"E203",
164+
"E501",
165+
"ISC001",
90166
]
91167

92168
[tool.ruff.lint.per-file-ignores]
93-
"tests/**/*.py" = ["F401"] # unused imports
169+
"tests/**/*.py" = ["S101"] # use of assert
170+
171+
[tool.ruff.lint.mccabe]
172+
# Flag errors (`C901`) whenever the complexity level exceeds 15.
173+
max-complexity = 15
174+
175+
176+
[tool.tox]
177+
requires = ["tox>=4"]
178+
env_list = ["lint", "py{39,310,311,312,313}"]
179+
180+
[tool.tox.env.codespell]
181+
description = "Run spell checkers."
182+
skip_install = true
183+
deps = [
184+
"codespell",
185+
"tomli", # required for getting config from pyproject.toml
186+
]
187+
commands = [
188+
["codespell", "{posargs}"]
189+
]
190+
191+
[tool.tox.env.format]
192+
description = "Run ruff code formatter."
193+
skip_install = true
194+
deps = ["ruff==0.11.13"]
195+
commands = [
196+
["ruff", "format", "{posargs:.}"],
197+
]
198+
199+
[tool.tox.env.format_check]
200+
description = "Check that code is correctly formatted by ruff."
201+
skip_install = true
202+
deps = ["ruff==0.11.13"]
203+
commands = [
204+
["ruff", "format", "--check", "{posargs:.}"],
205+
]
206+
207+
[tool.tox.env.lint]
208+
description = "Run code linter (no fixes)."
209+
skip_install = true
210+
deps = ["ruff==0.11.13"]
211+
commands = [
212+
["ruff", "check", "{posargs:.}"],
213+
]

tox.ini

Lines changed: 0 additions & 10 deletions
This file was deleted.

0 commit comments

Comments
 (0)