From c1d6855d2c3e901b2d826fd1ba2c151250fda6f5 Mon Sep 17 00:00:00 2001 From: Kyle McCormick Date: Wed, 18 Dec 2024 10:37:25 -0500 Subject: [PATCH] feat: tutor-contrib-test-legacy-js (#31) --- README.rst | 1 + .../tutor-contrib-test-legacy-js/.gitignore | 7 +++ .../tutor-contrib-test-legacy-js/MANIFEST.in | 1 + plugins/tutor-contrib-test-legacy-js/Makefile | 28 +++++++++ .../tutor-contrib-test-legacy-js/README.rst | 36 +++++++++++ plugins/tutor-contrib-test-legacy-js/setup.py | 60 +++++++++++++++++++ .../tutor_test_legacy_js/__about__.py | 1 + .../tutor_test_legacy_js/__init__.py | 0 .../tutor_test_legacy_js/patches/.gitignore | 0 ...dx-dev-dockerfile-post-python-requirements | 10 ++++ .../tutor_test_legacy_js/plugin.py | 24 ++++++++ 11 files changed, 168 insertions(+) create mode 100644 plugins/tutor-contrib-test-legacy-js/.gitignore create mode 100644 plugins/tutor-contrib-test-legacy-js/MANIFEST.in create mode 100644 plugins/tutor-contrib-test-legacy-js/Makefile create mode 100644 plugins/tutor-contrib-test-legacy-js/README.rst create mode 100644 plugins/tutor-contrib-test-legacy-js/setup.py create mode 100644 plugins/tutor-contrib-test-legacy-js/tutor_test_legacy_js/__about__.py create mode 100644 plugins/tutor-contrib-test-legacy-js/tutor_test_legacy_js/__init__.py create mode 100644 plugins/tutor-contrib-test-legacy-js/tutor_test_legacy_js/patches/.gitignore create mode 100644 plugins/tutor-contrib-test-legacy-js/tutor_test_legacy_js/patches/openedx-dev-dockerfile-post-python-requirements create mode 100644 plugins/tutor-contrib-test-legacy-js/tutor_test_legacy_js/plugin.py diff --git a/README.rst b/README.rst index 33e7ccf..d8d7183 100644 --- a/README.rst +++ b/README.rst @@ -19,6 +19,7 @@ community: Plugin Status (*Experimental*, *Production*, or *Deprecated*) =================================== ====================================================== tutor-contrib-learner-dashboard-mfe Deprecated +tutor-contrib-test-legacy-js "Production" (Supported For Developers) =================================== ====================================================== Getting Started diff --git a/plugins/tutor-contrib-test-legacy-js/.gitignore b/plugins/tutor-contrib-test-legacy-js/.gitignore new file mode 100644 index 0000000..f6a874f --- /dev/null +++ b/plugins/tutor-contrib-test-legacy-js/.gitignore @@ -0,0 +1,7 @@ +.*.swp +!.gitignore +TODO +__pycache__ +*.egg-info/ +/build/ +/dist/ diff --git a/plugins/tutor-contrib-test-legacy-js/MANIFEST.in b/plugins/tutor-contrib-test-legacy-js/MANIFEST.in new file mode 100644 index 0000000..770386a --- /dev/null +++ b/plugins/tutor-contrib-test-legacy-js/MANIFEST.in @@ -0,0 +1 @@ +recursive-include tutor_test_legacy_js/patches * diff --git a/plugins/tutor-contrib-test-legacy-js/Makefile b/plugins/tutor-contrib-test-legacy-js/Makefile new file mode 100644 index 0000000..6213333 --- /dev/null +++ b/plugins/tutor-contrib-test-legacy-js/Makefile @@ -0,0 +1,28 @@ +.DEFAULT_GOAL := help +.PHONY: docs +SRC_DIRS = ./tutor_test_legacy_js +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} + +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/plugins/tutor-contrib-test-legacy-js/README.rst b/plugins/tutor-contrib-test-legacy-js/README.rst new file mode 100644 index 0000000..d8ab347 --- /dev/null +++ b/plugins/tutor-contrib-test-legacy-js/README.rst @@ -0,0 +1,36 @@ +test-legacy-js plugin for `Tutor `__ +==================================================================== + +This plugin allows edx-platform developers to run legacy JavaScript tests by adding some system requirements to the ``openedx-dev`` image. + +This is a plugin rather than an upstream feature because adding these requirements directly to the core ``openedx-dev`` image would nontrivially increase its size and build time. Only a small minority of edx-platform developers need to run unit tests on the mostly-deprecated legacy JavaScript code. + +Installation +------------ + +This will install the Test Legacy JS plugin directly from Github:: + + pip install git+https://github.com/openedx/openedx-tutor-plugins.git#subdirectory=plugins/tutor-contrib-test-legacy-js + +Alternatively, you can clone the parent repository locally and install it from the checkout:: + + git clone https://github.com/openedx/openedx-tutor-plugins.git + cd openedx-tutor-plugins/plugins/tutor-contrib-test-legacy-js + pip install -e . + +Usage +----- + +Once installed, run the following commands to enable it:: + + tutor plugins enable test-legacy-js + tutor images build openedx-dev + +This should allow you to run legacy edx-platform JS tests:: + + tutor dev run lms npm run test + +License +------- + +This software is licensed under the terms of the AGPLv3. diff --git a/plugins/tutor-contrib-test-legacy-js/setup.py b/plugins/tutor-contrib-test-legacy-js/setup.py new file mode 100644 index 0000000..6418e0d --- /dev/null +++ b/plugins/tutor-contrib-test-legacy-js/setup.py @@ -0,0 +1,60 @@ +import io +import os +from setuptools import setup, find_packages + +HERE = os.path.abspath(os.path.dirname(__file__)) + + +def load_readme(): + with io.open(os.path.join(HERE, "README.rst"), "rt", encoding="utf8") as f: + return f.read() + + +def load_about(): + about = {} + with io.open( + os.path.join(HERE, "tutor_test_legacy_js", "__about__.py"), + "rt", + encoding="utf-8", + ) as f: + exec(f.read(), about) # pylint: disable=exec-used + return about + + +ABOUT = load_about() + + +setup( + name="tutor-contrib-test-legacy-js", + version=ABOUT["__version__"], + url="https://github.com/openedx/openedx-tutor-plugins", + project_urls={ + "Code": "https://github.com/openedx/openedx-tutor-plugins", + "Issue tracker": "https://github.com/openedx/openedx-tutor-plugins/issues", + }, + license="AGPLv3", + author="Adolfo R. Brandes", + description="test-legacy-js plugin for Tutor", + long_description=load_readme(), + packages=find_packages(exclude=["tests*"]), + include_package_data=True, + python_requires=">=3.9", + install_requires=["tutor"], + extras_require={"dev": ["tutor[dev]>=16.0.0,<17.0.0"]}, + entry_points={ + "tutor.plugin.v1": [ + "test-legacy-js = tutor_test_legacy_js.plugin" + ] + }, + classifiers=[ + "Development Status :: 3 - Alpha", + "Intended Audience :: Developers", + "License :: OSI Approved :: GNU Affero General Public License v3", + "Operating System :: OS Independent", + "Programming Language :: Python", + "Programming Language :: Python :: 3.9", + "Programming Language :: Python :: 3.10", + "Programming Language :: Python :: 3.11", + "Programming Language :: Python :: 3.12", + ], +) diff --git a/plugins/tutor-contrib-test-legacy-js/tutor_test_legacy_js/__about__.py b/plugins/tutor-contrib-test-legacy-js/tutor_test_legacy_js/__about__.py new file mode 100644 index 0000000..5becc17 --- /dev/null +++ b/plugins/tutor-contrib-test-legacy-js/tutor_test_legacy_js/__about__.py @@ -0,0 +1 @@ +__version__ = "1.0.0" diff --git a/plugins/tutor-contrib-test-legacy-js/tutor_test_legacy_js/__init__.py b/plugins/tutor-contrib-test-legacy-js/tutor_test_legacy_js/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/plugins/tutor-contrib-test-legacy-js/tutor_test_legacy_js/patches/.gitignore b/plugins/tutor-contrib-test-legacy-js/tutor_test_legacy_js/patches/.gitignore new file mode 100644 index 0000000..e69de29 diff --git a/plugins/tutor-contrib-test-legacy-js/tutor_test_legacy_js/patches/openedx-dev-dockerfile-post-python-requirements b/plugins/tutor-contrib-test-legacy-js/tutor_test_legacy_js/patches/openedx-dev-dockerfile-post-python-requirements new file mode 100644 index 0000000..9e9fb11 --- /dev/null +++ b/plugins/tutor-contrib-test-legacy-js/tutor_test_legacy_js/patches/openedx-dev-dockerfile-post-python-requirements @@ -0,0 +1,10 @@ +USER root +RUN --mount=type=cache,target=/var/cache/apt,sharing=locked \ + --mount=type=cache,target=/var/lib/apt,sharing=locked \ + apt update && \ + apt install -y libxmlsec1-dev ubuntu-restricted-extras xvfb libgtk-3-0 +RUN cd /opt && \ + (curl -L "https://ftp.mozilla.org/pub/firefox/releases/123.0/linux-x86_64/en-US/firefox-123.0.tar.bz2" > ffox.tar.gz) && \ + tar -xjf ffox.tar.gz && \ + ln -s /opt/firefox/firefox /usr/bin/firefox +USER app diff --git a/plugins/tutor-contrib-test-legacy-js/tutor_test_legacy_js/plugin.py b/plugins/tutor-contrib-test-legacy-js/tutor_test_legacy_js/plugin.py new file mode 100644 index 0000000..a6f4dd0 --- /dev/null +++ b/plugins/tutor-contrib-test-legacy-js/tutor_test_legacy_js/plugin.py @@ -0,0 +1,24 @@ +from __future__ import annotations + +import os +import os.path +from glob import glob + +import importlib.resources + +from tutor import hooks + +######################################## +# PATCH LOADING +######################################## + +# For each file in tutor_test_legacy_js/patches, +# apply a patch based on the file's name and contents. +for path in glob( + os.path.join( + importlib.resources.files("tutor_test_legacy_js") / "patches", + "*", + ) +): + with open(path, encoding="utf-8") as patch_file: + hooks.Filters.ENV_PATCHES.add_item((os.path.basename(path), patch_file.read()))