Skip to content

Commit bc81ed6

Browse files
authored
Adopt ruff and address lint (#321)
1 parent dc10306 commit bc81ed6

File tree

6 files changed

+120
-69
lines changed

6 files changed

+120
-69
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
@@ -85,6 +85,19 @@ jobs:
8585
- uses: jupyterlab/maintainer-tools/.github/actions/base-setup@v1
8686
- run: hatch run docs:build
8787

88+
test_lint:
89+
name: Test Lint
90+
runs-on: ubuntu-latest
91+
steps:
92+
- uses: actions/checkout@v3
93+
- uses: jupyterlab/maintainer-tools/.github/actions/base-setup@v1
94+
- name: Run Linters
95+
run: |
96+
hatch run typing:test
97+
hatch run lint:style
98+
pipx run 'validate-pyproject[all]' pyproject.toml
99+
pipx run doc8 --max-line-length=200
100+
88101
make_sdist:
89102
name: Make SDist
90103
runs-on: ubuntu-latest
@@ -103,14 +116,6 @@ jobs:
103116
- uses: jupyterlab/maintainer-tools/.github/actions/base-setup@v1
104117
- uses: jupyterlab/maintainer-tools/.github/actions/test-sdist@v1
105118

106-
pre_commit:
107-
name: pre-commit
108-
runs-on: ubuntu-latest
109-
steps:
110-
- uses: actions/checkout@v3
111-
- uses: jupyterlab/maintainer-tools/.github/actions/base-setup@v1
112-
- uses: jupyterlab/maintainer-tools/.github/actions/pre-commit@v1
113-
114119
check_release:
115120
runs-on: ubuntu-latest
116121
steps:
@@ -139,7 +144,7 @@ jobs:
139144
if: always()
140145
needs:
141146
- build
142-
- pre_commit
147+
- test_lint
143148
- test_docs
144149
- test_minimum_versions
145150
- test_prereleases

.pre-commit-config.yaml

Lines changed: 14 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
1+
ci:
2+
autoupdate_schedule: monthly
3+
14
repos:
25
- repo: https://github.com/pre-commit/pre-commit-hooks
36
rev: v4.4.0
47
hooks:
5-
- id: debug-statements
68
- id: end-of-file-fixer
79
- id: check-case-conflict
810
- id: check-executables-have-shebangs
@@ -11,72 +13,28 @@ repos:
1113
- id: check-case-conflict
1214
- id: check-toml
1315
- id: check-yaml
16+
- id: debug-statements
1417
- id: forbid-new-submodules
1518
- id: check-builtin-literals
1619
- id: trailing-whitespace
1720

18-
- repo: https://github.com/psf/black
19-
rev: 22.10.0
20-
hooks:
21-
- id: black
22-
args: ["--line-length", "100"]
23-
24-
- repo: https://github.com/PyCQA/isort
25-
rev: 5.10.1
26-
hooks:
27-
- id: isort
28-
files: \.py$
29-
args: [--profile=black]
30-
31-
- repo: https://github.com/abravalheri/validate-pyproject
32-
rev: v0.10.1
21+
- repo: https://github.com/python-jsonschema/check-jsonschema
22+
rev: 0.19.2
3323
hooks:
34-
- id: validate-pyproject
35-
stages: [manual]
24+
- id: check-github-workflows
3625

3726
- repo: https://github.com/executablebooks/mdformat
3827
rev: 0.7.16
3928
hooks:
4029
- id: mdformat
41-
additional_dependencies:
42-
[mdformat-gfm, mdformat-frontmatter, mdformat-footnote]
4330

44-
- repo: https://github.com/asottile/pyupgrade
45-
rev: v3.3.0
46-
hooks:
47-
- id: pyupgrade
48-
args: [--py38-plus]
49-
50-
- repo: https://github.com/PyCQA/doc8
51-
rev: v1.0.0
52-
hooks:
53-
- id: doc8
54-
args: [--max-line-length=200]
55-
stages: [manual]
56-
57-
- repo: https://github.com/pycqa/flake8
58-
rev: 6.0.0
59-
hooks:
60-
- id: flake8
61-
additional_dependencies:
62-
["flake8-bugbear==22.6.22", "flake8-implicit-str-concat==0.2.0"]
63-
stages: [manual]
64-
65-
- repo: https://github.com/pre-commit/mirrors-mypy
66-
rev: v0.991
31+
- repo: https://github.com/psf/black
32+
rev: 22.10.0
6733
hooks:
68-
- id: mypy
69-
args: ["--config-file", "pyproject.toml"]
70-
stages: [manual]
71-
additional_dependencies: [pytest, platformdirs, traitlets, ipykernel]
72-
exclude: |
73-
exclude: |
74-
(?x)^(
75-
jupyter_core/tests/.*_config.py |
76-
scripts/jupyter
77-
)$
34+
- id: black
7835

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

jupyter_core/application.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@
5959
base_flags.update(_jupyter_flags)
6060

6161

62-
class NoStart(Exception):
62+
class NoStart(Exception): # noqa
6363
"""Exception to raise when an application shouldn't start"""
6464

6565

jupyter_core/paths.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,7 @@ def jupyter_runtime_dir() -> str:
174174
).split(os.pathsep)
175175
else:
176176
deprecation(
177-
"Jupyter is migrating its paths to use standard platformdirs\n" # noqa
177+
"Jupyter is migrating its paths to use standard platformdirs\n"
178178
+ "given by the platformdirs library. To remove this warning and\n"
179179
+ "see the appropriate new directories, set the environment variable\n"
180180
+ "`JUPYTER_PLATFORM_DIRS=1` and then run `jupyter --paths`.\n"

pyproject.toml

Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,8 @@ docs = [
5151
"sphinxcontrib_github_alt",
5252
"traitlets",
5353
]
54+
lint = ["black>=22.6.0", "mdformat>0.7", "ruff>=0.0.156"]
55+
typing = ["mypy>=0.990"]
5456

5557
[project.scripts]
5658
jupyter = "jupyter_core.command:main"
@@ -81,6 +83,26 @@ dependencies = ["coverage", "pytest-cov"]
8183
test = "python -m pytest -vv --cov jupyter_core --cov-branch --cov-report term-missing:skip-covered {args}"
8284
nowarn = "test -W default {args}"
8385

86+
[tool.hatch.envs.typing]
87+
features = ["test", "typing"]
88+
dependencies = ["mypy>=0.990"]
89+
[tool.hatch.envs.typing.scripts]
90+
test = "mypy --install-types --non-interactive {args:.}"
91+
92+
[tool.hatch.envs.lint]
93+
features = ["lint"]
94+
[tool.hatch.envs.lint.scripts]
95+
style = [
96+
"ruff {args:.}",
97+
"black --check --diff {args:.}",
98+
"mdformat --check {args:*.md}"
99+
]
100+
fmt = [
101+
"black {args:.}",
102+
"ruff --fix {args:.}",
103+
"mdformat {args:*.md}"
104+
]
105+
84106
[tool.mypy]
85107
check_untyped_defs = true
86108
disallow_any_generics = true
@@ -97,6 +119,9 @@ warn_unused_configs = true
97119
warn_redundant_casts = true
98120
warn_return_any = true
99121
warn_unused_ignores = true
122+
exclude = [
123+
"jupyter_core/tests/.*/profile_default/.*_config.py"
124+
]
100125

101126
[tool.pytest.ini_options]
102127
addopts = "-raXs --durations 10 --color=yes --doctest-modules --ignore-glob=jupyter_core/tests/dotipython*"
@@ -123,3 +148,64 @@ exclude_lines = [
123148
"class .*\bProtocol\\):",
124149
"@(abc\\.)?abstractmethod",
125150
]
151+
152+
[tool.black]
153+
line-length = 100
154+
skip-string-normalization = true
155+
target-version = ["py38"]
156+
157+
[tool.ruff]
158+
target-version = "py38"
159+
line-length = 100
160+
select = [
161+
"A", "B", "C", "E", "F", "FBT", "I", "N", "Q", "RUF", "S", "T",
162+
"UP", "W", "YTT",
163+
]
164+
ignore = [
165+
# Allow non-abstract empty methods in abstract base classes
166+
"B027",
167+
# Ignore McCabe complexity
168+
"C901",
169+
# Allow boolean positional values in function calls, like `dict.get(... True)`
170+
"FBT003",
171+
# Use of `assert` detected
172+
"S101",
173+
# Line too long
174+
"E501",
175+
# Relative imports are banned
176+
"I252",
177+
# Boolean ... in function definition
178+
"FBT001", "FBT002",
179+
# Module level import not at top of file
180+
"E402",
181+
# A001/A002/A003 .. is shadowing a python builtin
182+
"A001", "A002", "A003",
183+
# Possible hardcoded password
184+
"S105", "S106",
185+
# Q000 Single quotes found but double quotes preferred
186+
"Q000",
187+
# N806 Variable `B` in function should be lowercase
188+
"N806",
189+
# T201 `print` found
190+
"T201",
191+
# N802 Function name `CreateWellKnownSid` should be lowercase
192+
"N802", "N803"
193+
]
194+
unfixable = [
195+
# Don't touch print statements
196+
"T201",
197+
# Don't touch noqa lines
198+
"RUF100",
199+
]
200+
201+
[tool.ruff.per-file-ignores]
202+
# B011 Do not call assert False since python -O removes these calls
203+
# F841 local variable 'foo' is assigned to but never used
204+
# C408 Unnecessary `dict` call
205+
# E402 Module level import not at top of file
206+
# T201 `print` found
207+
# B007 Loop control variable `i` not used within the loop body.
208+
# N802 Function name `assertIn` should be lowercase
209+
"tests/*" = ["B011", "F841", "C408", "E402", "T201", "B007", "N802"]
210+
# F821 Undefined name `get_config`
211+
"jupyter_core/tests/**/profile_default/*_config.py" = ["F821"]

0 commit comments

Comments
 (0)