Skip to content

Commit c7bf93c

Browse files
committed
[CI] Linter and formatter
Adds 'ruff' as Python linter and code formatter and 'pre-commit' for easy rules application both locally and in CI. New lint CI workflow is also added. The formatting tools are added as optional dependencies. They can be installed using: uv sync --extra dev-tools
1 parent 9717077 commit c7bf93c

File tree

3 files changed

+70
-0
lines changed

3 files changed

+70
-0
lines changed

.github/workflows/lint.yml

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
name: Lint
2+
3+
on:
4+
push:
5+
pull_request:
6+
7+
jobs:
8+
Lint:
9+
runs-on: ubuntu-latest
10+
steps:
11+
- uses: actions/checkout@v5
12+
13+
- name: Install uv
14+
uses: astral-sh/setup-uv@v6
15+
16+
- name: Install the project and its dependencies
17+
run: |
18+
uv sync
19+
uv sync --extra dev-tools
20+
21+
- name: Run pre-commit
22+
run: |-
23+
uv run pre-commit run --all-files

.pre-commit-config.yaml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
repos:
2+
- repo: https://github.com/astral-sh/ruff-pre-commit
3+
# Ruff version.
4+
rev: v0.14.5
5+
hooks:
6+
# Run the linter.
7+
- id: ruff-check
8+
args: [ --fix ]
9+
# Run the formatter.
10+
- id: ruff-format

pyproject.toml

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,10 @@ ingress_torch_xpu = [
3434
"pytorch_triton_xpu", # Transitive dependency listed explicitly so that we can state which package repository it is supposed to come from
3535
"lighthouse[ingress_torch_mlir]"
3636
]
37+
dev_tools = [
38+
"pre-commit",
39+
"ruff==0.14.5"
40+
]
3741

3842
[tool.uv]
3943
# Declare that the following "targets" are mutually exclusive of one another
@@ -82,3 +86,36 @@ include = ["lighthouse*"]
8286

8387
[tool.setuptools.dynamic]
8488
version = {attr = "lighthouse.__version__"}
89+
90+
[tool.ruff]
91+
src = ["lighthouse"]
92+
target-version = "py310"
93+
line-length = 88
94+
95+
[tool.ruff.format]
96+
docstring-code-format = true
97+
quote-style = "double"
98+
99+
# List of rules:
100+
# https://docs.astral.sh/ruff/rules/
101+
[tool.ruff.lint]
102+
select = [
103+
"D419", # empty-docstring
104+
"E", # Error
105+
"F", # Pyflakes
106+
"I", # isort
107+
"PERF", # Perflint
108+
"W", # Warning
109+
]
110+
ignore = [
111+
"E501", # line-too-long
112+
"PERF203", # try-except-in-loop
113+
"PERF401", # manual-list-comprehension
114+
]
115+
116+
[tool.ruff.lint.isort]
117+
known-local-folder = ["lighthouse", "MLPModel"]
118+
known-third-party = ["torch", "numpy"]
119+
known-first-party = ["mlir"]
120+
force-single-line = true # Improves merge conflicts
121+
force-sort-within-sections = true

0 commit comments

Comments
 (0)