Skip to content

Commit 79189d8

Browse files
feat: migrate from pylint/black to ruff (#31)
Linked Epic: overhangio/tutor#1251 - Migrate linting/formatting from **pylint/black** to **ruff** - Add new rules: - `I`: sort imports - `N`: enforce PEP8 naming standards - `W292`: check for missing newline at EOF - For config lines exceeding the 88-character limit, add `# noqa: E501` to ignore - Replace `pylint`/`black` with `ruff` as optional dev dependency - Add check for Python package distribution build in GitHub CI (`make test`) - This ensures PyPI publishing won’t fail due to build errors
1 parent f95bf7c commit 79189d8

5 files changed

Lines changed: 45 additions & 19 deletions

File tree

.hatch_build.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,5 +16,5 @@ def load_about() -> dict[str, str]:
1616
with open(
1717
os.path.join(HERE, "tutorjupyter", "__about__.py"), "rt", encoding="utf-8"
1818
) as f:
19-
exec(f.read(), about) # pylint: disable=exec-used
19+
exec(f.read(), about)
2020
return about

Makefile

Lines changed: 20 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,42 @@
11
.DEFAULT_GOAL := help
22
.PHONY: docs
33
SRC_DIRS = ./tutorjupyter
4-
BLACK_OPTS = --exclude templates ${SRC_DIRS}
54

6-
# Warning: These checks are not necessarily run on every PR.
7-
test: test-lint test-types test-format # Run some static checks.
5+
# Warning: These checks are run on every PR.
6+
test: test-lint test-format test-types test-pythonpackage # Run some static checks.
87

9-
test-format: ## Run code formatting tests
10-
black --check --diff $(BLACK_OPTS)
8+
test-format: ## Run code formatting tests.
9+
ruff format --check --diff $(SRC_DIRS)
1110

1211
test-lint: ## Run code linting tests
13-
pylint --errors-only --enable=unused-import,unused-argument --ignore=templates --ignore=docs/_ext ${SRC_DIRS}
12+
ruff check ${SRC_DIRS}
1413

1514
test-types: ## Run type checks.
1615
mypy --exclude=templates --ignore-missing-imports --implicit-reexport --strict ${SRC_DIRS}
1716

18-
format: ## Format code automatically
19-
black $(BLACK_OPTS)
17+
build-pythonpackage: ## Build the "tutor-jupyter" python package for upload to pypi
18+
python -m build --sdist
2019

21-
isort: ## Sort imports. This target is not mandatory because the output may be incompatible with black formatting. Provided for convenience purposes.
22-
isort --skip=templates ${SRC_DIRS}
20+
test-pythonpackage: build-pythonpackage ## Test that package can be uploaded to pypi
21+
twine check dist/tutor_jupyter-$(shell make version).tar.gz
22+
23+
format: ## Format code automatically.
24+
ruff format ${SRC_DIRS}
25+
26+
fix-lint: ## Fix lint errors automatically
27+
ruff check --fix ${SRC_DIRS}
2328

2429
changelog-entry: ## Create a new changelog entry.
2530
scriv create
2631

2732
changelog: ## Collect changelog entries in the CHANGELOG.md file.
2833
scriv collect
2934

30-
ESCAPE = 
31-
help: ## Print this help
35+
version: ## Print the current tutor-jupyter version
36+
@python -c 'import io, os; about = {}; exec(io.open(os.path.join("tutorjupyter", "__about__.py"), "rt", encoding="utf-8").read(), about); print(about["__version__"])'
37+
38+
ESCAPE =
39+
help: ## Print this help.
3240
@grep -E '^([a-zA-Z_-]+:.*?## .*|######* .+)$$' Makefile \
3341
| sed 's/######* \(.*\)/@ $(ESCAPE)[1;31m\1$(ESCAPE)[0m/g' | tr '@' '\n' \
3442
| awk 'BEGIN {FS = ":.*?## "}; {printf "\033[33m%-30s\033[0m %s\n", $$1, $$2}'
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
- [Improvement] Migrate from pylint and black to ruff. (by @Abdul-Muqadim-Arbisoft)
2+
- [Improvement] Test python package distribution build when running make test. (by @Abdul-Muqadim-Arbisoft)

pyproject.toml

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,7 @@ dynamic = ["version"]
3636
[project.optional-dependencies]
3737
dev = [
3838
"tutor[dev]>=20.0.0,<21.0.0",
39-
"pylint",
40-
"black"
39+
"ruff",
4140
]
4241

4342
[project.entry-points."tutor.plugin.v1"]
@@ -67,3 +66,19 @@ exclude = ["tests*"]
6766

6867
[tool.hatch.build.targets.wheel]
6968
packages = ["tutorjupyter"]
69+
70+
[tool.ruff]
71+
exclude = ["templates", "docs/_ext"]
72+
73+
[tool.ruff.lint]
74+
# E: pycodestyle errors
75+
# I: isort
76+
# N: pep8-naming
77+
select = ["E", "I", "N"]
78+
79+
# F401: unused-import
80+
# F841: unused-variable
81+
# W292: missing-newline-at-end-of-file
82+
extend-select = ["F401", "F841", "W292"]
83+
84+
[tool.ruff.format]

tutorjupyter/plugin.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,8 @@
2424
config: t.Dict[str, t.Dict[str, t.Any]] = {
2525
"defaults": {
2626
"VERSION": __version__,
27-
"DOCKER_IMAGE_HUB": "{{ DOCKER_REGISTRY }}overhangio/jupyterhub:{{ JUPYTER_VERSION }}",
28-
"DOCKER_IMAGE_LAB": "{{ DOCKER_REGISTRY }}overhangio/jupyterlab:{{ JUPYTER_VERSION }}",
27+
"DOCKER_IMAGE_HUB": "{{ DOCKER_REGISTRY }}overhangio/jupyterhub:{{ JUPYTER_VERSION }}", # noqa: E501
28+
"DOCKER_IMAGE_LAB": "{{ DOCKER_REGISTRY }}overhangio/jupyterlab:{{ JUPYTER_VERSION }}", # noqa: E501
2929
"HOST": "jupyter.{{ LMS_HOST }}",
3030
"DEFAULT_PASSPORT_ID": "jupyterhub",
3131
"LTI_CLIENT_KEY": "openedx",
@@ -52,9 +52,10 @@
5252

5353
def jupyterhub_crypt_key(size: int) -> str:
5454
"""
55-
Return a random hex-encoded bytes string of fixed size. This is equivalent to `openssl rand -hex 32`.
55+
Return a random hex-encoded bytes string of fixed size.
56+
This is equivalent to `openssl rand -hex 32`.
5657
https://jupyterhub.readthedocs.io/en/stable/reference/authenticators.html#authentication-state
57-
"""
58+
""" # noqa: E501
5859
return codecs.encode(token_bytes(size), "hex").decode()
5960

6061

0 commit comments

Comments
 (0)