Skip to content

Commit af9e1b0

Browse files
ci: Add taskfiles and update GH workflows for linting Python files. (#60)
Co-authored-by: Lin Zhihao <59785146+LinZhihao-723@users.noreply.github.com>
1 parent 8627352 commit af9e1b0

File tree

9 files changed

+97
-6
lines changed

9 files changed

+97
-6
lines changed

.github/workflows/code-linting-checks.yaml

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,15 @@ name: "code-linting-checks"
22

33
on:
44
pull_request:
5-
paths: ["**/*.yaml"]
5+
paths:
6+
- "**/*.py"
7+
- "**/*.pyi"
8+
- "**/*.yaml"
69
push:
7-
paths: ["**/*.yaml"]
10+
paths:
11+
- "**/*.py"
12+
- "**/*.pyi"
13+
- "**/*.yaml"
814
schedule:
915
# Run daily at 00:15 UTC (the 15 is to avoid periods of high load)
1016
- cron: "15 0 * * *"
@@ -35,6 +41,10 @@ jobs:
3541
shell: "bash"
3642
run: "npm install -g @go-task/cli"
3743

44+
- name: "Install uv"
45+
shell: "bash"
46+
run: "curl --fail --location --silent --show-error https://astral.sh/uv/install.sh | sh"
47+
3848
- name: "Run lint task"
3949
shell: "bash"
4050
run: "task lint:check"
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
# Python linter configs
2+
3+
This directory contains standalone, working Python linter configuration files that serve as
4+
reference settings for integrating these linters into your project.
5+
6+
For a project with its own `pyproject.toml` file, at the time of writing, there is no clean, general
7+
solution for including the standalone configuration files for different linters. In this scenario,
8+
the settings inside the configuration files should be copied into your `pyproject.toml` file, as
9+
seen in [ystdlib-py/pyproject.toml](../../ystdlib-py/pyproject.toml).
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
[mypy]
2+
strict = true
3+
4+
# Additional output
5+
pretty = true
6+
show_error_code_links = true
7+
show_error_context = true
8+
show_error_end = true
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
line-length = 100
2+
3+
[lint]
4+
select = ["ALL"]
5+
ignore = [
6+
"COM812", # Redundant and conflicts with ruff format
7+
"D203", # No blank line before docstrings (D211)
8+
"D205", # Breaks if summary is larger than one line due to wrapping or if no summary exists
9+
"D212", # Enforce docstring summary line on the next line after quotes (D213)
10+
"D400", # First line of docstrings may not end in period
11+
"D401", # Docstrings should be written in present tense (not imperative)
12+
"D415", # First line of docstrings may not end in a period, question mark, or exclamation point
13+
"FBT", # Allow bool positional parameters since other value positions are allowed
14+
"FIX002", # Allow todo statements
15+
"PERF401", # Allow for loops when creating lists
16+
"PERF403", # Allow for loops when creating dicts
17+
"S311", # Allow usage of `random` package
18+
"SIM102", # Allow collapsible if statements for readability
19+
"TD002", # Author unnecessary for todo statement
20+
"TD003", # Issue link unnecessary for todo statement
21+
"UP015", # Explicit open modes are helpful
22+
]
23+
isort.order-by-type = false
24+
25+
[format]
26+
docstring-code-format = true
27+
docstring-code-line-length = 100

exports/ystdlib-py/pyproject.toml

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,13 @@ dev = [
1919
]
2020

2121
[tool.mypy]
22-
pretty = true
2322
strict = true
24-
warn_unused_ignores = true
23+
24+
# Additional output
25+
pretty = true
26+
show_error_code_links = true
27+
show_error_context = true
28+
show_error_end = true
2529

2630
[tool.ruff]
2731
line-length = 100

taskfile.yaml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,14 @@ set: ["u", "pipefail"]
88
shopt: ["globstar"]
99

1010
vars:
11+
# Directories
12+
G_EXPORTS_DIR: "{{.ROOT_DIR}}/exports"
13+
G_LINT_CONFIGS_DIR: "{{.G_EXPORTS_DIR}}/lint-configs"
1114
G_OUTPUT_DIR: "{{.ROOT_DIR}}/build"
15+
G_YSTDLIB_PY_DIR: "{{.G_EXPORTS_DIR}}/ystdlib-py"
16+
17+
# Utility commands
18+
G_PYFIND_CMD: "uv run --project '{{.G_YSTDLIB_PY_DIR}}' pyfind"
1219

1320
tasks:
1421
clean:

taskfiles/lint/main.yaml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
version: "3"
22

33
includes:
4+
py:
5+
flatten: true
6+
taskfile: "./python.yaml"
47
utils: "../../exports/taskfiles/utils/utils.yaml"
58
yaml:
69
flatten: true
@@ -14,6 +17,7 @@ tasks:
1417
check:
1518
desc: "Runs all linters to identify any violations."
1619
cmds:
20+
- task: "check-py"
1721
- task: "check-yaml"
1822

1923
venv:
@@ -24,7 +28,7 @@ tasks:
2428
OUTPUT_DIR: "{{.G_LINT_VENV_DIR}}"
2529
sources:
2630
- "{{.LINT_REQUIREMENTS_FILE}}"
27-
- "{{.ROOT_DIR}}/exports/taskfiles/**/*.yaml"
31+
- "{{.G_EXPORTS_DIR}}/taskfiles/**/*.yaml"
2832
- "{{.ROOT_DIR}}/taskfile.yaml"
2933
- "{{.TASKFILE_DIR}}/**/*.yaml"
3034
generates: ["{{.CHECKSUM_FILE}}"]

taskfiles/lint/python.yaml

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
version: "3"
2+
3+
tasks:
4+
check-py:
5+
cmds:
6+
- task: "py"
7+
vars:
8+
RUFF_FORMAT_FLAGS: "--diff"
9+
10+
fix-py:
11+
cmds:
12+
- task: "py"
13+
vars:
14+
RUFF_CHECK_FLAGS: "--fix"
15+
16+
py:
17+
internal: true
18+
cmd: |-
19+
cd "{{.G_YSTDLIB_PY_DIR}}"
20+
uv run mypy "./src"
21+
uv run ruff check {{.RUFF_CHECK_FLAGS}} "./src"
22+
uv run ruff format {{.RUFF_FORMAT_FLAGS}} "./src"

taskfiles/ystdlib-py/test-pyfind.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ tasks:
107107
FIND_OUTPUT:
108108
sh: |
109109
cd "{{.G_TEST_DIR}}"
110-
uv run --project "{{.ROOT_DIR}}/exports/ystdlib-py" pyfind \
110+
{{.G_PYFIND_CMD}} \
111111
{{- range .FIND_ROOT_PATHS}}
112112
"{{.}}" \
113113
{{- end}}

0 commit comments

Comments
 (0)