Skip to content

Commit 13da199

Browse files
feat: migrate from pylint/black to ruff (#42)
1 parent 05ada48 commit 13da199

5 files changed

Lines changed: 37 additions & 12 deletions

File tree

.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, "tutorxqueue", "__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: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,40 @@
11
.DEFAULT_GOAL := help
22
.PHONY: docs
33
SRC_DIRS = ./tutorxqueue
4-
BLACK_OPTS = --exclude templates ${SRC_DIRS}
54

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

98
test-format: ## Run code formatting tests
10-
black --check --diff $(BLACK_OPTS)
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

17+
build-pythonpackage: ## Build the "tutor-xqueue" python package for upload to pypi
18+
python -m build --sdist
19+
20+
test-pythonpackage: build-pythonpackage ## Test that package can be uploaded to pypi
21+
twine check dist/tutor_xqueue-$(shell make version).tar.gz
22+
1823
format: ## Format code automatically
19-
black $(BLACK_OPTS)
24+
ruff format ${SRC_DIRS}
2025

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}
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

35+
version: ## Print the current tutor-xqueue version
36+
@python -c 'import io, os; about = {}; exec(io.open(os.path.join("tutorxqueue", "__about__.py"), "rt", encoding="utf-8").read(), about); print(about["__version__"])'
37+
3038
ESCAPE = 
3139
help: ## Print this help
3240
@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 @rehmansheikh222)
2+
- [Improvement] Test python package distribution build when running make test. (by @rehmansheikh222)

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

4342
# https://packaging.python.org/en/latest/specifications/well-known-project-urls/#well-known-labels
@@ -68,3 +67,19 @@ exclude = ["tests*"]
6867

6968
[project.entry-points."tutor.plugin.v1"]
7069
xqueue = "tutorxqueue.plugin"
70+
71+
[tool.ruff]
72+
exclude = ["templates", "docs/_ext"]
73+
74+
[tool.ruff.lint]
75+
# E: pycodestyle errors
76+
# I: isort
77+
# N: pep8-naming
78+
select = ["E", "I", "N"]
79+
80+
# F401: unused-import
81+
# F841: unused-variable
82+
# W292: missing-newline-at-end-of-file
83+
extend-select = ["F401", "F841", "W292"]
84+
85+
[tool.ruff.format]

tutorxqueue/plugin.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
"defaults": {
2424
"VERSION": __version__,
2525
"AUTH_USERNAME": "lms",
26-
"DOCKER_IMAGE": "{{ DOCKER_REGISTRY }}overhangio/openedx-xqueue:{{ XQUEUE_VERSION }}",
26+
"DOCKER_IMAGE": "{{ DOCKER_REGISTRY }}overhangio/openedx-xqueue:{{ XQUEUE_VERSION }}", # noqa: E501
2727
"HOST": "xqueue.{{ LMS_HOST }}",
2828
"MYSQL_DATABASE": "xqueue",
2929
"MYSQL_USERNAME": "xqueue",
@@ -200,7 +200,7 @@ def login(self) -> None:
200200
message = response.get("content")
201201
if message != "Logged in":
202202
raise exceptions.TutorError(
203-
f"Could not login to xqueue server at {self.base_url}. Response: '{message}'"
203+
f"Could not login to xqueue server at {self.base_url}. Response: '{message}'" # noqa: E501
204204
)
205205

206206
def show_submission(self, queue: str) -> Union[dict[str, Any], Any]:

0 commit comments

Comments
 (0)