Skip to content

Commit ceb424c

Browse files
authored
Adopt ruff and address lint (#471)
* adopt ruff and address lint * fix md changes * update pre-commit
1 parent fdb3352 commit ceb424c

File tree

8 files changed

+136
-109
lines changed

8 files changed

+136
-109
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: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,18 @@ env:
1212
PYTHONDONTWRITEBYTECODE: 1
1313

1414
jobs:
15-
pre_commit:
15+
lint:
16+
name: Test Lint
1617
runs-on: ubuntu-latest
1718
steps:
1819
- uses: actions/checkout@v3
1920
- uses: jupyterlab/maintainer-tools/.github/actions/base-setup@v1
20-
- uses: jupyterlab/maintainer-tools/.github/actions/pre-commit@v1
21+
- name: Run Linters
22+
run: |
23+
hatch run typing:test
24+
hatch run lint:style
25+
pipx run 'validate-pyproject[all]' pyproject.toml
26+
pipx run doc8 --max-line-length=200
2127
2228
check_links:
2329
runs-on: ubuntu-20.04
@@ -145,7 +151,7 @@ jobs:
145151
- check_links
146152
- test
147153
- docs
148-
- pre_commit
154+
- lint
149155
- check_local_actions
150156
- test_minimum_versions
151157
- test_prereleases

.pre-commit-config.yaml

Lines changed: 13 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
ci:
2+
autoupdate_schedule: monthly
3+
14
repos:
25
- repo: https://github.com/pre-commit/pre-commit-hooks
36
rev: v4.4.0
@@ -15,24 +18,10 @@ repos:
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
@@ -41,49 +30,13 @@ repos:
4130
additional_dependencies:
4231
[mdformat-gfm, mdformat-frontmatter, mdformat-footnote]
4332

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/john-hen/Flake8-pyproject
51-
rev: 1.2.2
52-
hooks:
53-
- id: Flake8-pyproject
54-
alias: flake8
55-
additional_dependencies:
56-
["flake8-bugbear==22.6.22", "flake8-implicit-str-concat==0.2.0"]
57-
stages: [manual]
58-
59-
- repo: https://github.com/pre-commit/mirrors-mypy
60-
rev: v0.991
61-
hooks:
62-
- id: mypy
63-
args: ["--config-file", "pyproject.toml"]
64-
additional_dependencies:
65-
[
66-
pytest,
67-
click,
68-
importlib_resources,
69-
types-requests,
70-
fastapi,
71-
mdformat,
72-
]
73-
stages: [manual]
74-
75-
- repo: https://github.com/python-jsonschema/check-jsonschema
76-
rev: 0.19.2
33+
- repo: https://github.com/psf/black
34+
rev: 22.10.0
7735
hooks:
78-
- id: check-github-workflows
79-
name: "Check GitHub Workflows"
80-
files: ^\.github/workflows/
81-
types: [yaml]
36+
- id: black
8237

83-
- repo: https://github.com/python-jsonschema/check-jsonschema
84-
rev: 0.19.2
38+
- repo: https://github.com/charliermarsh/ruff-pre-commit
39+
rev: v0.0.165
8540
hooks:
86-
- id: check-github-workflows
87-
name: "Check Example Workflows"
88-
files: ^example-workflows/
89-
types: [yaml]
41+
- id: ruff
42+
args: ["--fix"]

jupyter_releaser/lib.py

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -87,18 +87,18 @@ def draft_changelog(
8787
owner, repo_name = repo.split("/")
8888
gh = util.get_gh_object(dry_run=dry_run, owner=owner, repo=repo_name, token=auth)
8989

90-
data = dict(
91-
version_spec=version_spec,
92-
ref=ref,
93-
branch=branch,
94-
repo=repo,
95-
since=since,
96-
since_last_stable=since_last_stable,
97-
version=version,
98-
post_version_spec=post_version_spec,
99-
post_version_message=post_version_message,
100-
expected_sha=current_sha,
101-
)
90+
data = {
91+
"version_spec": version_spec,
92+
"ref": ref,
93+
"branch": branch,
94+
"repo": repo,
95+
"since": since,
96+
"since_last_stable": since_last_stable,
97+
"version": version,
98+
"post_version_spec": post_version_spec,
99+
"post_version_message": post_version_message,
100+
"expected_sha": current_sha,
101+
}
102102
with tempfile.TemporaryDirectory() as d:
103103
metadata_path = Path(d) / util.METADATA_JSON
104104
with open(metadata_path, "w") as fid:

jupyter_releaser/tests/test_cli.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -480,7 +480,7 @@ def test_delete_release(npm_dist, runner, mock_github, git_prep, draft_release):
480480

481481

482482
@pytest.mark.skipif(
483-
os.name == "nt" and sys.version_info.major == 3 and sys.version_info.minor < 8,
483+
os.name == "nt" and sys.version_info < (3, 8),
484484
reason="See https://bugs.python.org/issue26660",
485485
)
486486
def test_extract_dist_py(py_package, runner, mocker, mock_github, tmp_path, git_prep):
@@ -506,7 +506,7 @@ def test_extract_dist_py(py_package, runner, mocker, mock_github, tmp_path, git_
506506

507507

508508
@pytest.mark.skipif(
509-
os.name == "nt" and sys.version_info.major == 3 and sys.version_info.minor < 8,
509+
os.name == "nt" and sys.version_info < (3, 8),
510510
reason="See https://bugs.python.org/issue26660",
511511
)
512512
def test_extract_dist_multipy(py_multipackage, runner, mocker, mock_github, tmp_path, git_prep):
@@ -540,7 +540,7 @@ def test_extract_dist_multipy(py_multipackage, runner, mocker, mock_github, tmp_
540540

541541

542542
@pytest.mark.skipif(
543-
os.name == "nt" and sys.version_info.major == 3 and sys.version_info.minor < 8,
543+
os.name == "nt" and sys.version_info < (3, 8),
544544
reason="See https://bugs.python.org/issue26660",
545545
)
546546
def test_extract_dist_npm(npm_dist, runner, mocker, mock_github, tmp_path):

jupyter_releaser/tests/test_functions.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,7 @@ def test_get_empty_changelog(py_package, mocker):
203203
auth=None,
204204
)
205205

206-
assert not ("...None" in resp)
206+
assert "...None" not in resp
207207

208208

209209
def test_splice_github_entry(py_package, mocker):

jupyter_releaser/util.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -480,7 +480,7 @@ def fetch_release_asset(target_dir, asset, auth):
480480
"""Fetch a release asset into a target directory."""
481481
log(f"Fetching {asset.name}...")
482482
url = asset.url
483-
headers = dict(Authorization=f"token {auth}", Accept="application/octet-stream")
483+
headers = {"Authorization": f"token {auth}", "Accept": "application/octet-stream"}
484484
path = Path(target_dir) / asset.name
485485
with requests.get(url, headers=headers, stream=True) as r:
486486
r.raise_for_status()
@@ -494,7 +494,7 @@ def fetch_release_asset_data(asset, auth):
494494
"""Fetch the data for a release asset."""
495495
log(f"Fetching data for {asset.name}...")
496496
url = asset.url
497-
headers = dict(Authorization=f"token {auth}", Accept="application/octet-stream")
497+
headers = {"Authorization": f"token {auth}", "Accept": "application/octet-stream"}
498498

499499
sink = BytesIO()
500500
with requests.get(url, headers=headers, stream=True) as r:
@@ -602,7 +602,9 @@ def prepare_environment(fetch_draft_release=True):
602602
log("User was admin!")
603603
except Exception as e:
604604
log(str(e))
605-
raise RuntimeError("Could not get user permission level, assuming user was not admin!")
605+
raise RuntimeError(
606+
"Could not get user permission level, assuming user was not admin!"
607+
) from None
606608

607609
# Get the latest draft release if none is given.
608610
release_url = os.environ.get("RH_RELEASE_URL")

pyproject.toml

Lines changed: 89 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -53,15 +53,22 @@ docs = [
5353
"sphinx-click",
5454
]
5555
test = [
56-
"coverage",
57-
"fastapi",
58-
"pre-commit",
59-
"pytest>=7.0",
60-
"pytest-cov",
61-
"pytest-mock",
62-
"pytest-xdist[psutil]",
63-
"uvicorn"
56+
"coverage",
57+
"fastapi",
58+
"pre-commit",
59+
"pytest>=7.0",
60+
"pytest-cov",
61+
"pytest-mock",
62+
"pytest-xdist[psutil]",
63+
"uvicorn"
6464
]
65+
lint = [
66+
"black>=22.6.0",
67+
"mdformat>0.7",
68+
"mdformat-gfm>=0.3.5",
69+
"ruff>=0.0.156"
70+
]
71+
typing = ["mypy>=0.990"]
6572

6673
[project.scripts]
6774
jupyter-releaser = "jupyter_releaser.cli:main"
@@ -88,6 +95,25 @@ dependencies = ["coverage", "pytest-cov"]
8895
test = "python -m pytest -vv --cov jupyter_releaser --cov-branch --cov-report term-missing:skip-covered {args}"
8996
nowarn = "test -W default {args}"
9097

98+
[tool.hatch.envs.typing]
99+
features = ["typing", "test"]
100+
[tool.hatch.envs.typing.scripts]
101+
test = "mypy --install-types --non-interactive {args:jupyter_releaser}"
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+
91117
[tool.jupyter-releaser.hooks]
92118
after-populate-release = "bash ./.github/scripts/bump_tag.sh"
93119

@@ -148,23 +174,61 @@ module = [
148174
]
149175
ignore_missing_imports = true
150176

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

0 commit comments

Comments
 (0)