From 8f4a0b1d918c3bf52214a5497ddd531aaf38c8fd Mon Sep 17 00:00:00 2001 From: Danyal Faheem Date: Tue, 5 Aug 2025 15:42:29 +0500 Subject: [PATCH] feat: migrate from pylint/black to ruff (#69) Linked Epic: https://github.com/overhangio/tutor/issues/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 --- .hatch_build.py | 2 +- Makefile | 15 +++++++------ ...50723_121728_danyal.faheem_migrate_ruff.md | 1 + pyproject.toml | 21 ++++++++++++++++--- tutorcairn/plugin.py | 8 +++---- .../cairn/apps/superset/superset_config.py | 2 +- 6 files changed, 32 insertions(+), 17 deletions(-) create mode 100644 changelog.d/20250723_121728_danyal.faheem_migrate_ruff.md diff --git a/.hatch_build.py b/.hatch_build.py index 40edbb7..4b29311 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, "tutorcairn", "__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 20fa3ad..d595937 100644 --- a/Makefile +++ b/Makefile @@ -1,16 +1,15 @@ .DEFAULT_GOAL := help .PHONY: docs SRC_DIRS = ./tutorcairn -BLACK_OPTS = --exclude templates ${SRC_DIRS} # Warning: These checks are not necessarily run on every PR. -test: test-lint test-types test-format test-pythonpackage # Run some static checks. +test: test-lint test-format test-types 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} @@ -21,11 +20,11 @@ build-pythonpackage: ## Build the "tutor-cairn" python package for upload to pyp test-pythonpackage: build-pythonpackage ## Test that package can be uploaded to pypi twine check dist/tutor_cairn-$(shell make version).tar.gz -format: ## Format code automatically - black $(BLACK_OPTS) +format: ## Format code + ruff format ${SRC_DIRS} -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} +fix-lint: ## Fix lint errors automatically + ruff check --fix ${SRC_DIRS} changelog-entry: ## Create a new changelog entry. scriv create diff --git a/changelog.d/20250723_121728_danyal.faheem_migrate_ruff.md b/changelog.d/20250723_121728_danyal.faheem_migrate_ruff.md new file mode 100644 index 0000000..c36cf6d --- /dev/null +++ b/changelog.d/20250723_121728_danyal.faheem_migrate_ruff.md @@ -0,0 +1 @@ +- [Improvement] Migrate from pylint and black to ruff. (by @Danyal-Faheem) \ No newline at end of file diff --git a/pyproject.toml b/pyproject.toml index 636408e..3da2f31 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -32,9 +32,8 @@ dynamic = ["version"] [project.optional-dependencies] dev = [ - "tutor[dev]>=20.0.0,<21.0.0", - "pylint", - "black" + "tutor[dev]>=20.0.0,<21.0.0", + "ruff", ] [project.entry-points."tutor.plugin.v1"] @@ -65,3 +64,19 @@ exclude = ["tests*"] [tool.hatch.build.targets.wheel] packages = ["tutorcairn"] + +[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] diff --git a/tutorcairn/plugin.py b/tutorcairn/plugin.py index ee86673..779f1c6 100644 --- a/tutorcairn/plugin.py +++ b/tutorcairn/plugin.py @@ -25,7 +25,7 @@ config: t.Dict[str, t.Dict[str, t.Any]] = { "HOST": "data.{{ LMS_HOST }}", # Clickhouse "RUN_CLICKHOUSE": True, - "CLICKHOUSE_DOCKER_IMAGE": "{{ DOCKER_REGISTRY }}overhangio/cairn-clickhouse:{{ CAIRN_VERSION }}", + "CLICKHOUSE_DOCKER_IMAGE": "{{ DOCKER_REGISTRY }}overhangio/cairn-clickhouse:{{ CAIRN_VERSION }}", # noqa: E501 "CLICKHOUSE_HOST": "cairn-clickhouse", "CLICKHOUSE_HTTP_PORT": 8123, "CLICKHOUSE_HTTP_SCHEME": "http", @@ -38,7 +38,7 @@ config: t.Dict[str, t.Dict[str, t.Any]] = { "POSTGRESQL_PORT": "5432", "POSTGRESQL_DATABASE": "superset", "POSTGRESQL_USERNAME": "superset", - "SUPERSET_DOCKER_IMAGE": "{{ DOCKER_REGISTRY }}overhangio/cairn-superset:{{ CAIRN_VERSION }}", + "SUPERSET_DOCKER_IMAGE": "{{ DOCKER_REGISTRY }}overhangio/cairn-superset:{{ CAIRN_VERSION }}", # noqa: E501 "SUPERSET_LANGUAGE_CODE": "{{ LANGUAGE_CODE[:2] }}", # SSO "ENABLE_SSO": True, @@ -142,7 +142,7 @@ def _print_superset_host( @click.option( "-p", "--password", - help="Specify password from the command line. If undefined, no password will be set. (Ignored with SSO)", + help="Specify password from the command line. If undefined, no password will be set. (Ignored with SSO)", # noqa: E501 hide_input=True, ) @click.option( @@ -181,7 +181,7 @@ def create_user_command( if bootstrap_dashboards: yield ( "cairn-superset", - f"python ./superset/cairn/ctl.py bootstrap-dashboards {username} /app/bootstrap/courseoverview.json", + f"python ./superset/cairn/ctl.py bootstrap-dashboards {username} /app/bootstrap/courseoverview.json", # noqa: E501 ) diff --git a/tutorcairn/templates/cairn/apps/superset/superset_config.py b/tutorcairn/templates/cairn/apps/superset/superset_config.py index cc1061b..3477611 100644 --- a/tutorcairn/templates/cairn/apps/superset/superset_config.py +++ b/tutorcairn/templates/cairn/apps/superset/superset_config.py @@ -126,7 +126,7 @@ AUTH_ROLES_SYNC_AT_LOGIN = {{ CAIRN_AUTH_ROLES_SYNC_AT_LOGIN }} AUTH_USER_REGISTRATION = True {% endif %} -class CeleryConfig: # pylint: disable=too-few-public-methods +class CeleryConfig: BROKER_URL = f"redis://{REDIS_HOST}:{REDIS_PORT}/{REDIS_CELERY_DB}" CELERY_IMPORTS = ("superset.sql_lab", "superset.tasks","superset.tasks.thumbnails",) CELERYD_LOG_LEVEL = "DEBUG"