From 98ba2a58e7e843894a08c8970336435051f6f6b2 Mon Sep 17 00:00:00 2001 From: Emad Rad Date: Sat, 18 Nov 2023 18:38:30 +0330 Subject: [PATCH 1/5] 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 0cb623b1c08773cc422a39687b499968355b7583 Mon Sep 17 00:00:00 2001 From: Emad Rad Date: Sat, 18 Nov 2023 18:38:36 +0330 Subject: [PATCH 2/5] 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..a916de8 --- /dev/null +++ b/Makefile @@ -0,0 +1,34 @@ +.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-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 f59425268ae2b061113af007475180aaf3826a84 Mon Sep 17 00:00:00 2001 From: Emad Rad Date: Sat, 18 Nov 2023 18:38:44 +0330 Subject: [PATCH 3/5] chore: changelog entry added --- changelog.d/20231118_183802_codewithemad.md | 1 + 1 file changed, 1 insertion(+) create mode 100644 changelog.d/20231118_183802_codewithemad.md diff --git a/changelog.d/20231118_183802_codewithemad.md b/changelog.d/20231118_183802_codewithemad.md new file mode 100644 index 0000000..952a383 --- /dev/null +++ b/changelog.d/20231118_183802_codewithemad.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 139f241de4370f1add6483b9628dffd3e7de1513 Mon Sep 17 00:00:00 2001 From: Emad Rad Date: Sat, 18 Nov 2023 18:39:54 +0330 Subject: [PATCH 4/5] fix: typing added --- tutorandroid/__about__.py | 1 - tutorandroid/plugin.py | 17 +++++++++++------ 2 files changed, 11 insertions(+), 7 deletions(-) diff --git a/tutorandroid/__about__.py b/tutorandroid/__about__.py index 1722f39..5e5e910 100644 --- a/tutorandroid/__about__.py +++ b/tutorandroid/__about__.py @@ -1,2 +1 @@ __version__ = "16.0.0" - diff --git a/tutorandroid/plugin.py b/tutorandroid/plugin.py index 8d0d92f..6f1fc21 100644 --- a/tutorandroid/plugin.py +++ b/tutorandroid/plugin.py @@ -1,13 +1,13 @@ from __future__ import annotations -from glob import glob import os import typing as t +from glob import glob import pkg_resources - from tutor import hooks as tutor_hooks from tutor.__about__ import __version_suffix__ +from tutor.types import Config, get_typed from .__about__ import __version__ @@ -15,8 +15,8 @@ if __version_suffix__: __version__ += "-" + __version_suffix__ -config = { - "unique": {"OAUTH2_SECRET": "{{ 24|random_string }}"}, + +config: t.Dict[str, t.Dict[str, t.Any]] = { "defaults": { "VERSION": __version__, "APP_HOST": "mobile.{{ LMS_HOST }}", @@ -30,6 +30,9 @@ "RELEASE_KEY_PASSWORD": "android release key password", "RELEASE_KEY_ALIAS": "android release key alias", }, + "unique": { + "OAUTH2_SECRET": "{{ 24|random_string }}", + }, } with open( @@ -68,7 +71,9 @@ @tutor_hooks.Filters.IMAGES_PULL.add() @tutor_hooks.Filters.IMAGES_PUSH.add() -def _add_remote_android_app_image_iff_customized(images, user_config): +def _add_remote_android_app_image_iff_customized( + images: list[tuple[str, str]], user_config: Config +) -> list[tuple[str, str]]: """ Register ANDROID-APP image for pushing & pulling if and only if it has been set to something other than the default. @@ -80,7 +85,7 @@ def _add_remote_android_app_image_iff_customized(images, user_config): to push/pull the ANDROID-APP image if the user has customized it to anything other than the default image URL. """ - image_tag = user_config["ANDROID_APP_DOCKER_IMAGE"] + image_tag = get_typed(user_config, "ANDROID_APP_DOCKER_IMAGE", str, "") if not image_tag.startswith("docker.io/overhangio/openedx-android-app:"): # Image has been customized. Add to list for pulling/pushing. images.append(("android-app", image_tag)) From df108fd4c6c9c50073111cd93259eb79da062e24 Mon Sep 17 00:00:00 2001 From: Emad Rad Date: Sat, 18 Nov 2023 18:40:08 +0330 Subject: [PATCH 5/5] chore: cleanup --- tutorandroid/plugin.py | 1 - 1 file changed, 1 deletion(-) diff --git a/tutorandroid/plugin.py b/tutorandroid/plugin.py index 6f1fc21..02f23fb 100644 --- a/tutorandroid/plugin.py +++ b/tutorandroid/plugin.py @@ -133,7 +133,6 @@ def _print_android_app_public_hosts( return hostnames -####### Boilerplate code # Add the "templates" folder as a template root tutor_hooks.Filters.ENV_TEMPLATE_ROOTS.add_item( pkg_resources.resource_filename("tutorandroid", "templates")