feat: migrate from pylint/black to ruff (#57)

* feat: migrate from pylint/black to ruff

* test: verify python package distribution build when running make test
This commit is contained in:
Muhammad Labeeb 2025-08-28 19:00:22 +05:00 committed by GitHub
parent bc96768c69
commit 95fe3e3cc3
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
5 changed files with 38 additions and 14 deletions

View File

@ -18,5 +18,5 @@ def load_about() -> dict[str, str]:
with open( with open(
os.path.join(HERE, "tutorcredentials", "__about__.py"), "rt", encoding="utf-8" os.path.join(HERE, "tutorcredentials", "__about__.py"), "rt", encoding="utf-8"
) as f: ) as f:
exec(f.read(), about) # pylint: disable=exec-used exec(f.read(), about)
return about return about

View File

@ -1,25 +1,30 @@
.DEFAULT_GOAL := help .DEFAULT_GOAL := help
.PHONY: docs .PHONY: docs
SRC_DIRS = ./tutorcredentials SRC_DIRS = ./tutorcredentials
BLACK_OPTS = --exclude templates ${SRC_DIRS}
# Warning: These checks are run on every PR. # Warning: These checks are 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. test-format: ## Run code formatting tests.
black --check --diff $(BLACK_OPTS) ruff format --check --diff ${SRC_DIRS}
test-lint: ## Run code linting tests 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. test-types: ## Run type checks.
mypy --exclude=templates --ignore-missing-imports --implicit-reexport --strict ${SRC_DIRS} mypy --exclude=templates --ignore-missing-imports --implicit-reexport --strict ${SRC_DIRS}
format: ## Format code automatically. build-pythonpackage: ## Build the "tutor-credentials" python package for upload to pypi
black $(BLACK_OPTS) 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. test-pythonpackage: build-pythonpackage ## Test that package can be uploaded to pypi
isort --skip=templates ${SRC_DIRS} twine check dist/tutor_credentials-$(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. changelog-entry: ## Create a new changelog entry.
scriv create scriv create
@ -27,6 +32,9 @@ changelog-entry: ## Create a new changelog entry.
changelog: ## Collect changelog entries in the CHANGELOG.md file. changelog: ## Collect changelog entries in the CHANGELOG.md file.
scriv collect scriv collect
version: ## Print the current tutor-credentials version
@python -c 'import io, os; about = {}; exec(io.open(os.path.join("tutorcredentials", "__about__.py"), "rt", encoding="utf-8").read(), about); print(about["__version__"])'
ESCAPE =  ESCAPE = 
help: ## Print this help. help: ## Print this help.
@grep -E '^([a-zA-Z_-]+:.*?## .*|######* .+)$$' Makefile \ @grep -E '^([a-zA-Z_-]+:.*?## .*|######* .+)$$' Makefile \

View File

@ -0,0 +1,2 @@
- [Improvement] Migrate from pylint and black to ruff. (by @mlabeeb03)
- [Improvement] Test python package distribution build when running make test. (by @mlabeeb03)

View File

@ -37,8 +37,7 @@ dynamic = ["version"]
[project.optional-dependencies] [project.optional-dependencies]
dev = [ dev = [
"tutor[dev]>=20.0.0,<21.0.0", "tutor[dev]>=20.0.0,<21.0.0",
"pylint", "ruff",
"black"
] ]
[project.entry-points."tutor.plugin.v1"] [project.entry-points."tutor.plugin.v1"]
@ -69,3 +68,19 @@ exclude = ["tests*"]
[tool.hatch.build.targets.wheel] [tool.hatch.build.targets.wheel]
packages = ["tutorcredentials"] packages = ["tutorcredentials"]
[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]

View File

@ -5,10 +5,9 @@ import typing as t
from glob import glob from glob import glob
import importlib_resources import importlib_resources
from tutormfe.hooks import MFE_APPS, MFE_ATTRS_TYPE
from tutor import hooks as tutor_hooks from tutor import hooks as tutor_hooks
from tutor.__about__ import __version_suffix__ from tutor.__about__ import __version_suffix__
from tutormfe.hooks import MFE_APPS, MFE_ATTRS_TYPE
from .__about__ import __version__ from .__about__ import __version__
@ -25,7 +24,7 @@ config: t.Dict[str, t.Dict[str, t.Any]] = {
"defaults": { "defaults": {
"VERSION": __version__, "VERSION": __version__,
"BACKEND_SERVICE_EDX_OAUTH2_KEY": "{{ CREDENTIALS_OAUTH2_KEY }}", "BACKEND_SERVICE_EDX_OAUTH2_KEY": "{{ CREDENTIALS_OAUTH2_KEY }}",
"DOCKER_IMAGE": "{{ DOCKER_REGISTRY }}overhangio/openedx-credentials:{{ CREDENTIALS_VERSION }}", "DOCKER_IMAGE": "{{ DOCKER_REGISTRY }}overhangio/openedx-credentials:{{ CREDENTIALS_VERSION }}", # noqa: E501
"EXTRA_PIP_REQUIREMENTS": [], "EXTRA_PIP_REQUIREMENTS": [],
"HOST": "credentials.{{ LMS_HOST }}", "HOST": "credentials.{{ LMS_HOST }}",
"MYSQL_DATABASE": "credentials", "MYSQL_DATABASE": "credentials",