From 5d6580c82bb43c6f0ca90e5fd7c32752472eeefb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9gis=20Behmo?= Date: Fri, 26 May 2023 18:26:28 +0200 Subject: [PATCH 1/7] feat: label nightly version This is to address https://github.com/overhangio/tutor-mfe/issues/122 As a consequence of this change, images will be tagged with a "-nightly" suffix. Next, we'll probably have to build them periodically in CI. --- tutornotes/__about__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tutornotes/__about__.py b/tutornotes/__about__.py index 8665bae..a5ab4a5 100644 --- a/tutornotes/__about__.py +++ b/tutornotes/__about__.py @@ -1,7 +1,7 @@ __version__ = "15.0.4" # Handle version suffix for nightly, just like tutor core. -__version_suffix__ = "" +__version_suffix__ = "nightly" if __version_suffix__: __version__ += "-" + __version_suffix__ From a7ad3758b50e00e7af83956b08004d3183cd8ac4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9gis=20Behmo?= Date: Fri, 26 May 2023 18:47:48 +0200 Subject: [PATCH 2/7] fix: nightly package version The package version number may not include the "-nightly" suffix. Otherwise, installation fails with: setuptools.extern.packaging.version.InvalidVersion: Invalid version: '15.0.7-nightly' --- setup.py | 2 +- tutornotes/__about__.py | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/setup.py b/setup.py index 3d4352c..30d542f 100644 --- a/setup.py +++ b/setup.py @@ -15,7 +15,7 @@ setup( name="tutor-notes", - version=about["__version__"], + version=about["__package_version__"], url="https://docs.tutor.overhang.io/", project_urls={ "Documentation": "https://docs.tutor.overhang.io/", diff --git a/tutornotes/__about__.py b/tutornotes/__about__.py index a5ab4a5..57d2630 100644 --- a/tutornotes/__about__.py +++ b/tutornotes/__about__.py @@ -1,4 +1,5 @@ __version__ = "15.0.4" +__package_version__ = __version__ # Handle version suffix for nightly, just like tutor core. __version_suffix__ = "nightly" From cb08b6321793ced90996f75071ba3baa9012938e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9gis=20Behmo?= Date: Tue, 21 Nov 2023 12:40:11 +0100 Subject: [PATCH 3/7] fix: add missing pkg-config package (#30) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Build fails in nightly with the following error: #27 4.029 × Getting requirements to build wheel did not run successfully. #27 4.029 │ exit code: 1 #27 4.029 ╰─> [24 lines of output] #27 4.029 /bin/sh: 1: pkg-config: not found #27 4.029 /bin/sh: 1: pkg-config: not found #27 4.029 Trying pkg-config --exists mysqlclient #27 4.029 Command 'pkg-config --exists mysqlclient' returned non-zero exit status 127. #27 4.029 Trying pkg-config --exists mariadb #27 4.029 Command 'pkg-config --exists mariadb' returned non-zero exit status 127. #27 4.029 Traceback (most recent call last): #27 4.029 File "/app/venv/lib/python3.8/site-packages/pip/_vendor/pyproject_hooks/_in_process/_in_process.py", line 353, in #27 4.029 main() #27 4.029 File "/app/venv/lib/python3.8/site-packages/pip/_vendor/pyproject_hooks/_in_process/_in_process.py", line 335, in main #27 4.029 json_out['return_val'] = hook(**hook_input['kwargs']) #27 4.029 File "/app/venv/lib/python3.8/site-packages/pip/_vendor/pyproject_hooks/_in_process/_in_process.py", line 118, in get_requires_for_build_wheel #27 4.029 return hook(config_settings) #27 4.029 File "/tmp/pip-build-env-td0z_pds/overlay/lib/python3.8/site-packages/setuptools/build_meta.py", line 355, in get_requires_for_build_wheel #27 4.029 return self._get_build_requires(config_settings, requirements=['wheel']) #27 4.029 File "/tmp/pip-build-env-td0z_pds/overlay/lib/python3.8/site-packages/setuptools/build_meta.py", line 325, in _get_build_requires #27 4.029 self.run_setup() #27 4.029 File "/tmp/pip-build-env-td0z_pds/overlay/lib/python3.8/site-packages/setuptools/build_meta.py", line 341, in run_setup #27 4.029 exec(code, locals()) #27 4.029 File "", line 154, in #27 4.029 File "", line 48, in get_config_posix #27 4.029 File "", line 27, in find_package_name #27 4.029 Exception: Can not find valid pkg-config name. #27 4.029 Specify MYSQLCLIENT_CFLAGS and MYSQLCLIENT_LDFLAGS env vars manually --- tutornotes/templates/notes/build/notes/Dockerfile | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/tutornotes/templates/notes/build/notes/Dockerfile b/tutornotes/templates/notes/build/notes/Dockerfile index b26c2f7..68c95f9 100644 --- a/tutornotes/templates/notes/build/notes/Dockerfile +++ b/tutornotes/templates/notes/build/notes/Dockerfile @@ -1,12 +1,19 @@ {% if is_buildkit_enabled() %}# syntax=docker/dockerfile:1.4{% endif %} FROM docker.io/ubuntu:20.04 +ENV DEBIAN_FRONTEND=noninteractive RUN {% if is_buildkit_enabled() %}--mount=type=cache,target=/var/cache/apt,sharing=locked \ --mount=type=cache,target=/var/lib/apt,sharing=locked{% endif %} \ apt update && \ apt upgrade -y && \ - # python 3.8 - apt install -y language-pack-en git python3 python3-pip python3-venv libmysqlclient-dev + apt install -y \ + language-pack-en \ + git \ + python3 \ + python3-pip \ + python3-venv \ + libmysqlclient-dev \ + pkg-config RUN ln -s /usr/bin/python3 /usr/bin/python ###### Git-clone Notes repo ###### From f88afe05c3aea60c353e9a7d9363aa3141811ea1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9gis=20Behmo?= Date: Mon, 20 Nov 2023 17:39:47 +0100 Subject: [PATCH 4/7] feat: simplify nightly version management By pulling the version suffix from tutor, we avoid git conflicts when merging the release branch in nightly. --- setup.py | 2 +- tutornotes/__about__.py | 6 ------ tutornotes/plugin.py | 5 +++++ 3 files changed, 6 insertions(+), 7 deletions(-) diff --git a/setup.py b/setup.py index 41e7e69..0316dda 100644 --- a/setup.py +++ b/setup.py @@ -15,7 +15,7 @@ setup( name="tutor-notes", - version=about["__package_version__"], + version=about["__version__"], url="https://docs.tutor.overhang.io/", project_urls={ "Documentation": "https://docs.tutor.overhang.io/", diff --git a/tutornotes/__about__.py b/tutornotes/__about__.py index fa69782..99e36f2 100644 --- a/tutornotes/__about__.py +++ b/tutornotes/__about__.py @@ -1,8 +1,2 @@ __version__ = "16.0.2" -__package_version__ = __version__ -# Handle version suffix for nightly, just like tutor core. -__version_suffix__ = "nightly" - -if __version_suffix__: - __version__ += "-" + __version_suffix__ diff --git a/tutornotes/plugin.py b/tutornotes/plugin.py index ba4e077..66ea3a2 100644 --- a/tutornotes/plugin.py +++ b/tutornotes/plugin.py @@ -7,9 +7,14 @@ import pkg_resources from tutor import hooks as tutor_hooks +from tutor.__about__ import __version_suffix__ from .__about__ import __version__ +# Handle version suffix in nightly mode, just like tutor core +if __version_suffix__: + __version__ += "-" + __version_suffix__ + config = { "unique": { "MYSQL_PASSWORD": "{{ 8|random_string }}", From 727d500bf52ab39fe5ae0d76d7d23b8183d000b2 Mon Sep 17 00:00:00 2001 From: Emad Rad Date: Fri, 24 Nov 2023 02:35:41 +0330 Subject: [PATCH 5/7] Feat: Testing and Linting (#31) * ci: test action added * chore: changelog entry added * feat: Makefile added * fix: typing added * chore: cleanup with isort and black --- .github/workflows/test.yml | 22 ++++++ Makefile | 34 ++++++++++ changelog.d/20231005_153517_codewithemad.md | 1 + tutornotes/plugin.py | 75 +++++++++++---------- 4 files changed, 95 insertions(+), 37 deletions(-) create mode 100644 .github/workflows/test.yml create mode 100644 Makefile create mode 100644 changelog.d/20231005_153517_codewithemad.md 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 diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..2bc273a --- /dev/null +++ b/Makefile @@ -0,0 +1,34 @@ +.DEFAULT_GOAL := help +.PHONY: docs +SRC_DIRS = ./tutornotes +BLACK_OPTS = --exclude templates ${SRC_DIRS} + +# Warning: These checks are 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}' diff --git a/changelog.d/20231005_153517_codewithemad.md b/changelog.d/20231005_153517_codewithemad.md new file mode 100644 index 0000000..81ca4f1 --- /dev/null +++ b/changelog.d/20231005_153517_codewithemad.md @@ -0,0 +1 @@ +- [Improvement] Added Makefile and test action to repository and formatted code with Black and isort. (by @CodeWithEmad) \ No newline at end of file diff --git a/tutornotes/plugin.py b/tutornotes/plugin.py index 66ea3a2..dd18a50 100644 --- a/tutornotes/plugin.py +++ b/tutornotes/plugin.py @@ -1,11 +1,10 @@ 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__ @@ -16,11 +15,6 @@ __version__ += "-" + __version_suffix__ config = { - "unique": { - "MYSQL_PASSWORD": "{{ 8|random_string }}", - "SECRET_KEY": "{{ 24|random_string }}", - "OAUTH2_SECRET": "{{ 24|random_string }}", - }, "defaults": { "VERSION": __version__, "DOCKER_IMAGE": "{{ DOCKER_REGISTRY }}overhangio/openedx-notes:{{ NOTES_VERSION }}", @@ -30,14 +24,14 @@ "REPOSITORY": "https://github.com/openedx/edx-notes-api", "REPOSITORY_VERSION": "{{ OPENEDX_COMMON_VERSION }}", }, + "unique": { + "MYSQL_PASSWORD": "{{ 8|random_string }}", + "SECRET_KEY": "{{ 24|random_string }}", + "OAUTH2_SECRET": "{{ 24|random_string }}", + }, } # Initialization hooks - -# To add a custom initialization task, create a bash script template under: -# tutorcodejail/templates/codejail/tasks/ -# and then add it to the MY_INIT_TASKS list. Each task is in the format: -# ("", ("", "", "