Skip to content

Commit 200549d

Browse files
committed
setup pre-commit
1 parent f188111 commit 200549d

File tree

4 files changed

+147
-1
lines changed

4 files changed

+147
-1
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: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
# Copyright 2020 Google LLC
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
[build-system]
16+
requires = [
17+
"setuptools",
18+
"wheel",
19+
]
20+
21+
[tool.ruff]
22+
line-length = 88
23+
24+
[tool.ruff.lint]
25+
select = [
26+
# pycodestyle
27+
"E",
28+
"W",
29+
# Pyflakes
30+
"F",
31+
# pyupgrade
32+
"UP",
33+
# flake8-bugbear
34+
"B",
35+
# flake8-simplify
36+
"SIM",
37+
# isort
38+
"I",
39+
# pep8 naming
40+
"N",
41+
# pydocstyle
42+
"D",
43+
# annotations
44+
"ANN",
45+
# debugger
46+
"T10",
47+
# flake8-pytest
48+
"PT",
49+
# flake8-return
50+
"RET",
51+
# flake8-unused-arguments
52+
"ARG",
53+
# flake8-fixme
54+
"FIX",
55+
# flake8-eradicate
56+
"ERA",
57+
# pandas-vet
58+
"PD",
59+
# numpy-specific rules
60+
"NPY",
61+
]
62+
63+
ignore = [
64+
"D104", # Missing docstring in public package
65+
"D100", # Missing docstring in public module
66+
"D211", # No blank line before class
67+
"PD901", # Avoid using 'df' for pandas dataframes. Perfectly fine in functions with limited scope
68+
"ANN201", # Missing return type annotation for public function (makes no sense for NoneType return types...)
69+
"ANN101", # Missing type annotation for `self`
70+
"ANN204", # Missing return type annotation for special method
71+
"ANN002", # Missing type annotation for `*args`
72+
"ANN003", # Missing type annotation for `**kwargs`
73+
"D105", # Missing docstring in magic method
74+
"D203", # 1 blank line before after class docstring
75+
"D204", # 1 blank line required after class docstring
76+
"D413", # 1 blank line after parameters
77+
"SIM108", # Simplify if/else to one line; not always clearer
78+
"D206", # Docstrings should be indented with spaces; unnecessary when running ruff-format
79+
"E501", # Line length too long; unnecessary when running ruff-format
80+
"W191", # Indentation contains tabs; unnecessary when running ruff-format
81+
]
82+
83+
84+
[tool.ruff.lint.per-file-ignores]
85+
"__init__.py" = ["F401"]

setup.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,8 @@ def _make_docs_packages():
110110
],
111111
namespace_packages=[],
112112
install_requires=_make_required_install_packages(),
113-
extras_require= {
113+
extras_require={
114+
"dev": ["pre-commit"],
114115
'docs': _make_docs_packages(),
115116
},
116117
python_requires='>=3.9,<4',

0 commit comments

Comments
 (0)