feat: migrate to ruff for linting and formatting checks (#50)
This commit is contained in:
parent
4fde7e355b
commit
ae4e3f20ac
@ -17,5 +17,5 @@ class MetaDataHook(MetadataHookInterface):
|
|||||||
def load_about() -> dict[str, str]:
|
def load_about() -> dict[str, str]:
|
||||||
about: dict[str, str] = {}
|
about: dict[str, str] = {}
|
||||||
with open(os.path.join(HERE, "tutornotes", "__about__.py"), "rt", encoding="utf-8") as f:
|
with open(os.path.join(HERE, "tutornotes", "__about__.py"), "rt", encoding="utf-8") as f:
|
||||||
exec(f.read(), about) # pylint: disable=exec-used
|
exec(f.read(), about)
|
||||||
return about
|
return about
|
||||||
|
|||||||
24
Makefile
24
Makefile
@ -1,22 +1,31 @@
|
|||||||
.DEFAULT_GOAL := help
|
.DEFAULT_GOAL := help
|
||||||
.PHONY: docs
|
.PHONY: docs
|
||||||
SRC_DIRS = ./tutornotes
|
SRC_DIRS = ./tutornotes
|
||||||
BLACK_OPTS = --exclude templates ${SRC_DIRS}
|
RUFF_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
|
||||||
|
|
||||||
test-format: ## Run code formatting tests.
|
test-format: ## Run code formatting tests.
|
||||||
black --check --diff $(BLACK_OPTS)
|
ruff format --check --diff $(RUFF_OPTS)
|
||||||
|
|
||||||
test-lint: ## Run code linting tests
|
test-lint:
|
||||||
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}
|
||||||
|
|
||||||
|
build-pythonpackage:
|
||||||
|
python -m build --sdist
|
||||||
|
|
||||||
|
test-pythonpackage: build-pythonpackage
|
||||||
|
twine check dist/tutor_notes-$(shell make version).tar.gz
|
||||||
|
|
||||||
format: ## Format code automatically.
|
format: ## Format code automatically.
|
||||||
black $(BLACK_OPTS)
|
ruff format $(RUFF_OPTS)
|
||||||
|
|
||||||
|
fix-lint: ## Fix linting issues automatically.
|
||||||
|
ruff check --fix $(RUFF_OPTS)
|
||||||
|
|
||||||
isort: ## Sort imports. This target is not mandatory because the output may be incompatible with black formatting. Provided for convenience purposes.
|
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}
|
isort --skip=templates ${SRC_DIRS}
|
||||||
@ -27,6 +36,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-notes version
|
||||||
|
@python -c 'import io, os; about = {}; exec(io.open(os.path.join("tutornotes", "__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 \
|
||||||
|
|||||||
@ -0,0 +1,2 @@
|
|||||||
|
- [Improvement] Migrate from pylint and black to ruff. (by @dawoudsheraz)
|
||||||
|
- [Improvement] Test python package distribution build when running make-test. (by @dawoudsheraz)
|
||||||
@ -36,8 +36,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",
|
||||||
"black",
|
"ruff"
|
||||||
"pylint"
|
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|
||||||
@ -69,3 +68,20 @@ exclude = ["tests*"]
|
|||||||
|
|
||||||
[project.entry-points."tutor.plugin.v1"]
|
[project.entry-points."tutor.plugin.v1"]
|
||||||
notes = "tutornotes.plugin"
|
notes = "tutornotes.plugin"
|
||||||
|
|
||||||
|
[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]
|
||||||
|
# Default config is automatically taken from https://docs.astral.sh/ruff/configuration/
|
||||||
|
|||||||
@ -17,7 +17,7 @@ if __version_suffix__:
|
|||||||
config = {
|
config = {
|
||||||
"defaults": {
|
"defaults": {
|
||||||
"VERSION": __version__,
|
"VERSION": __version__,
|
||||||
"DOCKER_IMAGE": "{{ DOCKER_REGISTRY }}overhangio/openedx-notes:{{ NOTES_VERSION }}",
|
"DOCKER_IMAGE": "{{ DOCKER_REGISTRY }}overhangio/openedx-notes:{{ NOTES_VERSION }}", # noqa: E501
|
||||||
"HOST": "notes.{{ LMS_HOST }}",
|
"HOST": "notes.{{ LMS_HOST }}",
|
||||||
"MYSQL_DATABASE": "notes",
|
"MYSQL_DATABASE": "notes",
|
||||||
"MYSQL_USERNAME": "notes",
|
"MYSQL_USERNAME": "notes",
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user