From f217ce700f2c97b4d98a033ee107118ec7906fbc Mon Sep 17 00:00:00 2001 From: Emad Rad Date: Sat, 18 Nov 2023 18:15:12 +0330 Subject: [PATCH 1/6] feat: Makefile added --- Makefile | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 Makefile diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..900866e --- /dev/null +++ b/Makefile @@ -0,0 +1,34 @@ +.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 # Run some static checks. + +test-format: ## Run code formatting tests + black --check --diff $(BLACK_OPTS) + +test-lint: ## Run code linting tests + pylint --errors-only --enable=unused-import,unused-argument --ignore=templates --ignore=docs/_ext ${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) + +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} + +changelog-entry: ## Create a new changelog entry. + scriv create + +changelog: ## Collect changelog entries in the CHANGELOG.md file. + scriv collect + +ESCAPE =  +help: ## Print this help + @grep -E '^([a-zA-Z_-]+:.*?## .*|######* .+)$$' Makefile \ + | sed 's/######* \(.*\)/@ $(ESCAPE)[1;31m\1$(ESCAPE)[0m/g' | tr '@' '\n' \ + | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[33m%-30s\033[0m %s\n", $$1, $$2}' From 84922b944cb6cd9b5cbe7e2a1f7075875072b58b Mon Sep 17 00:00:00 2001 From: Emad Rad Date: Sat, 18 Nov 2023 18:15:15 +0330 Subject: [PATCH 2/6] ci: test action added --- .github/workflows/test.yml | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 .github/workflows/test.yml diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml new file mode 100644 index 0000000..2ff802d --- /dev/null +++ b/.github/workflows/test.yml @@ -0,0 +1,22 @@ +name: Run tests + +on: + pull_request: + branches: [master] + +jobs: + tests: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + - name: Set up Python 3.8 + uses: actions/setup-python@v2 + with: + python-version: 3.8 + - name: Upgrade pip + run: python -m pip install --upgrade pip setuptools + - name: Install dependencies + run: | + pip install 'tutor[dev]>=16.0.0,<17.0.0' + - name: Test lint, types, and format + run: make test From d5e3229e60fdb99b96d0fbfb6fcdb7cec6154881 Mon Sep 17 00:00:00 2001 From: Emad Rad Date: Sat, 18 Nov 2023 18:16:04 +0330 Subject: [PATCH 3/6] chore: changelog entry added --- changelog.d/20231118_181548_codewithemad_test_lint.md | 1 + 1 file changed, 1 insertion(+) create mode 100644 changelog.d/20231118_181548_codewithemad_test_lint.md diff --git a/changelog.d/20231118_181548_codewithemad_test_lint.md b/changelog.d/20231118_181548_codewithemad_test_lint.md new file mode 100644 index 0000000..952a383 --- /dev/null +++ b/changelog.d/20231118_181548_codewithemad_test_lint.md @@ -0,0 +1 @@ +- [Improvement] Added Typing to code, Makefile and test action to the repository and formatted code with Black and isort. (by @CodeWithEmad) \ No newline at end of file From 267c3533674792ed7da3f0cfd48c87f1fa8bc25e Mon Sep 17 00:00:00 2001 From: Emad Rad Date: Sat, 18 Nov 2023 18:23:46 +0330 Subject: [PATCH 4/6] fix: all configs moved to 1 place --- tutorcairn/plugin.py | 80 +++++++++++++++++++++++--------------------- 1 file changed, 41 insertions(+), 39 deletions(-) diff --git a/tutorcairn/plugin.py b/tutorcairn/plugin.py index 75a6291..9b4a313 100644 --- a/tutorcairn/plugin.py +++ b/tutorcairn/plugin.py @@ -18,51 +18,53 @@ if __version_suffix__: HERE = os.path.abspath(os.path.dirname(__file__)) - -hooks.Filters.CONFIG_UNIQUE.add_items( - [ - ("CAIRN_CLICKHOUSE_PASSWORD", "{{ 20|random_string }}"), - ("CAIRN_POSTGRESQL_PASSWORD", "{{ 20|random_string }}"), - ("CAIRN_SUPERSET_SECRET_KEY", "{{ 20|random_string }}"), - ("CAIRN_SSO_CLIENT_SECRET", "{{ 20|random_string }}"), - ] -) -hooks.Filters.CONFIG_DEFAULTS.add_items( - [ - ("CAIRN_VERSION", __version__), - ("CAIRN_DOCKER_HOST_SOCK_PATH", "/var/run/docker.sock"), - ("CAIRN_HOST", "data.{{ LMS_HOST }}"), +config: t.Dict[str, t.Dict[str, t.Any]] = { + "defaults": { + "VERSION": __version__, + "DOCKER_HOST_SOCK_PATH": "/var/run/docker.sock", + "HOST": "data.{{ LMS_HOST }}", # Clickhouse - ("CAIRN_RUN_CLICKHOUSE", True), - ( - "CAIRN_CLICKHOUSE_DOCKER_IMAGE", - "{{ DOCKER_REGISTRY }}overhangio/cairn-clickhouse:{{ CAIRN_VERSION }}", - ), - ("CAIRN_CLICKHOUSE_HOST", "cairn-clickhouse"), - ("CAIRN_CLICKHOUSE_HTTP_PORT", 8123), - ("CAIRN_CLICKHOUSE_HTTP_SCHEME", "http"), - ("CAIRN_CLICKHOUSE_PORT", 9000), - ("CAIRN_CLICKHOUSE_DATABASE", "openedx"), - ("CAIRN_CLICKHOUSE_USERNAME", "openedx"), + "RUN_CLICKHOUSE": True, + "CLICKHOUSE_DOCKER_IMAGE": "{{ DOCKER_REGISTRY }}overhangio/cairn-clickhouse:{{ CAIRN_VERSION }}", + "CLICKHOUSE_HOST": "cairn-clickhouse", + "CLICKHOUSE_HTTP_PORT": 8123, + "CLICKHOUSE_HTTP_SCHEME": "http", + "CLICKHOUSE_PORT": 9000, + "CLICKHOUSE_DATABASE": "openedx", + "CLICKHOUSE_USERNAME": "openedx", # Superset/Postgresql - ("CAIRN_RUN_POSTGRESQL", True), - ("CAIRN_POSTGRESQL_DATABASE", "superset"), - ("CAIRN_POSTGRESQL_USERNAME", "superset"), - ( - "CAIRN_SUPERSET_DOCKER_IMAGE", - "{{ DOCKER_REGISTRY }}overhangio/cairn-superset:{{ CAIRN_VERSION }}", - ), - ("CAIRN_SUPERSET_LANGUAGE_CODE", "{{ LANGUAGE_CODE[:2] }}"), + "RUN_POSTGRESQL": True, + "POSTGRESQL_DATABASE": "superset", + "POSTGRESQL_USERNAME": "superset", + "SUPERSET_DOCKER_IMAGE": "{: DOCKER_REGISTRY }}overhangio/cairn-superset:{{ CAIRN_VERSION }}", + "SUPERSET_LANGUAGE_CODE": "{{ LANGUAGE_CODE[:2] }}", # SSO - ("CAIRN_ENABLE_SSO", True), - ("CAIRN_SSO_CLIENT_ID", "cairn"), + "ENABLE_SSO": True, + "SSO_CLIENT_ID": "cairn", # Vector # https://hub.docker.com/r/timberio/vector/tags # https://github.com/vectordotdev/vector/releases - ("CAIRN_VECTOR_DOCKER_IMAGE", "docker.io/timberio/vector:0.25.1-alpine"), - #Auto sync user roles - ("CAIRN_AUTH_ROLES_SYNC_AT_LOGIN", False), - ] + "VECTOR_DOCKER_IMAGE": "docker.io/timberio/vector:0.25.1-alpine", + # Auto sync user roles + "AUTH_ROLES_SYNC_AT_LOGIN": False, + }, + "unique": { + "CLICKHOUSE_PASSWORD": "{{ 20|random_string }}", + "POSTGRESQL_PASSWORD": "{{ 20|random_string }}", + "SUPERSET_SECRET_KEY": "{{ 20|random_string }}", + "SSO_CLIENT_SECRET": "{{ 20|random_string }}", + }, +} + +# Add configuration entries +hooks.Filters.CONFIG_DEFAULTS.add_items( + [(f"CAIRN_{key}", value) for key, value in config.get("defaults", {}).items()] +) +hooks.Filters.CONFIG_UNIQUE.add_items( + [(f"CAIRN_{key}", value) for key, value in config.get("unique", {}).items()] +) +hooks.Filters.CONFIG_OVERRIDES.add_items( + list(config.get("overrides", {}).items()) ) # Init scripts From 3e68e6f8cbd22e6a6891d46553a25aae4835cc44 Mon Sep 17 00:00:00 2001 From: Emad Rad Date: Sat, 18 Nov 2023 18:24:17 +0330 Subject: [PATCH 5/6] chore: cleanup with black and isort --- tutorcairn/__about__.py | 1 - tutorcairn/plugin.py | 15 +++++++++++---- 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/tutorcairn/__about__.py b/tutorcairn/__about__.py index 3e6531e..c7d74af 100644 --- a/tutorcairn/__about__.py +++ b/tutorcairn/__about__.py @@ -1,2 +1 @@ __version__ = "16.0.3" - diff --git a/tutorcairn/plugin.py b/tutorcairn/plugin.py index 9b4a313..d1b3980 100644 --- a/tutorcairn/plugin.py +++ b/tutorcairn/plugin.py @@ -1,12 +1,12 @@ from __future__ import annotations -from glob import glob + import os import shlex import typing as t +from glob import glob import click import pkg_resources - from tutor import hooks from tutor.__about__ import __version_suffix__ @@ -120,7 +120,9 @@ hooks.Filters.IMAGES_PUSH.add_items( @hooks.Filters.APP_PUBLIC_HOSTS.add() -def _print_superset_host(hosts: list[str], context_name: t.Literal["local", "dev"]): +def _print_superset_host( + hosts: list[str], context_name: t.Literal["local", "dev"] +) -> list[str]: if context_name == "dev": hosts.append("{{ CAIRN_HOST }}:2247") else: @@ -154,7 +156,12 @@ def _print_superset_host(hosts: list[str], context_name: t.Literal["local", "dev @click.argument("username") @click.argument("email") def create_user_command( - bootstrap_dashboards: bool, admin: bool, password: str, course_ids: list[str], username: str, email: str + bootstrap_dashboards: bool, + admin: bool, + password: str, + course_ids: list[str], + username: str, + email: str, ) -> t.Iterable[tuple[str, str]]: admin_opt = " --admin" if admin else "" From db88bdec10494faafb0905645ffa63f8fabab2b6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9gis=20Behmo?= Date: Mon, 27 Nov 2023 08:39:51 +0100 Subject: [PATCH 6/6] fix: `DOCKER_IMAGE` typo that was breaking env --- tutorcairn/plugin.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tutorcairn/plugin.py b/tutorcairn/plugin.py index d1b3980..e54e704 100644 --- a/tutorcairn/plugin.py +++ b/tutorcairn/plugin.py @@ -36,7 +36,7 @@ config: t.Dict[str, t.Dict[str, t.Any]] = { "RUN_POSTGRESQL": True, "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 }}", "SUPERSET_LANGUAGE_CODE": "{{ LANGUAGE_CODE[:2] }}", # SSO "ENABLE_SSO": True,