From edbed9ce6912de60ab9b4f92c0d9d0a2c205136e Mon Sep 17 00:00:00 2001 From: Wojtek Kosior Date: Sat, 12 Feb 2022 16:39:18 +0100 Subject: when generating JSON documents, put generating software info in 'generated_by' property --- src/hydrilla/builder/build.py | 14 +++++++++++--- src/hydrilla/schemas | 2 +- src/test/test_hydrilla_builder.py | 27 ++++++++++++++++++--------- 3 files changed, 30 insertions(+), 13 deletions(-) diff --git a/src/hydrilla/builder/build.py b/src/hydrilla/builder/build.py index 891b568..8e10776 100644 --- a/src/hydrilla/builder/build.py +++ b/src/hydrilla/builder/build.py @@ -35,6 +35,7 @@ import jsonschema import click from .. import util +from . import _version here = Path(__file__).resolve().parent @@ -42,6 +43,11 @@ _ = util.translation(here / 'locales').gettext index_validator = util.validator_for('package_source-1.schema.json') +generated_by = { + 'name': 'hydrilla.builder', + 'version': _version.version +} + class FileReferenceError(Exception): """ Exception used to report various problems concerning files referenced from @@ -278,9 +284,10 @@ class Build: new_item_obj.update([(p, item_def[p]) for p in copy_props]) new_item_obj['version'] = util.normalize_version(item_def['version']) - new_item_obj['api_schema_version'] = [1, 0, 1] + new_item_obj['api_schema_version'] = [1] new_item_obj['source_copyright'] = self.copyright_file_refs new_item_obj['source_name'] = self.source_name + new_item_obj['generated_by'] = generated_by item_list.append(new_item_obj) @@ -327,12 +334,13 @@ class Build: } self.source_description = { - 'api_schema_version': [1, 0, 1], + 'api_schema_version': [1], 'source_name': self.source_name, 'source_copyright': self.copyright_file_refs, 'upstream_url': index_obj['upstream_url'], 'definitions': item_refs, - 'source_archives': source_archives_obj + 'source_archives': source_archives_obj, + 'generated_by': generated_by } if 'comment' in index_obj: diff --git a/src/hydrilla/schemas b/src/hydrilla/schemas index a844277..b191710 160000 --- a/src/hydrilla/schemas +++ b/src/hydrilla/schemas @@ -1 +1 @@ -Subproject commit a8442778ff400fd9d50cac7944b491c7d641df1f +Subproject commit b19171081e23bcccf9b41588c0464ca9c2c657c0 diff --git a/src/test/test_hydrilla_builder.py b/src/test/test_hydrilla_builder.py index 041a3f6..26ede09 100644 --- a/src/test/test_hydrilla_builder.py +++ b/src/test/test_hydrilla_builder.py @@ -17,10 +17,15 @@ from typing import Callable, Optional, Iterable from jsonschema import ValidationError from hydrilla import util as hydrilla_util -from hydrilla.builder import build +from hydrilla.builder import build, _version here = Path(__file__).resolve().parent +expected_generated_by = { + 'name': 'hydrilla.builder', + 'version': _version.version +} + default_srcdir = here / 'source-package-example' default_js_filenames = ['bye.js', 'hello.js', 'message.js'] @@ -57,7 +62,7 @@ class CaseSettings: self.contents = default_contents.copy() self.expected_resources = [{ - 'api_schema_version': [1, 0, 1], + 'api_schema_version': [1], 'source_name': 'hello', 'source_copyright': [{ 'file': 'report.spdx', @@ -80,9 +85,10 @@ class CaseSettings: }, { 'file': 'bye.js', 'sha256': self.sha256_hashes['bye.js'] - }] + }], + 'generated_by': expected_generated_by }, { - 'api_schema_version': [1, 0, 1], + 'api_schema_version': [1], 'source_name': 'hello', 'source_copyright': [{ 'file': 'report.spdx', @@ -102,10 +108,11 @@ class CaseSettings: 'scripts': [{ 'file': 'message.js', 'sha256': self.sha256_hashes['message.js'] - }] + }], + 'generated_by': expected_generated_by }] self.expected_mapping = { - 'api_schema_version': [1, 0, 1], + 'api_schema_version': [1], 'source_name': 'hello', 'source_copyright': [{ 'file': 'report.spdx', @@ -127,10 +134,11 @@ class CaseSettings: 'https://hachettebugs.koszko.org/***': { 'identifier': 'helloapple' } - } + }, + 'generated_by': expected_generated_by } self.expected_source_description = { - 'api_schema_version': [1, 0, 1], + 'api_schema_version': [1], 'source_name': 'hello', 'source_copyright': [{ 'file': 'report.spdx', @@ -160,7 +168,8 @@ class CaseSettings: 'identifier': 'helloapple', 'long_name': 'Hello Apple', 'version': [2021, 11, 10], - }] + }], + 'generated_by': expected_generated_by } def expected(self) -> list[dict]: -- cgit v1.2.3