Skip to content

Commit ea9f097

Browse files
committed
adds linting configuration and workflow
1 parent 7438b3c commit ea9f097

File tree

4 files changed

+134
-0
lines changed

4 files changed

+134
-0
lines changed

.github/workflows/ci-lint.yml

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
name: pre-commit
2+
3+
on:
4+
pull_request:
5+
push:
6+
branches: [master]
7+
8+
jobs:
9+
pre-commit:
10+
runs-on: ubuntu-latest
11+
steps:
12+
- uses: actions/[email protected]
13+
with:
14+
# Ensure the full history is fetched
15+
# This is required to run pre-commit on a specific set of commits
16+
# TODO: Remove this when all the pre-commit issues are fixed
17+
fetch-depth: 0
18+
- uses: actions/[email protected]
19+
with:
20+
python-version: 3.13
21+
- uses: pre-commit/[email protected]

.pre-commit-config.yaml

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
# pre-commit is a tool to perform a predefined set of tasks manually and/or
2+
# automatically before git commits are made.
3+
#
4+
# Config reference: https://pre-commit.com/#pre-commit-configyaml---top-level
5+
#
6+
# Common tasks
7+
#
8+
# - Register git hooks: pre-commit install --install-hooks
9+
# - Run on all files: pre-commit run --all-files
10+
#
11+
# These pre-commit hooks are run as CI.
12+
#
13+
# NOTE: if it can be avoided, add configs/args in pyproject.toml or below instead of creating a new `.config.file`.
14+
# https://pre-commit.ci/#configuration
15+
ci:
16+
autoupdate_schedule: monthly
17+
autofix_commit_msg: |
18+
[pre-commit.ci] Apply automatic pre-commit fixes
19+
20+
repos:
21+
# general
22+
- repo: https://github.com/pre-commit/pre-commit-hooks
23+
rev: v4.6.0
24+
hooks:
25+
- id: end-of-file-fixer
26+
exclude: '\.svg$'
27+
- id: trailing-whitespace
28+
exclude: '\.svg$'
29+
- id: check-json
30+
- id: check-yaml
31+
args: [--allow-multiple-documents, --unsafe]
32+
- id: check-toml
33+
34+
- repo: https://github.com/astral-sh/ruff-pre-commit
35+
rev: v0.5.6
36+
hooks:
37+
- id: ruff
38+
args: ["--fix"]
39+
- id: ruff-format

pyproject.toml

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,3 +19,76 @@ requires = [
1919
# Required for using org_tensorflow bazel repository.
2020
"numpy~=1.22.0",
2121
]
22+
23+
[tool.ruff]
24+
line-length = 88
25+
26+
[tool.ruff.lint]
27+
select = [
28+
# pycodestyle
29+
"E",
30+
"W",
31+
# Pyflakes
32+
"F",
33+
# pyupgrade
34+
"UP",
35+
# flake8-bugbear
36+
"B",
37+
# flake8-simplify
38+
"SIM",
39+
# isort
40+
"I",
41+
# pep8 naming
42+
"N",
43+
# pydocstyle
44+
"D",
45+
# annotations
46+
"ANN",
47+
# debugger
48+
"T10",
49+
# flake8-pytest
50+
"PT",
51+
# flake8-return
52+
"RET",
53+
# flake8-unused-arguments
54+
"ARG",
55+
# flake8-fixme
56+
"FIX",
57+
# flake8-eradicate
58+
"ERA",
59+
# pandas-vet
60+
"PD",
61+
# numpy-specific rules
62+
"NPY",
63+
]
64+
65+
ignore = [
66+
"D104", # Missing docstring in public package
67+
"D100", # Missing docstring in public module
68+
"D211", # No blank line before class
69+
"PD901", # Avoid using 'df' for pandas dataframes. Perfectly fine in functions with limited scope
70+
"ANN201", # Missing return type annotation for public function (makes no sense for NoneType return types...)
71+
"ANN101", # Missing type annotation for `self`
72+
"ANN204", # Missing return type annotation for special method
73+
"ANN002", # Missing type annotation for `*args`
74+
"ANN003", # Missing type annotation for `**kwargs`
75+
"D105", # Missing docstring in magic method
76+
"D203", # 1 blank line before after class docstring
77+
"D204", # 1 blank line required after class docstring
78+
"D413", # 1 blank line after parameters
79+
"SIM108", # Simplify if/else to one line; not always clearer
80+
"D206", # Docstrings should be indented with spaces; unnecessary when running ruff-format
81+
"E501", # Line length too long; unnecessary when running ruff-format
82+
"W191", # Indentation contains tabs; unnecessary when running ruff-format
83+
84+
# REMOVE AFTER FIXING
85+
"ANN001", # Missing type annotation for function argument `args`
86+
"ANN202", # Missing Missing return type annotation for private function
87+
"D103", # Missing docstring in public function
88+
"D101", # Missing docstring in public class
89+
]
90+
91+
92+
[tool.ruff.lint.per-file-ignores]
93+
"__init__.py" = ["F401"]
94+

setup.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -204,6 +204,7 @@ def select_constraint(default, nightly=None, git_master=None):
204204
extras_require={
205205
'mutual-information': _make_mutual_information_requirements(),
206206
'visualization': _make_visualization_requirements(),
207+
'dev': ["precommit"]
207208
'all': _make_all_extra_requirements(),
208209
},
209210
python_requires='>=3.9,<4',

0 commit comments

Comments
 (0)