From 1edc3d04717413618e8e23a08f0cd11f90ec2043 Mon Sep 17 00:00:00 2001 From: Richard Tibbles Date: Wed, 18 Oct 2023 14:08:06 -0700 Subject: [PATCH 1/4] Call pre-commit on generated files from within the generate script. Update pre_commit to rebuild when spec or setup.py has changed. --- .pre-commit-config.yaml | 8 ++++++++ Makefile | 1 - scripts/generate_from_specs.py | 20 +++++++++++++++++--- 3 files changed, 25 insertions(+), 4 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index b52e549..830d896 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -1,5 +1,13 @@ exclude: (\.git/|\.tox/|\.venv/|le_utils\.egg-info) repos: +- repo: local + hooks: + - id: rebuild + name: Regenerate files + description: Regenerates files when specs or version has changed + entry: make build + language: system + files: (spec/.*\.json|setup\.py)$ - repo: https://github.com/pre-commit/pre-commit-hooks rev: v2.0.0 hooks: diff --git a/Makefile b/Makefile index c680427..94c2493 100644 --- a/Makefile +++ b/Makefile @@ -26,7 +26,6 @@ test: build: pip install -e . python scripts/generate_from_specs.py - pre-commit run --all-files || true release: clean build python setup.py sdist diff --git a/scripts/generate_from_specs.py b/scripts/generate_from_specs.py index 88d50a8..8032f58 100644 --- a/scripts/generate_from_specs.py +++ b/scripts/generate_from_specs.py @@ -8,6 +8,7 @@ import os import re import string +import subprocess import sys from collections import OrderedDict from glob import glob @@ -238,26 +239,34 @@ def write_js_file(output_file, name, ordered_output, schema=None): def write_labels_src_files(label_outputs): + output_files = [] for label_type, ordered_output in label_outputs.items(): py_output_file = os.path.join( py_labels_output_dir, "{}.py".format(pascal_to_snake(label_type)) ) write_python_file(py_output_file, label_type, ordered_output) + output_files.append(py_output_file) js_output_file = os.path.join(js_labels_output_dir, "{}.js".format(label_type)) write_js_file(js_output_file, label_type, ordered_output) + output_files.append(js_output_file) + return output_files def write_constants_src_files(constants_outputs, schemas): + output_files = [] for constant_type, ordered_output in constants_outputs.items(): py_output_file = os.path.join( py_output_dir, "{}.py".format(pascal_to_snake(constant_type)) ) schema = schemas.get(constant_type) write_python_file(py_output_file, constant_type, ordered_output, schema=schema) + output_files.append(py_output_file) js_output_file = os.path.join(js_output_dir, "{}.js".format(constant_type)) write_js_file(js_output_file, constant_type, ordered_output, schema=schema) + output_files.append(js_output_file) + return output_files def set_package_json_version(): @@ -279,6 +288,7 @@ def set_package_json_version(): else: f.write("\n") f.write(line.rstrip()) + return [package_json] if __name__ == "__main__": @@ -289,8 +299,12 @@ def set_package_json_version(): schemas_to_write, schema_constants_to_write = read_schema_specs() constants_to_write.update(schema_constants_to_write) - write_labels_src_files(labels_to_write) + output_files = [] - write_constants_src_files(constants_to_write, schemas_to_write) + output_files += write_labels_src_files(labels_to_write) - set_package_json_version() + output_files += write_constants_src_files(constants_to_write, schemas_to_write) + + output_files += set_package_json_version() + + subprocess.call(["pre-commit", "run", "--files"] + output_files) From 421ca56e08d0ba30e5d6ebd1e8fa3005e4f73203 Mon Sep 17 00:00:00 2001 From: Richard Tibbles Date: Wed, 18 Oct 2023 14:08:32 -0700 Subject: [PATCH 2/4] Add IMSCP format preset. --- le_utils/constants/format_presets.py | 4 ++++ le_utils/resources/presetlookup.json | 12 ++++++++++++ 2 files changed, 16 insertions(+) diff --git a/le_utils/constants/format_presets.py b/le_utils/constants/format_presets.py index df20260..119fc3a 100644 --- a/le_utils/constants/format_presets.py +++ b/le_utils/constants/format_presets.py @@ -72,6 +72,9 @@ QTI_THUMBNAIL = "qti_thumbnail" QTI_THUMBNAIL_READABLE = "QTI Thumbnail" +IMSCP_ZIP = "imscp_zip" +IMSCP_ZIP_READABLE = "IMSCP Zip" + SLIDESHOW_IMAGE = "slideshow_image" SLIDESHOW_IMAGE_READABLE = "Slideshow Image" @@ -114,6 +117,7 @@ (SLIDESHOW_IMAGE, SLIDESHOW_IMAGE_READABLE), (SLIDESHOW_THUMBNAIL, SLIDESHOW_THUMBNAIL_READABLE), (SLIDESHOW_MANIFEST, SLIDESHOW_MANIFEST_READABLE), + (IMSCP_ZIP, IMSCP_ZIP_READABLE), ) diff --git a/le_utils/resources/presetlookup.json b/le_utils/resources/presetlookup.json index a16c80a..5e8e027 100644 --- a/le_utils/resources/presetlookup.json +++ b/le_utils/resources/presetlookup.json @@ -239,6 +239,18 @@ "allowed_formats": ["png", "jpg", "jpeg"], "convertible_formats": [] }, + "imscp_zip": { + "readable_name": "IMSCP Zip", + "multi_language": false, + "supplementary": false, + "thumbnail": false, + "subtitle": false, + "display": true, + "order": 1, + "kind": "html5", + "allowed_formats": ["zip"], + "convertible_formats": [] + }, "h5p": { "readable_name": "H5P", "multi_language": false, From 2ee350ae082ccc04a8cf90fb41fbe631a6f04a9f Mon Sep 17 00:00:00 2001 From: Richard Tibbles Date: Wed, 18 Oct 2023 14:09:04 -0700 Subject: [PATCH 3/4] Bump version. Rebuild files. --- js/package.json | 2 +- setup.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/js/package.json b/js/package.json index fc6481b..74c3684 100644 --- a/js/package.json +++ b/js/package.json @@ -27,5 +27,5 @@ "scripts": { "test": "echo \"Error: no test specified\" && exit 1" }, - "version": "0.2.0" + "version": "0.2.2" } \ No newline at end of file diff --git a/setup.py b/setup.py index 7eae16a..ce37712 100644 --- a/setup.py +++ b/setup.py @@ -12,7 +12,7 @@ setup( name="le-utils", packages=find_packages(), - version="0.2.1", + version="0.2.2", description="LE-Utils contains shared constants used in Kolibri, Ricecooker, and Kolibri Studio.", long_description=long_description, long_description_content_type="text/markdown", From 6822ca826c5e51d90ca576a27ac9f2e100e3b4fa Mon Sep 17 00:00:00 2001 From: Richard Tibbles Date: Wed, 18 Oct 2023 16:15:52 -0700 Subject: [PATCH 4/4] Revert pre-commit addition to generate specs. --- .pre-commit-config.yaml | 8 -------- 1 file changed, 8 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 830d896..b52e549 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -1,13 +1,5 @@ exclude: (\.git/|\.tox/|\.venv/|le_utils\.egg-info) repos: -- repo: local - hooks: - - id: rebuild - name: Regenerate files - description: Regenerates files when specs or version has changed - entry: make build - language: system - files: (spec/.*\.json|setup\.py)$ - repo: https://github.com/pre-commit/pre-commit-hooks rev: v2.0.0 hooks: