Skip to content

Commit

Permalink
Move apps schema to it's own python package
Browse files Browse the repository at this point in the history
  • Loading branch information
sonicaj committed May 5, 2024
1 parent de161b3 commit 4a9347f
Show file tree
Hide file tree
Showing 32 changed files with 45 additions and 38 deletions.
1 change: 1 addition & 0 deletions apps_schema/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# FIXME: We need to account for migration apps_schema
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -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 [])]

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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')
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -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 [])]

Expand All @@ -22,7 +22,7 @@ def json_schema(self):
schema['properties']['attrs'] = {'type': 'array'}
schema['required'].append('attrs')
# We do not validate nested children and hence do not add it in the
# json schema as it makes it very complex to handle all the possibilities
# json apps_schema as it makes it very complex to handle all the possibilities
return schema


Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from apps_validation.schema.attrs import DictSchema
from apps_schema.attrs import DictSchema

from .base import BaseFeature

Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from apps_validation.schema.attrs import DictSchema, StringSchema
from apps_schema.attrs import DictSchema, StringSchema

from .base import BaseFeature

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from apps_validation.schema.attrs import IntegerSchema
from apps_schema.attrs import IntegerSchema

from .base import BaseFeature

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from apps_validation.schema.attrs import DictSchema, StringSchema
from apps_schema.attrs import DictSchema, StringSchema

from .base import BaseFeature

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from apps_validation.schema.attrs import DictSchema, StringSchema
from apps_schema.attrs import DictSchema, StringSchema

from .base import BaseFeature

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from apps_validation.schema.attrs import DictSchema, StringSchema
from apps_schema.attrs import DictSchema, StringSchema

from .base import BaseFeature

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from apps_validation.schema.attrs import IntegerSchema, StringSchema
from apps_schema.attrs import IntegerSchema, StringSchema

from .base import BaseFeature

Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,10 @@ def validate(self, schema):
verrors.add(f'{schema}.variable', 'Variable value must be specified')

if not self.schema:
verrors.add(f'{schema}.schema', 'Schema must be specified for variable')
verrors.add(f'{schema}.apps_schema', 'Schema must be specified for variable')
else:
try:
self.schema.validate(f'{schema}.schema')
self.schema.validate(f'{schema}.apps_schema')
except ValidationErrors as ve:
verrors.extend(ve)

Expand Down
2 changes: 1 addition & 1 deletion apps_validation/ci/git.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
4 changes: 2 additions & 2 deletions apps_validation/pytest/unit/test_attr_schema.py
Original file line number Diff line number Diff line change
@@ -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',
Expand Down
1 change: 0 additions & 1 deletion apps_validation/schema/__init__.py

This file was deleted.

8 changes: 4 additions & 4 deletions apps_validation/scripts/catalog_update.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]:
Expand Down
4 changes: 2 additions & 2 deletions apps_validation/validation/validate_app_version.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -76,7 +76,7 @@ def validate_catalog_item_version(
except ValidationErrors as v:
verrors.extend(v)

# validate_app_migrations(verrors, version_path, f'{schema}.app_migrations')
# validate_app_migrations(verrors, version_path, f'{apps_schema}.app_migrations')
# FIXME: Add validation for app migrations

verrors.check()
Expand Down
2 changes: 1 addition & 1 deletion apps_validation/validation/validate_catalog.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion apps_validation/validation/validate_dev_directory.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
12 changes: 6 additions & 6 deletions apps_validation/validation/validate_questions.py
Original file line number Diff line number Diff line change
@@ -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

Expand Down Expand Up @@ -49,7 +49,7 @@ def validate_questions_yaml(questions_yaml_path: str, schema: str):
if not isinstance(portal_type, str):
verrors.add(error_schema, 'Portal type must be a string')
if not isinstance(portal_schema, dict):
verrors.add(error_schema, 'Portal schema must be a dictionary')
verrors.add(error_schema, 'Portal apps_schema must be a dictionary')
else:
validate_key_value_types(
portal_schema, (('protocols', list), ('host', list), ('ports', list), ('path', str, False)),
Expand Down Expand Up @@ -109,9 +109,9 @@ def validate_question(
variable_type = schema_data['type']

for condition, key, schema_str in (
(variable_type != 'list', 'subquestions', f'{schema}.schema.subquestions'),
(variable_type == 'list', 'items', f'{schema}.schema.items'),
(variable_type == 'dict', 'attrs', f'{schema}.schema.attrs'),
(variable_type != 'list', 'subquestions', f'{schema}.apps_schema.subquestions'),
(variable_type == 'list', 'items', f'{schema}.apps_schema.items'),
(variable_type == 'dict', 'attrs', f'{schema}.apps_schema.attrs'),
):
if not (condition and type(schema_data.get(key)) == list):
continue
Expand Down
2 changes: 1 addition & 1 deletion apps_validation/validation/validate_recommended_apps.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion catalog_reader/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ def get_app_version_details(
('chart_metadata', 'app.yaml', yaml.safe_load),
('app_metadata', 'metadata.yaml', yaml.safe_load),
('schema', 'questions.yaml', yaml.safe_load),
('readme', 'README.md', markdown.markdown), # TODO: Has been changed, make sure json schema accounts for it
('readme', 'README.md', markdown.markdown), # TODO: Has been changed, make sure json apps_schema accounts for it
('changelog', 'CHANGELOG.md', markdown.markdown),
):
if os.path.exists(os.path.join(version_path, filename)):
Expand Down
2 changes: 1 addition & 1 deletion catalog_reader/supported_version.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from apps_validation.schema.features import FEATURES
from apps_schema.features import FEATURES


def version_supported(version_details: dict) -> bool:
Expand Down
9 changes: 8 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -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={
Expand Down

0 comments on commit 4a9347f

Please sign in to comment.