Skip to content

Commit ae4e3f2

Browse files
authored
feat: migrate to ruff for linting and formatting checks (#50)
1 parent 4fde7e3 commit ae4e3f2

File tree

5 files changed

+40
-10
lines changed

5 files changed

+40
-10
lines changed

.hatch_build.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,5 +17,5 @@ def update(self, metadata: dict[str, t.Any]) -> None:
1717
def load_about() -> dict[str, str]:
1818
about: dict[str, str] = {}
1919
with open(os.path.join(HERE, "tutornotes", "__about__.py"), "rt", encoding="utf-8") as f:
20-
exec(f.read(), about) # pylint: disable=exec-used
20+
exec(f.read(), about)
2121
return about

Makefile

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,31 @@
11
.DEFAULT_GOAL := help
22
.PHONY: docs
33
SRC_DIRS = ./tutornotes
4-
BLACK_OPTS = --exclude templates ${SRC_DIRS}
4+
RUFF_OPTS = --exclude templates ${SRC_DIRS}
55

66
# Warning: These checks are run on every PR.
7-
test: test-lint test-types test-format # Run some static checks.
7+
test: test-lint test-types test-format test-pythonpackage
88

99
test-format: ## Run code formatting tests.
10-
black --check --diff $(BLACK_OPTS)
10+
ruff format --check --diff $(RUFF_OPTS)
1111

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

1515
test-types: ## Run type checks.
1616
mypy --exclude=templates --ignore-missing-imports --implicit-reexport --strict ${SRC_DIRS}
1717

18+
build-pythonpackage:
19+
python -m build --sdist
20+
21+
test-pythonpackage: build-pythonpackage
22+
twine check dist/tutor_notes-$(shell make version).tar.gz
23+
1824
format: ## Format code automatically.
19-
black $(BLACK_OPTS)
25+
ruff format $(RUFF_OPTS)
26+
27+
fix-lint: ## Fix linting issues automatically.
28+
ruff check --fix $(RUFF_OPTS)
2029

2130
isort: ## Sort imports. This target is not mandatory because the output may be incompatible with black formatting. Provided for convenience purposes.
2231
isort --skip=templates ${SRC_DIRS}
@@ -27,6 +36,9 @@ changelog-entry: ## Create a new changelog entry.
2736
changelog: ## Collect changelog entries in the CHANGELOG.md file.
2837
scriv collect
2938

39+
version: ## Print the current tutor-notes version
40+
@python -c 'import io, os; about = {}; exec(io.open(os.path.join("tutornotes", "__about__.py"), "rt", encoding="utf-8").read(), about); print(about["__version__"])'
41+
3042
ESCAPE = 
3143
help: ## Print this help.
3244
@grep -E '^([a-zA-Z_-]+:.*?## .*|######* .+)$$' Makefile \
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 @dawoudsheraz)
2+
- [Improvement] Test python package distribution build when running make-test. (by @dawoudsheraz)

pyproject.toml

Lines changed: 18 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-
"black",
40-
"pylint"
39+
"ruff"
4140
]
4241

4342

@@ -69,3 +68,20 @@ exclude = ["tests*"]
6968

7069
[project.entry-points."tutor.plugin.v1"]
7170
notes = "tutornotes.plugin"
71+
72+
[tool.ruff]
73+
exclude = ["templates", "docs/_ext"]
74+
75+
[tool.ruff.lint]
76+
# E: pycodestyle errors
77+
# I: isort
78+
# N: pep8-naming
79+
select = ["E", "I", "N"]
80+
81+
# F401: unused-import
82+
# F841: unused-variable
83+
# W292: missing-newline-at-end-of-file
84+
extend-select = ["F401", "F841", "W292"]
85+
86+
[tool.ruff.format]
87+
# Default config is automatically taken from https://docs.astral.sh/ruff/configuration/

tutornotes/plugin.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
config = {
1818
"defaults": {
1919
"VERSION": __version__,
20-
"DOCKER_IMAGE": "{{ DOCKER_REGISTRY }}overhangio/openedx-notes:{{ NOTES_VERSION }}",
20+
"DOCKER_IMAGE": "{{ DOCKER_REGISTRY }}overhangio/openedx-notes:{{ NOTES_VERSION }}", # noqa: E501
2121
"HOST": "notes.{{ LMS_HOST }}",
2222
"MYSQL_DATABASE": "notes",
2323
"MYSQL_USERNAME": "notes",

0 commit comments

Comments
 (0)