From 47c90a84097e371d718b58d87da2a8614ca25344 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9gis=20Behmo?= Date: Tue, 10 May 2022 12:18:20 +0200 Subject: [PATCH] feat: upgrade to nutmeg --- .gitlab-ci.yml | 2 +- README.rst | 4 +- setup.py | 7 +- tutornotes/__about__.py | 2 +- tutornotes/patches/common-env-features | 1 - tutornotes/patches/openedx-common-settings | 2 + tutornotes/plugin.py | 83 +++++++++++++++---- .../templates/notes/build/notes/Dockerfile | 5 +- .../templates/notes/{hooks => tasks}/lms/init | 0 .../notes/{hooks => tasks}/mysql/init | 0 .../notes/{hooks => tasks}/notes/init | 0 11 files changed, 79 insertions(+), 27 deletions(-) delete mode 100644 tutornotes/patches/common-env-features create mode 100644 tutornotes/patches/openedx-common-settings rename tutornotes/templates/notes/{hooks => tasks}/lms/init (100%) rename tutornotes/templates/notes/{hooks => tasks}/mysql/init (100%) rename tutornotes/templates/notes/{hooks => tasks}/notes/init (100%) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index c3d8f1d..c125e87 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -2,7 +2,7 @@ variables: TUTOR_PLUGIN: notes TUTOR_IMAGES: notes TUTOR_PYPI_PACKAGE: tutor-notes - OPENEDX_RELEASE: maple + OPENEDX_RELEASE: nutmeg GITHUB_REPO: overhangio/tutor-notes include: diff --git a/README.rst b/README.rst index 061014d..2406ec4 100644 --- a/README.rst +++ b/README.rst @@ -1,9 +1,9 @@ Students notes plugin for `Tutor `_ =================================================================== -This is a plugin for `Tutor `_ to easily add the `Open edX note-taking app `_ to an Open edX platform. This app allows students to annotate portions of the courseware (see `the official documentation `_). +This is a plugin for `Tutor `_ to easily add the `Open edX note-taking app `_ to an Open edX platform. This app allows students to annotate portions of the courseware (see `the official documentation `_). -.. image:: https://edx.readthedocs.io/projects/open-edx-building-and-running-a-course/en/open-release-maple.master/_images/SFD_SN_bodyexample.png +.. image:: https://edx.readthedocs.io/projects/open-edx-building-and-running-a-course/en/open-release-nutmeg.master/_images/SFD_SN_bodyexample.png :alt: Notes in action Installation diff --git a/setup.py b/setup.py index 44ec68f..da30c74 100644 --- a/setup.py +++ b/setup.py @@ -30,16 +30,15 @@ setup( long_description=readme, packages=find_packages(exclude=["tests*"]), include_package_data=True, - python_requires=">=3.5", - install_requires=["tutor>=13.0.0,<14.0.0"], - entry_points={"tutor.plugin.v0": ["notes = tutornotes.plugin"]}, + python_requires=">=3.7", + install_requires=["tutor>=14.0.0,<15.0.0"], + entry_points={"tutor.plugin.v1": ["notes = tutornotes.plugin"]}, classifiers=[ "Development Status :: 5 - Production/Stable", "Intended Audience :: Developers", "License :: OSI Approved :: GNU Affero General Public License v3", "Operating System :: OS Independent", "Programming Language :: Python", - "Programming Language :: Python :: 3.6", "Programming Language :: Python :: 3.7", "Programming Language :: Python :: 3.8", "Programming Language :: Python :: 3.9", diff --git a/tutornotes/__about__.py b/tutornotes/__about__.py index cb28663..2294691 100644 --- a/tutornotes/__about__.py +++ b/tutornotes/__about__.py @@ -1 +1 @@ -__version__ = "13.0.1" +__version__ = "14.0.0" diff --git a/tutornotes/patches/common-env-features b/tutornotes/patches/common-env-features deleted file mode 100644 index 57f16c4..0000000 --- a/tutornotes/patches/common-env-features +++ /dev/null @@ -1 +0,0 @@ -"ENABLE_EDXNOTES": true diff --git a/tutornotes/patches/openedx-common-settings b/tutornotes/patches/openedx-common-settings new file mode 100644 index 0000000..417ce24 --- /dev/null +++ b/tutornotes/patches/openedx-common-settings @@ -0,0 +1,2 @@ +# Student notes +FEATURES["ENABLE_EDXNOTES"] = True diff --git a/tutornotes/plugin.py b/tutornotes/plugin.py index 8d27e3c..bd3a8bf 100644 --- a/tutornotes/plugin.py +++ b/tutornotes/plugin.py @@ -3,11 +3,13 @@ import os import pkg_resources +from tutor import hooks as tutor_hooks + from .__about__ import __version__ config = { - "add": { + "unique": { "MYSQL_PASSWORD": "{{ 8|random_string }}", "SECRET_KEY": "{{ 24|random_string }}", "OAUTH2_SECRET": "{{ 24|random_string }}", @@ -21,21 +23,68 @@ config = { }, } -templates = pkg_resources.resource_filename("tutornotes", "templates") -hooks = { - "init": ["mysql", "lms", "notes"], - "build-image": {"notes": "{{ NOTES_DOCKER_IMAGE }}"}, - "remote-image": {"notes": "{{ NOTES_DOCKER_IMAGE }}"}, -} +# Initialization hooks +tutor_hooks.Filters.COMMANDS_INIT.add_item(( + "mysql", + ("notes", "tasks", "mysql", "init"), +)) +tutor_hooks.Filters.COMMANDS_INIT.add_item(( + "lms", + ("notes", "tasks", "lms", "init"), +)) +tutor_hooks.Filters.COMMANDS_INIT.add_item(( + "notes", + ("notes", "tasks", "notes", "init"), +)) +# Image management +tutor_hooks.Filters.IMAGES_BUILD.add_item(( + "notes", + ("plugins", "notes", "build", "notes"), + "{{ NOTES_DOCKER_IMAGE }}", + (), +)) +tutor_hooks.Filters.IMAGES_PULL.add_item(( + "notes", + "{{ NOTES_DOCKER_IMAGE }}", +)) +tutor_hooks.Filters.IMAGES_PUSH.add_item(( + "notes", + "{{ NOTES_DOCKER_IMAGE }}", +)) -def patches(): - all_patches = {} - for path in glob( - os.path.join(pkg_resources.resource_filename("tutornotes", "patches"), "*") - ): - with open(path) as patch_file: - name = os.path.basename(path) - content = patch_file.read() - all_patches[name] = content - return all_patches +####### Boilerplate code +# Add the "templates" folder as a template root +tutor_hooks.Filters.ENV_TEMPLATE_ROOTS.add_item( + pkg_resources.resource_filename("tutornotes", "templates") +) +# Render the "build" and "apps" folders +tutor_hooks.Filters.ENV_TEMPLATE_TARGETS.add_items( + [ + ("notes/build", "plugins"), + ("notes/apps", "plugins"), + ], +) +# Load patches from files +for path in glob( + os.path.join( + pkg_resources.resource_filename("tutornotes", "patches"), + "*", + ) +): + with open(path, encoding="utf-8") as patch_file: + tutor_hooks.Filters.ENV_PATCHES.add_item((os.path.basename(path), patch_file.read())) +# Add configuration entries +tutor_hooks.Filters.CONFIG_DEFAULTS.add_items( + [ + (f"NOTES_{key}", value) + for key, value in config.get("defaults", {}).items() + ] +) +tutor_hooks.Filters.CONFIG_UNIQUE.add_items( + [ + (f"NOTES_{key}", value) + for key, value in config.get("unique", {}).items() + ] +) +tutor_hooks.Filters.CONFIG_OVERRIDES.add_items(list(config.get("overrides", {}).items())) diff --git a/tutornotes/templates/notes/build/notes/Dockerfile b/tutornotes/templates/notes/build/notes/Dockerfile index 662a055..a1a8681 100644 --- a/tutornotes/templates/notes/build/notes/Dockerfile +++ b/tutornotes/templates/notes/build/notes/Dockerfile @@ -16,7 +16,10 @@ WORKDIR /app/edx-notes-api RUN python -m venv /app/venv ENV PATH /app/venv/bin:${PATH} -RUN pip install setuptools==44.1.0 pip==20.3.4 wheel==0.37.0 +# https://pypi.org/project/setuptools/ +# https://pypi.org/project/pip/ +# https://pypi.org/project/wheel/ +RUN pip install setuptools==62.1.0 pip==22.0.4 wheel==0.37.1 RUN pip3 install -r requirements/base.txt EXPOSE 8000 diff --git a/tutornotes/templates/notes/hooks/lms/init b/tutornotes/templates/notes/tasks/lms/init similarity index 100% rename from tutornotes/templates/notes/hooks/lms/init rename to tutornotes/templates/notes/tasks/lms/init diff --git a/tutornotes/templates/notes/hooks/mysql/init b/tutornotes/templates/notes/tasks/mysql/init similarity index 100% rename from tutornotes/templates/notes/hooks/mysql/init rename to tutornotes/templates/notes/tasks/mysql/init diff --git a/tutornotes/templates/notes/hooks/notes/init b/tutornotes/templates/notes/tasks/notes/init similarity index 100% rename from tutornotes/templates/notes/hooks/notes/init rename to tutornotes/templates/notes/tasks/notes/init