Skip to content

Commit 84573a1

Browse files
authored
Adopt ruff and address lint (#37)
* adopt ruff and address lint * fix test fixture * fix test fixture * try to fix downstream
1 parent 68f5d96 commit 84573a1

File tree

7 files changed

+194
-147
lines changed

7 files changed

+194
-147
lines changed

.github/dependabot.yml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
version: 2
22
updates:
3-
# Set update schedule for GitHub Actions
43
- package-ecosystem: "github-actions"
54
directory: "/"
65
schedule:
7-
# Check for updates to GitHub Actions every weekday
6+
interval: "weekly"
7+
- package-ecosystem: "pip"
8+
directory: "/"
9+
schedule:
810
interval: "weekly"

.github/workflows/test.yml

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,19 @@ jobs:
4444
- uses: jupyterlab/maintainer-tools/.github/actions/base-setup@v1
4545
- run: hatch run docs:build
4646

47+
test_lint:
48+
name: Test Lint
49+
runs-on: ubuntu-latest
50+
steps:
51+
- uses: actions/checkout@v3
52+
- uses: jupyterlab/maintainer-tools/.github/actions/base-setup@v1
53+
- name: Run Linters
54+
run: |
55+
hatch run typing:test
56+
hatch run lint:style
57+
pipx run 'validate-pyproject[all]' pyproject.toml
58+
pipx run doc8 --max-line-length=200 --ignore-path=docs/source/other/full-config.rst
59+
4760
test_minimum_versions:
4861
name: Test Minimum Versions
4962
timeout-minutes: 20
@@ -90,14 +103,6 @@ jobs:
90103
with:
91104
test_command: hatch run test:test
92105

93-
pre_commit:
94-
name: pre-commit
95-
runs-on: ubuntu-latest
96-
steps:
97-
- uses: actions/checkout@v3
98-
- uses: jupyterlab/maintainer-tools/.github/actions/base-setup@v1
99-
- uses: jupyterlab/maintainer-tools/.github/actions/pre-commit@v1
100-
101106
check_release:
102107
runs-on: ubuntu-latest
103108
steps:
@@ -146,7 +151,7 @@ jobs:
146151
if: always()
147152
needs:
148153
- build
149-
- pre_commit
154+
- test_lint
150155
- test_docs
151156
- test_minimum_versions
152157
- test_prereleases

.pre-commit-config.yaml

Lines changed: 12 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
default_language_version:
2-
node: system
1+
ci:
2+
autoupdate_schedule: monthly
33

44
repos:
55
- repo: https://github.com/pre-commit/pre-commit-hooks
@@ -18,59 +18,23 @@ repos:
1818
- id: check-builtin-literals
1919
- id: trailing-whitespace
2020

21-
- repo: https://github.com/psf/black
22-
rev: 22.10.0
23-
hooks:
24-
- id: black
25-
args: [--line-length=100]
26-
27-
- repo: https://github.com/PyCQA/isort
28-
rev: 5.10.1
29-
hooks:
30-
- id: isort
31-
files: \.py$
32-
args: [--profile=black]
33-
34-
- repo: https://github.com/pre-commit/mirrors-mypy
35-
rev: v0.991
36-
hooks:
37-
- id: mypy
38-
additional_dependencies: [types-requests]
39-
40-
- repo: https://github.com/abravalheri/validate-pyproject
41-
rev: v0.10.1
21+
- repo: https://github.com/python-jsonschema/check-jsonschema
22+
rev: 0.19.2
4223
hooks:
43-
- id: validate-pyproject
44-
stages: [manual]
24+
- id: check-github-workflows
4525

4626
- repo: https://github.com/executablebooks/mdformat
4727
rev: 0.7.16
4828
hooks:
4929
- id: mdformat
5030

51-
- repo: https://github.com/asottile/pyupgrade
52-
rev: v3.3.0
53-
hooks:
54-
- id: pyupgrade
55-
args: [--py38-plus]
56-
57-
- repo: https://github.com/PyCQA/doc8
58-
rev: v1.0.0
59-
hooks:
60-
- id: doc8
61-
args: [--max-line-length=200]
62-
stages: [manual]
63-
64-
- repo: https://github.com/john-hen/Flake8-pyproject
65-
rev: 1.2.2
31+
- repo: https://github.com/psf/black
32+
rev: 22.10.0
6633
hooks:
67-
- id: Flake8-pyproject
68-
alias: flake8
69-
additional_dependencies:
70-
["flake8-bugbear==22.6.22", "flake8-implicit-str-concat==0.2.0"]
71-
stages: [manual]
34+
- id: black
7235

73-
- repo: https://github.com/python-jsonschema/check-jsonschema
74-
rev: 0.19.2
36+
- repo: https://github.com/charliermarsh/ruff-pre-commit
37+
rev: v0.0.165
7538
hooks:
76-
- id: check-github-workflows
39+
- id: ruff
40+
args: ["--fix"]

pyproject.toml

Lines changed: 85 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,14 @@ server = [
5151
test = [
5252
"pytest-timeout"
5353
]
54+
lint = [
55+
"black>=22.6.0",
56+
"mdformat>0.7",
57+
"ruff>=0.0.156",
58+
]
59+
typing = [
60+
"mypy>=0.990"
61+
]
5462

5563
[project.urls]
5664
Homepage = "http://jupyter.org"
@@ -86,6 +94,26 @@ dependencies = ["coverage[toml]"]
8694
test = "coverage run -m pytest {args}"
8795
nowarn = "test -W default {args}"
8896

97+
[tool.hatch.envs.typing]
98+
features = ["test", "typing", "server", "client"]
99+
dependencies = ["mypy>=0.990"]
100+
[tool.hatch.envs.typing.scripts]
101+
test = "mypy --install-types --non-interactive {args:.}"
102+
103+
[tool.hatch.envs.lint]
104+
features = ["lint"]
105+
[tool.hatch.envs.lint.scripts]
106+
style = [
107+
"ruff {args:.}",
108+
"black --check --diff {args:.}",
109+
"mdformat --check {args:docs *.md}"
110+
]
111+
fmt = [
112+
"black {args:.}",
113+
"ruff --fix {args:.}",
114+
"mdformat {args:docs *.md}"
115+
]
116+
89117
[tool.jupyter-releaser.options]
90118
post-version-spec = "dev"
91119

@@ -130,18 +158,61 @@ warn_redundant_casts = true
130158
explicit_package_bases = true
131159
namespace_packages = true
132160

133-
[tool.flake8]
134-
ignore = "E501, W503, E402"
135-
builtins = "c, get_config"
136-
exclude = [
137-
".cache",
138-
".github",
139-
"docs",
140-
"setup.py",
141-
]
142-
enable-extensions = "G"
143-
extend-ignore = [
144-
"G001", "G002", "G004", "G200", "G201", "G202",
145-
# black adds spaces around ':'
146-
"E203",
161+
[tool.black]
162+
line-length = 100
163+
skip-string-normalization = true
164+
target-version = ["py38"]
165+
166+
[tool.ruff]
167+
target-version = "py38"
168+
line-length = 100
169+
select = [
170+
"A", "B", "C", "E", "F", "FBT", "I", "N", "Q", "RUF", "S", "T",
171+
"UP", "W", "YTT",
172+
]
173+
ignore = [
174+
# Allow non-abstract empty methods in abstract base classes
175+
"B027",
176+
# Ignore McCabe complexity
177+
"C901",
178+
# Allow boolean positional values in function calls, like `dict.get(... True)`
179+
"FBT003",
180+
# Use of `assert` detected
181+
"S101",
182+
# Line too long
183+
"E501",
184+
# Relative imports are banned
185+
"I252",
186+
# Boolean ... in function definition
187+
"FBT001",
188+
"FBT002",
189+
# Module level import not at top of file
190+
"E402",
191+
# A001/A002/A003 .. is shadowing a python builtin
192+
"A001",
193+
"A002",
194+
"A003",
195+
# Possible hardcoded password
196+
"S105",
197+
"S106",
198+
# Q000 Single quotes found but double quotes preferred
199+
"Q000",
200+
# N806 Variable `B` in function should be lowercase
201+
"N806",
202+
]
203+
unfixable = [
204+
# Don't touch print statements
205+
"T201",
206+
# Don't touch noqa lines
207+
"RUF100",
147208
]
209+
210+
[tool.ruff.per-file-ignores]
211+
# B011 Do not call assert False since python -O removes these calls
212+
# F841 local variable 'foo' is assigned to but never used
213+
# C408 Unnecessary `dict` call
214+
# E402 Module level import not at top of file
215+
# T201 `print` found
216+
# B007 Loop control variable `i` not used within the loop body.
217+
# N802 Function name `assertIn` should be lowercase
218+
"tests/*" = ["B011", "F841", "C408", "E402", "T201", "B007", "N802"]

0 commit comments

Comments
 (0)