From f5f06d98fcc5c8f1d41c24505fae7e5112024c9a Mon Sep 17 00:00:00 2001 From: Waqar Ahmed Date: Sun, 5 May 2024 17:24:37 +0500 Subject: [PATCH] Move apps schema to it's own python package --- apps_schema/__init__.py | 1 + .../schema => apps_schema}/attrs/__init__.py | 0 {apps_validation/schema => apps_schema}/attrs/array.py | 2 +- {apps_validation/schema => apps_schema}/attrs/base.py | 8 ++++---- {apps_validation/schema => apps_schema}/attrs/bool.py | 0 .../schema => apps_schema}/attrs/dictionary.py | 2 +- {apps_validation/schema => apps_schema}/attrs/integer.py | 0 {apps_validation/schema => apps_schema}/attrs/string.py | 0 {apps_validation/schema => apps_schema}/attrs/utils.py | 0 .../schema => apps_schema}/features/__init__.py | 0 {apps_validation/schema => apps_schema}/features/acl.py | 2 +- {apps_validation/schema => apps_schema}/features/base.py | 0 .../schema => apps_schema}/features/basic.py | 2 +- .../schema => apps_schema}/features/certificate.py | 2 +- .../schema => apps_schema}/features/container_image.py | 2 +- .../schema => apps_schema}/features/interface.py | 2 +- .../schema => apps_schema}/features/ix_volume.py | 2 +- {apps_validation/schema => apps_schema}/features/node.py | 2 +- .../schema => apps_schema}/features/utils.py | 0 {apps_validation/schema => apps_schema}/variable.py | 0 apps_validation/ci/git.py | 2 +- apps_validation/pytest/unit/test_attr_schema.py | 4 ++-- apps_validation/schema/__init__.py | 1 - apps_validation/scripts/catalog_update.py | 8 ++++---- apps_validation/validation/validate_app_version.py | 2 +- apps_validation/validation/validate_catalog.py | 2 +- apps_validation/validation/validate_dev_directory.py | 2 +- apps_validation/validation/validate_questions.py | 4 ++-- apps_validation/validation/validate_recommended_apps.py | 2 +- catalog_reader/supported_version.py | 2 +- setup.py | 9 ++++++++- 31 files changed, 36 insertions(+), 29 deletions(-) create mode 100644 apps_schema/__init__.py rename {apps_validation/schema => apps_schema}/attrs/__init__.py (100%) rename {apps_validation/schema => apps_schema}/attrs/array.py (90%) rename {apps_validation/schema => apps_schema}/attrs/base.py (94%) rename {apps_validation/schema => apps_schema}/attrs/bool.py (100%) rename {apps_validation/schema => apps_schema}/attrs/dictionary.py (93%) rename {apps_validation/schema => apps_schema}/attrs/integer.py (100%) rename {apps_validation/schema => apps_schema}/attrs/string.py (100%) rename {apps_validation/schema => apps_schema}/attrs/utils.py (100%) rename {apps_validation/schema => apps_schema}/features/__init__.py (100%) rename {apps_validation/schema => apps_schema}/features/acl.py (70%) rename {apps_validation/schema => apps_schema}/features/base.py (100%) rename {apps_validation/schema => apps_schema}/features/basic.py (80%) rename {apps_validation/schema => apps_schema}/features/certificate.py (83%) rename {apps_validation/schema => apps_schema}/features/container_image.py (90%) rename {apps_validation/schema => apps_schema}/features/interface.py (81%) rename {apps_validation/schema => apps_schema}/features/ix_volume.py (96%) rename {apps_validation/schema => apps_schema}/features/node.py (79%) rename {apps_validation/schema => apps_schema}/features/utils.py (100%) rename {apps_validation/schema => apps_schema}/variable.py (100%) delete mode 100644 apps_validation/schema/__init__.py diff --git a/apps_schema/__init__.py b/apps_schema/__init__.py new file mode 100644 index 0000000..6e6ae06 --- /dev/null +++ b/apps_schema/__init__.py @@ -0,0 +1 @@ +# FIXME: We need to account for migration apps_schema diff --git a/apps_validation/schema/attrs/__init__.py b/apps_schema/attrs/__init__.py similarity index 100% rename from apps_validation/schema/attrs/__init__.py rename to apps_schema/attrs/__init__.py diff --git a/apps_validation/schema/attrs/array.py b/apps_schema/attrs/array.py similarity index 90% rename from apps_validation/schema/attrs/array.py rename to apps_schema/attrs/array.py index 07bd996..c3304ce 100644 --- a/apps_validation/schema/attrs/array.py +++ b/apps_schema/attrs/array.py @@ -12,7 +12,7 @@ def __init__(self, data): self._skip_data_values = ['items'] def initialize_values(self, data): - from apps_validation.schema.variable import Variable + from apps_schema.variable import Variable super().initialize_values(data) self.items = [Variable(d) for d in (data.get('items') or [])] diff --git a/apps_validation/schema/attrs/base.py b/apps_schema/attrs/base.py similarity index 94% rename from apps_validation/schema/attrs/base.py rename to apps_schema/attrs/base.py index a89c429..e1b90e0 100644 --- a/apps_validation/schema/attrs/base.py +++ b/apps_schema/attrs/base.py @@ -10,7 +10,7 @@ class SchemaMeta(type): def __new__(cls, name, bases, dct): klass = type.__new__(cls, name, bases, dct) if klass.__name__ != 'BaseSchema' and getattr(klass, 'SCHEMA_NAME', NotImplementedError) is NotImplementedError: - raise ValueError(f'{name!r} attr schema does not has SCHEMA_NAME defined') + raise ValueError(f'{name!r} attr apps_schema does not has SCHEMA_NAME defined') ATTRIBUTES_SCHEMA[klass.SCHEMA_NAME] = klass return klass @@ -47,18 +47,18 @@ def validate(self, schema, data=None): self.initialize_values(data) if not self._schema_data: - raise Exception('Schema data must be initialized before validating schema') + raise Exception('Schema data must be initialized before validating apps_schema') verrors = ValidationErrors() try: json_schema_validate(self._schema_data, self.json_schema()) except JsonValidationError as e: - verrors.add(schema, f'Failed to validate schema: {e}') + verrors.add(schema, f'Failed to validate apps_schema: {e}') verrors.check() if '$ref' in self._schema_data: - from apps_validation.schema.features import FEATURES + from apps_schema.features import FEATURES for index, ref in enumerate(self._schema_data['$ref']): if not isinstance(ref, str): verrors.add(f'{schema}.$ref.{index}', 'Must be a string') diff --git a/apps_validation/schema/attrs/bool.py b/apps_schema/attrs/bool.py similarity index 100% rename from apps_validation/schema/attrs/bool.py rename to apps_schema/attrs/bool.py diff --git a/apps_validation/schema/attrs/dictionary.py b/apps_schema/attrs/dictionary.py similarity index 93% rename from apps_validation/schema/attrs/dictionary.py rename to apps_schema/attrs/dictionary.py index f9b6072..9a32240 100644 --- a/apps_validation/schema/attrs/dictionary.py +++ b/apps_schema/attrs/dictionary.py @@ -12,7 +12,7 @@ def __init__(self, data): self._skip_data_values = ['attrs'] def initialize_values(self, data): - from apps_validation.schema.variable import Variable + from apps_schema.variable import Variable super().initialize_values(data) self.attrs = [Variable(d) for d in (data.get('attrs') or [])] diff --git a/apps_validation/schema/attrs/integer.py b/apps_schema/attrs/integer.py similarity index 100% rename from apps_validation/schema/attrs/integer.py rename to apps_schema/attrs/integer.py diff --git a/apps_validation/schema/attrs/string.py b/apps_schema/attrs/string.py similarity index 100% rename from apps_validation/schema/attrs/string.py rename to apps_schema/attrs/string.py diff --git a/apps_validation/schema/attrs/utils.py b/apps_schema/attrs/utils.py similarity index 100% rename from apps_validation/schema/attrs/utils.py rename to apps_schema/attrs/utils.py diff --git a/apps_validation/schema/features/__init__.py b/apps_schema/features/__init__.py similarity index 100% rename from apps_validation/schema/features/__init__.py rename to apps_schema/features/__init__.py diff --git a/apps_validation/schema/features/acl.py b/apps_schema/features/acl.py similarity index 70% rename from apps_validation/schema/features/acl.py rename to apps_schema/features/acl.py index e6c5a8c..2495438 100644 --- a/apps_validation/schema/features/acl.py +++ b/apps_schema/features/acl.py @@ -1,4 +1,4 @@ -from apps_validation.schema.attrs import DictSchema +from apps_schema.attrs import DictSchema from .base import BaseFeature diff --git a/apps_validation/schema/features/base.py b/apps_schema/features/base.py similarity index 100% rename from apps_validation/schema/features/base.py rename to apps_schema/features/base.py diff --git a/apps_validation/schema/features/basic.py b/apps_schema/features/basic.py similarity index 80% rename from apps_validation/schema/features/basic.py rename to apps_schema/features/basic.py index d505f39..0fa5593 100644 --- a/apps_validation/schema/features/basic.py +++ b/apps_schema/features/basic.py @@ -1,4 +1,4 @@ -from apps_validation.schema.attrs import DictSchema, StringSchema +from apps_schema.attrs import DictSchema, StringSchema from .base import BaseFeature diff --git a/apps_validation/schema/features/certificate.py b/apps_schema/features/certificate.py similarity index 83% rename from apps_validation/schema/features/certificate.py rename to apps_schema/features/certificate.py index 4a0f107..e39940e 100644 --- a/apps_validation/schema/features/certificate.py +++ b/apps_schema/features/certificate.py @@ -1,4 +1,4 @@ -from apps_validation.schema.attrs import IntegerSchema +from apps_schema.attrs import IntegerSchema from .base import BaseFeature diff --git a/apps_validation/schema/features/container_image.py b/apps_schema/features/container_image.py similarity index 90% rename from apps_validation/schema/features/container_image.py rename to apps_schema/features/container_image.py index a1df45c..8b08160 100644 --- a/apps_validation/schema/features/container_image.py +++ b/apps_schema/features/container_image.py @@ -1,4 +1,4 @@ -from apps_validation.schema.attrs import DictSchema, StringSchema +from apps_schema.attrs import DictSchema, StringSchema from .base import BaseFeature diff --git a/apps_validation/schema/features/interface.py b/apps_schema/features/interface.py similarity index 81% rename from apps_validation/schema/features/interface.py rename to apps_schema/features/interface.py index 447cd3e..a01694c 100644 --- a/apps_validation/schema/features/interface.py +++ b/apps_schema/features/interface.py @@ -1,4 +1,4 @@ -from apps_validation.schema.attrs import DictSchema, StringSchema +from apps_schema.attrs import DictSchema, StringSchema from .base import BaseFeature diff --git a/apps_validation/schema/features/ix_volume.py b/apps_schema/features/ix_volume.py similarity index 96% rename from apps_validation/schema/features/ix_volume.py rename to apps_schema/features/ix_volume.py index 1c71bac..5a0ceec 100644 --- a/apps_validation/schema/features/ix_volume.py +++ b/apps_schema/features/ix_volume.py @@ -1,4 +1,4 @@ -from apps_validation.schema.attrs import DictSchema, StringSchema +from apps_schema.attrs import DictSchema, StringSchema from .base import BaseFeature diff --git a/apps_validation/schema/features/node.py b/apps_schema/features/node.py similarity index 79% rename from apps_validation/schema/features/node.py rename to apps_schema/features/node.py index 525a850..0aad319 100644 --- a/apps_validation/schema/features/node.py +++ b/apps_schema/features/node.py @@ -1,4 +1,4 @@ -from apps_validation.schema.attrs import IntegerSchema, StringSchema +from apps_schema.attrs import IntegerSchema, StringSchema from .base import BaseFeature diff --git a/apps_validation/schema/features/utils.py b/apps_schema/features/utils.py similarity index 100% rename from apps_validation/schema/features/utils.py rename to apps_schema/features/utils.py diff --git a/apps_validation/schema/variable.py b/apps_schema/variable.py similarity index 100% rename from apps_validation/schema/variable.py rename to apps_schema/variable.py diff --git a/apps_validation/ci/git.py b/apps_validation/ci/git.py index 6737663..7d12a06 100644 --- a/apps_validation/ci/git.py +++ b/apps_validation/ci/git.py @@ -2,11 +2,11 @@ import subprocess from collections import defaultdict +from apps_validation.exceptions import CatalogDoesNotExist from catalog_reader.dev_directory import ( DEV_DIRECTORY_RELATIVE_PATH, get_ci_development_directory, OPTIONAL_METADATA_FILES ) from catalog_reader.train_utils import is_train_valid -from apps_validation.exceptions import CatalogDoesNotExist def get_changed_apps(catalog_path: str, base_branch: str = 'master') -> dict: diff --git a/apps_validation/pytest/unit/test_attr_schema.py b/apps_validation/pytest/unit/test_attr_schema.py index ea20390..eaa72e2 100644 --- a/apps_validation/pytest/unit/test_attr_schema.py +++ b/apps_validation/pytest/unit/test_attr_schema.py @@ -1,10 +1,10 @@ import pytest from apps_validation.exceptions import ValidationErrors -from apps_validation.schema.attrs import get_schema +from apps_schema.attrs import get_schema -@pytest.mark.parametrize('schema,should_work', [ +@pytest.mark.parametrize('apps_schema,should_work', [ ( { 'type': 'dict', diff --git a/apps_validation/schema/__init__.py b/apps_validation/schema/__init__.py deleted file mode 100644 index 26018be..0000000 --- a/apps_validation/schema/__init__.py +++ /dev/null @@ -1 +0,0 @@ -# FIXME: We need to account for migration schema diff --git a/apps_validation/scripts/catalog_update.py b/apps_validation/scripts/catalog_update.py index 1e68d15..60ad2db 100644 --- a/apps_validation/scripts/catalog_update.py +++ b/apps_validation/scripts/catalog_update.py @@ -8,16 +8,16 @@ from jsonschema import validate as json_schema_validate, ValidationError as JsonValidationError +from apps_validation.ci.names import CACHED_CATALOG_FILE_NAME, CACHED_VERSION_FILE_NAME +from apps_validation.exceptions import ValidationErrors +from apps_validation.validation.json_schema_utils import CATALOG_JSON_SCHEMA +from apps_validation.validation.validate_app_version import validate_catalog_item_version_data from catalog_reader.catalog import retrieve_train_names, retrieve_trains_data, get_apps_in_trains from catalog_reader.dev_directory import ( get_app_version, get_ci_development_directory, get_to_keep_versions, OPTIONAL_METADATA_FILES, REQUIRED_METADATA_FILES, version_has_been_bumped, ) from catalog_reader.train_utils import get_train_path -from apps_validation.ci.names import CACHED_CATALOG_FILE_NAME, CACHED_VERSION_FILE_NAME -from apps_validation.exceptions import ValidationErrors -from apps_validation.validation.json_schema_utils import CATALOG_JSON_SCHEMA -from apps_validation.validation.validate_app_version import validate_catalog_item_version_data def get_trains(location: str) -> typing.Tuple[dict, dict]: diff --git a/apps_validation/validation/validate_app_version.py b/apps_validation/validation/validate_app_version.py index 585214b..ebade9b 100644 --- a/apps_validation/validation/validate_app_version.py +++ b/apps_validation/validation/validate_app_version.py @@ -5,8 +5,8 @@ from jsonschema import validate as json_schema_validate, ValidationError as JsonValidationError from semantic_version import Version -from catalog_reader.questions_util import CUSTOM_PORTALS_KEY from apps_validation.exceptions import ValidationErrors +from catalog_reader.questions_util import CUSTOM_PORTALS_KEY from .app_version import validate_app_version_file from .ix_values import validate_ix_values_schema diff --git a/apps_validation/validation/validate_catalog.py b/apps_validation/validation/validate_catalog.py index 8bf2621..f74eb19 100644 --- a/apps_validation/validation/validate_catalog.py +++ b/apps_validation/validation/validate_catalog.py @@ -5,8 +5,8 @@ from jsonschema import validate as json_schema_validate, ValidationError as JsonValidationError from apps_validation.ci.names import CACHED_CATALOG_FILE_NAME -from catalog_reader.train_utils import get_train_path from apps_validation.exceptions import CatalogDoesNotExist, ValidationErrors +from catalog_reader.train_utils import get_train_path from .json_schema_utils import CATALOG_JSON_SCHEMA from .validate_app_rename_migrations import validate_migrations diff --git a/apps_validation/validation/validate_dev_directory.py b/apps_validation/validation/validate_dev_directory.py index 9b7f404..95b2f8d 100644 --- a/apps_validation/validation/validate_dev_directory.py +++ b/apps_validation/validation/validate_dev_directory.py @@ -3,12 +3,12 @@ from jsonschema import ValidationError as JsonValidationError +from apps_validation.exceptions import ValidationErrors from catalog_reader.dev_directory import ( get_app_version, get_ci_development_directory, get_to_keep_versions, REQUIRED_METADATA_FILES, version_has_been_bumped, ) from catalog_reader.names import UPGRADE_STRATEGY_FILENAME, TO_KEEP_VERSIONS -from apps_validation.exceptions import ValidationErrors from .app_version import validate_app_version_file from .validate_app_version import validate_catalog_item_version diff --git a/apps_validation/validation/validate_questions.py b/apps_validation/validation/validate_questions.py index 18e821e..aee8359 100644 --- a/apps_validation/validation/validate_questions.py +++ b/apps_validation/validation/validate_questions.py @@ -1,10 +1,10 @@ import typing import yaml +from apps_schema.variable import Variable +from apps_validation.exceptions import ValidationErrors from catalog_reader.questions import CUSTOM_PORTALS_ENABLE_KEY, CUSTOM_PORTAL_GROUP_KEY from catalog_reader.questions_util import CUSTOM_PORTALS_KEY -from apps_validation.exceptions import ValidationErrors -from apps_validation.schema.variable import Variable from .utils import validate_key_value_types diff --git a/apps_validation/validation/validate_recommended_apps.py b/apps_validation/validation/validate_recommended_apps.py index 5bc4f4b..0b418b5 100644 --- a/apps_validation/validation/validate_recommended_apps.py +++ b/apps_validation/validation/validate_recommended_apps.py @@ -3,8 +3,8 @@ from jsonschema import validate as json_schema_validate, ValidationError as JsonValidationError -from catalog_reader.names import RECOMMENDED_APPS_FILENAME from apps_validation.exceptions import ValidationErrors +from catalog_reader.names import RECOMMENDED_APPS_FILENAME from .json_schema_utils import RECOMMENDED_APPS_JSON_SCHEMA diff --git a/catalog_reader/supported_version.py b/catalog_reader/supported_version.py index 7108501..58f9bb6 100644 --- a/catalog_reader/supported_version.py +++ b/catalog_reader/supported_version.py @@ -1,4 +1,4 @@ -from apps_validation.schema.features import FEATURES +from apps_schema.features import FEATURES def version_supported(version_details: dict) -> bool: diff --git a/setup.py b/setup.py index 4ed2471..5b6faba 100644 --- a/setup.py +++ b/setup.py @@ -8,7 +8,14 @@ description='Validate TrueNAS Apps Catalog', version=VERSION, include_package_data=True, - packages=find_packages(include=['apps_validation', 'catalog_reader', 'apps_validation.*', 'catalog_reader.*']), + packages=find_packages(include=[ + 'apps_schema', + 'apps_schema.*', + 'apps_validation', + 'apps_validation.*', + 'catalog_reader', + 'catalog_reader.*' + ]), license='GNU3', platforms='any', entry_points={