Skip to content

Commit f87483b

Browse files
committed
Set up lint workflow
1 parent e11cb53 commit f87483b

File tree

4 files changed

+180
-0
lines changed

4 files changed

+180
-0
lines changed

.github/workflows/lint.yml

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
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/checkout@v4
13+
- uses: actions/setup-python@v5
14+
- uses: pre-commit/action@v3.0.1

.pre-commit-config.yaml

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
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"]

pyproject.toml

Lines changed: 123 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,123 @@
1+
[build-system]
2+
requires = [
3+
"setuptools",
4+
"wheel",
5+
]
6+
7+
[tool.ruff]
8+
line-length = 88
9+
10+
[tool.ruff.lint]
11+
select = [
12+
# pycodestyle
13+
"E",
14+
"W",
15+
# Pyflakes
16+
"F",
17+
# pyupgrade
18+
"UP",
19+
# flake8-bugbear
20+
"B",
21+
# flake8-simplify
22+
"SIM",
23+
# isort
24+
"I",
25+
# pep8 naming
26+
"N",
27+
# pydocstyle
28+
"D",
29+
# annotations
30+
"ANN",
31+
# debugger
32+
"T10",
33+
# flake8-pytest
34+
"PT",
35+
# flake8-return
36+
"RET",
37+
# flake8-unused-arguments
38+
"ARG",
39+
# flake8-fixme
40+
"FIX",
41+
# flake8-eradicate
42+
"ERA",
43+
# pandas-vet
44+
"PD",
45+
# numpy-specific rules
46+
"NPY",
47+
]
48+
ignore = [
49+
"ANN002", # Missing type annotation for `*args`
50+
"ANN003", # Missing type annotation for `**kwargs`
51+
"ANN101", # Missing type annotation for `self`
52+
"ANN102", # Missing type annotation for `cls` in classmethod
53+
"ANN201", # Missing return type annotation for public function (makes no sense for NoneType return types...)
54+
"ANN204", # Missing return type annotation for special method
55+
"D100", # Missing docstring in public module
56+
"D104", # Missing docstring in public package
57+
"D105", # Missing docstring in magic method
58+
"D107", # Missing docstring in `__init__`
59+
"D203", # 1 blank line before after class docstring
60+
"D204", # 1 blank line required after class docstring
61+
"D206", # Advised to disable by ruff-format
62+
"D211", # No blank line before class
63+
"D213", # Multiline summary second line
64+
"D413", # 1 blank line after parameters
65+
"E501", # Advised to disable by ruff-format
66+
"N802", # Function name should be lowercase; unittest uses mixed case
67+
"PD901", # Avoid using 'df' for pandas dataframes. Perfectly fine in functions with limited scope
68+
"SIM108", # Simplify if/else to one line; not always clearer
69+
"W191", # Advised to disable by ruff-format
70+
71+
# These are issues which remain to be fixed
72+
"ANN001", # Missing type annotation for function argument
73+
"ANN202", # Missing return type for private function
74+
"ANN206", # Missing return type annotation for classmethod
75+
"ANN401", # Dynamically typed expressions (typing.Any) are disallowed
76+
"ARG002", # Unused method argument
77+
"B007", # Loop control variable not used within loop body
78+
"B008", # Do not perform function call in argument defaults
79+
"B018", # Found useless expression
80+
"B024", # <class> is an abstract base class, but it has no abstract methods
81+
"D101", # Missing docstring in public class
82+
"D102", # Missing docstring in public method
83+
"D103", # Missing docstring in public function
84+
"D200", # One-line docstring should fit on one line
85+
"D401", # First line of docstring should be in imperative mood
86+
"D404", # First word of the docstring should not be "This"
87+
"E721", # Use `is` and `is not` for type comparisons, or `isinstance()` for isinstance checks
88+
"ERA001", # Dead code
89+
"FIX002", # Line contains TODO, consider resolving the issue
90+
"PD011", # Use `.to_numpy()` instead of `.values`
91+
"PD013", # `.melt` is preferred to `.stack`
92+
"RET504", # Unncessary assignment before `return`
93+
"RET505", # Unncessary `else` after `return` statement
94+
"SIM101", # Multiple `isinstance` calls, merge into a single call
95+
"SIM102", # Use a single `if` statement instead of nested `if` statements
96+
"SIM105", # Replace with `contextlib.suppress(FileNotFoundError)`
97+
"SIM110", # Use `return all(...)` instead of `for` loop
98+
"SIM117", # Use a single `with` statement with multiple contexts instead of nested `with` statements
99+
"SIM118", # Use `key in dict` instead of `key in dict.keys()`
100+
"UP008", # Use `super()` instead of `super(__class__, self)`
101+
"UP031", # Use format specifiers instead of percent format
102+
]
103+
104+
[tool.ruff.lint.per-file-ignores]
105+
"__init__.py" = [
106+
"F401", # Unused import
107+
]
108+
"*_test.py" = [
109+
"ANN001", # Type annotations aren't needed for tests; these are fixtures or parametrizations
110+
"PT009", # Use a regular `assert` instead of a unittest-style `assertEqual`
111+
"PT027", # Use `pytest.raises` instead of unittest-style `assertRaisesRegex`
112+
113+
# Missing docstrings; probably want to fill these out for tests. For now, we just disable
114+
"D101", # Missing docstring in public class
115+
"D102", # Missing docstring in public method
116+
117+
]
118+
119+
[tool.ruff.lint.pydocstyle]
120+
convention = "google"
121+
122+
[tool.isort]
123+
profile = "black"

setup.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,11 @@ def select_constraint(default, nightly=None, git_master=None):
8989
git_master='@git+https://github.com/tensorflow/metadata@master'),
9090
'pyarrow>=10,<11',
9191
],
92+
extras_require={
93+
'lint': [
94+
'pre-commit',
95+
]
96+
},
9297
# Add in any packaged data.
9398
include_package_data=True,
9499
package_data={'': ['*.lib', '*.so']},

0 commit comments

Comments
 (0)