From a75855d79cf855f2fa61da6a2810df782a5a050a Mon Sep 17 00:00:00 2001 From: Emad Rad Date: Sat, 18 Nov 2023 16:56:09 +0330 Subject: [PATCH 1/7] 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..a4fd9a3 --- /dev/null +++ b/Makefile @@ -0,0 +1,34 @@ +.DEFAULT_GOAL := help +.PHONY: docs +SRC_DIRS = ./tutorminio +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 3b4c36ce012f79ea0ae57d24444576483a42680c Mon Sep 17 00:00:00 2001 From: Emad Rad Date: Sat, 18 Nov 2023 16:56:33 +0330 Subject: [PATCH 2/7] chore: changelog entry added --- changelog.d/20231004_141745_codewithemad.md | 1 + 1 file changed, 1 insertion(+) create mode 100644 changelog.d/20231004_141745_codewithemad.md diff --git a/changelog.d/20231004_141745_codewithemad.md b/changelog.d/20231004_141745_codewithemad.md new file mode 100644 index 0000000..952a383 --- /dev/null +++ b/changelog.d/20231004_141745_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 57db7599051b025a17010d6517bf071eb7c589d6 Mon Sep 17 00:00:00 2001 From: Emad Rad Date: Sat, 18 Nov 2023 16:58:07 +0330 Subject: [PATCH 3/7] 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..829f613 --- /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 .[dev] + - name: Test lint, types, and format + run: make test From ed9b54c3e563958db14e19836f378381b5d5a4aa Mon Sep 17 00:00:00 2001 From: Emad Rad Date: Sat, 18 Nov 2023 16:59:35 +0330 Subject: [PATCH 4/7] chore: sort imports with isort --- tutorminio/plugin.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/tutorminio/plugin.py b/tutorminio/plugin.py index 2f761f7..1311741 100644 --- a/tutorminio/plugin.py +++ b/tutorminio/plugin.py @@ -1,11 +1,10 @@ from __future__ import annotations import os +import typing as t from glob import glob -from typing import Literal import pkg_resources - from tutor import hooks as tutor_hooks from tutor.__about__ import __version_suffix__ From 6c4af5b3afa756586562c5c9085a2292320ce5fc Mon Sep 17 00:00:00 2001 From: Emad Rad Date: Sat, 18 Nov 2023 17:02:02 +0330 Subject: [PATCH 5/7] fix: move all configs to one place --- tutorminio/plugin.py | 50 +++++++++++++++++++++++--------------------- 1 file changed, 26 insertions(+), 24 deletions(-) diff --git a/tutorminio/plugin.py b/tutorminio/plugin.py index 1311741..14a8408 100644 --- a/tutorminio/plugin.py +++ b/tutorminio/plugin.py @@ -16,39 +16,41 @@ HERE = os.path.abspath(os.path.dirname(__file__)) - -tutor_hooks.Filters.CONFIG_DEFAULTS.add_items( - [ - ("MINIO_VERSION", __version__), - ("MINIO_BUCKET_NAME", "openedx"), - ("MINIO_FILE_UPLOAD_BUCKET_NAME", "openedxuploads"), - ("MINIO_VIDEO_UPLOAD_BUCKET_NAME", "openedxvideos"), - ("MINIO_HOST", "files.{{ LMS_HOST }}"), - ("MINIO_CONSOLE_HOST", "minio.{{ LMS_HOST }}"), +config: t.Dict[str, t.Dict[str, t.Any]] = { + "defaults": { + "VERSION": __version__, + "BUCKET_NAME": "openedx", + "FILE_UPLOAD_BUCKET_NAME": "openedxuploads", + "VIDEO_UPLOAD_BUCKET_NAME": "openedxvideos", + "HOST": "files.{{ LMS_HOST }}", + "CONSOLE_HOST": "minio.{{ LMS_HOST }}", # https://hub.docker.com/r/minio/minio/tags # https://hub.docker.com/r/minio/mc/tags # We must stick to these older releases because they are the last ones that support gateway mode to Azure: # https://blog.min.io/deprecation-of-the-minio-gateway/ # https://min.io/docs/minio/linux/operations/install-deploy-manage/migrate-fs-gateway.html - ( - "MINIO_DOCKER_IMAGE", - "docker.io/minio/minio:RELEASE.2022-03-26T06-49-28Z.hotfix.26ec6a857", - ), - ("MINIO_MC_DOCKER_IMAGE", "docker.io/minio/mc:RELEASE.2022-03-31T04-55-30Z"), - ("MINIO_GATEWAY", None), - ] -) + "DOCKER_IMAGE": "docker.io/minio/minio:RELEASE.2022-03-26T06-49-28Z.hotfix.26ec6a857", + "MC_DOCKER_IMAGE": "docker.io/minio/mc:RELEASE.2022-03-31T04-55-30Z", + "GATEWAY": None, + }, + "unique": { + "AWS_SECRET_ACCESS_KEY": "{{ 24|random_string }}", + }, + "overrides": { + "OPENEDX_AWS_ACCESS_KEY": "openedx", + "OPENEDX_AWS_SECRET_ACCESS_KEY": "{{ MINIO_AWS_SECRET_ACCESS_KEY }}", + }, +} +# Add configuration entries +tutor_hooks.Filters.CONFIG_DEFAULTS.add_items( + [(f"MINIO_{key}", value) for key, value in config.get("defaults", {}).items()] +) tutor_hooks.Filters.CONFIG_UNIQUE.add_items( - [ - ("MINIO_AWS_SECRET_ACCESS_KEY", "{{ 24|random_string }}"), - ] + [(f"MINIO_{key}", value) for key, value in config.get("unique", {}).items()] ) tutor_hooks.Filters.CONFIG_OVERRIDES.add_items( - [ - ("OPENEDX_AWS_ACCESS_KEY", "openedx"), - ("OPENEDX_AWS_SECRET_ACCESS_KEY", "{{ MINIO_AWS_SECRET_ACCESS_KEY }}"), - ] + list(config.get("overrides", {}).items()) ) @tutor_hooks.Filters.APP_PUBLIC_HOSTS.add() From c57c260706a5f750bc8fdcf9be8946967668146e Mon Sep 17 00:00:00 2001 From: Emad Rad Date: Sat, 18 Nov 2023 17:06:31 +0330 Subject: [PATCH 6/7] chore: cleanup --- tutorminio/__about__.py | 1 - tutorminio/plugin.py | 9 +++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/tutorminio/__about__.py b/tutorminio/__about__.py index d945113..610c111 100644 --- a/tutorminio/__about__.py +++ b/tutorminio/__about__.py @@ -1,2 +1 @@ __version__ = "16.0.1" - diff --git a/tutorminio/plugin.py b/tutorminio/plugin.py index 14a8408..d8bc7be 100644 --- a/tutorminio/plugin.py +++ b/tutorminio/plugin.py @@ -16,7 +16,7 @@ HERE = os.path.abspath(os.path.dirname(__file__)) -config: t.Dict[str, t.Dict[str, t.Any]] = { +config: dict[str, dict[str, t.Any]] = { "defaults": { "VERSION": __version__, "BUCKET_NAME": "openedx", @@ -53,17 +53,18 @@ list(config.get("overrides", {}).items()) ) + @tutor_hooks.Filters.APP_PUBLIC_HOSTS.add() def add_minio_hosts( - hosts: list[str], context_name: Literal["local", "dev"] - ) -> list[str]: + hosts: list[str], context_name: t.Literal["local", "dev"] +) -> list[str]: if context_name == "dev": hosts.append("{{ MINIO_CONSOLE_HOST }}:9001") else: hosts.append("{{ MINIO_CONSOLE_HOST }}") - return hosts + # Add pre-init script as init task with high priority with open( os.path.join(HERE, "templates", "minio", "tasks", "minio", "init.sh"), From 70eacd693a911e2bffc002258493780e9dfd4104 Mon Sep 17 00:00:00 2001 From: Emad Rad Date: Fri, 8 Dec 2023 14:05:01 +0330 Subject: [PATCH 7/7] feat: Including dev dependencies in extras_require --- setup.py | 1 + 1 file changed, 1 insertion(+) diff --git a/setup.py b/setup.py index 859bbf6..32faade 100644 --- a/setup.py +++ b/setup.py @@ -34,6 +34,7 @@ include_package_data=True, python_requires=">=3.8", install_requires=["tutor>=16.0.0,<17.0.0"], + extras_require={"dev": "tutor[dev]>=16.0.0,<17.0.0"}, entry_points={"tutor.plugin.v1": ["minio = tutorminio.plugin"]}, classifiers=[ "Development Status :: 5 - Production/Stable",