From a539ca2693d0651f531a9b9f92163e8492d63068 Mon Sep 17 00:00:00 2001 From: Abdul-Muqadim-Arbisoft Date: Sun, 7 Sep 2025 19:44:37 +0500 Subject: [PATCH 1/2] feat: migrate from pylint/black to ruff (#64) * feat: migrate from pylint/black to ruff Linked Epic: overhangio/tutor#1251 Some new rules that have been added are: I: sort imports N: check for pep8-naming standards W292: check for missing extra line at EOF Some of our lines, particularly in config break the 88 character line length limit. For that, we add a # noqa: E501 to let ruff know to ignore the rule for that line * test: python package distribution build when running make test Pushing to pypi would occasionally fail because of breaking distribution build. We verify the build in the github CI now so that we can mitigate those errors later on. * fix: install ruff instead of pylint/black as optional dev dependency --- .hatch_build.py | 2 +- Makefile | 24 ++++++++++++------- ...50907_194312_abdul.muqadim_migrate_ruff.md | 2 ++ pyproject.toml | 19 +++++++++++++-- tutorandroid/plugin.py | 4 ++-- 5 files changed, 38 insertions(+), 13 deletions(-) create mode 100644 changelog.d/20250907_194312_abdul.muqadim_migrate_ruff.md diff --git a/.hatch_build.py b/.hatch_build.py index ed60b7f..627375b 100644 --- a/.hatch_build.py +++ b/.hatch_build.py @@ -18,5 +18,5 @@ def load_about() -> dict[str, str]: with open( os.path.join(HERE, "tutorandroid", "__about__.py"), "rt", encoding="utf-8" ) as f: - exec(f.read(), about) # pylint: disable=exec-used + exec(f.read(), about) return about diff --git a/Makefile b/Makefile index a916de8..c9ebb5c 100644 --- a/Makefile +++ b/Makefile @@ -1,25 +1,30 @@ .DEFAULT_GOAL := help .PHONY: docs SRC_DIRS = ./tutorandroid -BLACK_OPTS = --exclude templates ${SRC_DIRS} # Warning: These checks are not necessarily run on every PR. -test: test-lint test-types test-format # Run some static checks. +test: test-lint test-types test-format test-pythonpackage # Run some static checks. test-format: ## Run code formatting tests - black --check --diff $(BLACK_OPTS) + ruff format --check --diff ${SRC_DIRS} test-lint: ## Run code linting tests - pylint --errors-only --enable=unused-import,unused-argument --ignore=templates --ignore=docs/_ext ${SRC_DIRS} + ruff check ${SRC_DIRS} test-types: ## Run type checks. mypy --exclude=templates --ignore-missing-imports --implicit-reexport --strict ${SRC_DIRS} -format: ## Format code automatically - black $(BLACK_OPTS) +build-pythonpackage: ## Build the "tutor-android" python package for upload to pypi + python -m build --sdist -isort: ## Sort imports. This target is not mandatory because the output may be incompatible with black formatting. Provided for convenience purposes. - isort --skip=templates ${SRC_DIRS} +test-pythonpackage: build-pythonpackage ## Test that package can be uploaded to pypi + twine check dist/tutor_android-$(shell make version).tar.gz + +format: ## Format code automatically + ruff format ${SRC_DIRS} + +fix-lint: ## Fix lint errors automatically + ruff check --fix ${SRC_DIRS} changelog-entry: ## Create a new changelog entry. scriv create @@ -27,6 +32,9 @@ changelog-entry: ## Create a new changelog entry. changelog: ## Collect changelog entries in the CHANGELOG.md file. scriv collect +version: ## Print the current tutor-android version + @python -c 'import io, os; about = {}; exec(io.open(os.path.join("tutorandroid", "__about__.py"), "rt", encoding="utf-8").read(), about); print(about["__version__"])' + ESCAPE =  help: ## Print this help @grep -E '^([a-zA-Z_-]+:.*?## .*|######* .+)$$' Makefile \ diff --git a/changelog.d/20250907_194312_abdul.muqadim_migrate_ruff.md b/changelog.d/20250907_194312_abdul.muqadim_migrate_ruff.md new file mode 100644 index 0000000..d484909 --- /dev/null +++ b/changelog.d/20250907_194312_abdul.muqadim_migrate_ruff.md @@ -0,0 +1,2 @@ +- [Improvement] Migrate from pylint and black to ruff. (by @Abdul-Muqadim-Arbisoft) +- [Improvement] Test python package distribution build when running make test. (by @Abdul-Muqadim-Arbisoft) \ No newline at end of file diff --git a/pyproject.toml b/pyproject.toml index 59f40b3..8eb8782 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -35,8 +35,7 @@ dynamic = ["version"] [project.optional-dependencies] dev = [ "tutor[dev]>=20.0.0,<21.0.0", - "pylint", - "black" + "ruff", ] [project.entry-points."tutor.plugin.v1"] @@ -66,3 +65,19 @@ exclude = [ "tests*" ] [tool.hatch.build.targets.wheel] packages = ["tutorandroid"] + +[tool.ruff] +exclude = ["templates", "docs/_ext"] + +[tool.ruff.lint] +# E: pycodestyle errors +# I: isort +# N: pep8-naming +select = ["E", "I", "N"] + +# F401: unused-import +# F841: unused-variable +# W292: missing-newline-at-end-of-file +extend-select = ["F401", "F841", "W292"] + +[tool.ruff.format] \ No newline at end of file diff --git a/tutorandroid/plugin.py b/tutorandroid/plugin.py index a0a2b6c..4b65e2c 100644 --- a/tutorandroid/plugin.py +++ b/tutorandroid/plugin.py @@ -23,8 +23,8 @@ config: t.Dict[str, t.Dict[str, t.Any]] = { # Version 4.0.0 is not working: # https://github.com/overhangio/tutor-android/pull/6#issuecomment-1541510489 "APP_VERSION": "3.1.4", - "DOCKER_IMAGE": "{{ DOCKER_REGISTRY }}overhangio/openedx-android:{{ ANDROID_VERSION }}", - "APP_DOCKER_IMAGE": "{{ DOCKER_REGISTRY }}overhangio/openedx-android-app:{{ ANDROID_VERSION }}", + "DOCKER_IMAGE": "{{ DOCKER_REGISTRY }}overhangio/openedx-android:{{ ANDROID_VERSION }}", # noqa: E501 + "APP_DOCKER_IMAGE": "{{ DOCKER_REGISTRY }}overhangio/openedx-android-app:{{ ANDROID_VERSION }}", # noqa: E501 "ENABLE_RELEASE_MODE": False, "RELEASE_STORE_PASSWORD": "android store password", "RELEASE_KEY_PASSWORD": "android release key password", From 8b682f09022c88a7dfe7f850e6a8d554636ea685 Mon Sep 17 00:00:00 2001 From: Abdul-Muqadim-Arbisoft Date: Sun, 7 Sep 2025 19:50:54 +0500 Subject: [PATCH 2/2] fix: add one line where file ends according to pep8 principle missed one line empty priciple at end of file, add that in this commit --- pyproject.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyproject.toml b/pyproject.toml index 8eb8782..374a994 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -80,4 +80,4 @@ select = ["E", "I", "N"] # W292: missing-newline-at-end-of-file extend-select = ["F401", "F841", "W292"] -[tool.ruff.format] \ No newline at end of file +[tool.ruff.format]