Skip to content

Commit

Permalink
#2291: Extract LBDatafile schema to separate python file
Browse files Browse the repository at this point in the history
  • Loading branch information
thearusable committed Jun 25, 2024
1 parent 8da76ec commit 6221608
Show file tree
Hide file tree
Showing 3 changed files with 88 additions and 86 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ compile_commands.json
*.lo
*.o
*.obj
*.pyc

# Precompiled Headers
*.gch
Expand Down
89 changes: 3 additions & 86 deletions scripts/JSON_data_files_validator.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@

import brotli
from schema import And, Optional, Schema

# Import VT related schemas
import LBDatafile_schema

def exc_handler(exception_type, exception, traceback):
""" Exception handler for hiding traceback. """
Expand All @@ -38,91 +39,7 @@ def get_error_message(iterable_collection: Iterable) -> str:
def _get_valid_schema(self) -> Schema:
""" Returns representation of a valid schema
"""
allowed_types_data = ("LBDatafile")
valid_schema_data = Schema(
{
Optional('type'): And(str, lambda a: a in allowed_types_data,
error=f"{self.get_error_message(allowed_types_data)} must be chosen"),
Optional('metadata'): {
Optional('type'): And(str, lambda a: a in allowed_types_data,
error=f"{self.get_error_message(allowed_types_data)} must be chosen"),
Optional('rank'): int,
Optional('shared_node'): {
'id': int,
'size': int,
'rank': int,
'num_nodes': int,
},
Optional('phases'): {
Optional('count'): int,
'skipped': {
'list': [int],
'range': [[int]],
},
'identical_to_previous': {
'list': [int],
'range': [[int]],
},
},
Optional('attributes'): dict
},
'phases': [
{
'id': int,
'tasks': [
{
'entity': {
Optional('collection_id'): int,
'home': int,
'id': int,
Optional('index'): [int],
'type': str,
'migratable': bool,
Optional('objgroup_id'): int
},
'node': int,
'resource': str,
Optional('subphases'): [
{
'id': int,
'time': float,
}
],
'time': float,
Optional('user_defined'): dict,
Optional('attributes'): dict
},
],
Optional('communications'): [
{
'type': str,
'to': {
'type': str,
'id': int,
Optional('home'): int,
Optional('collection_id'): int,
Optional('migratable'): bool,
Optional('index'): [int],
Optional('objgroup_id'): int,
},
'messages': int,
'from': {
'type': str,
'id': int,
Optional('home'): int,
Optional('collection_id'): int,
Optional('migratable'): bool,
Optional('index'): [int],
Optional('objgroup_id'): int,
},
'bytes': float
}
],
Optional('user_defined'): dict
},
]
}
)
valid_schema_data = LBDatafile_schema.LBDatafile_schema
allowed_types_stats = ("LBStatsfile")
valid_schema_stats = Schema(
{
Expand Down
84 changes: 84 additions & 0 deletions scripts/LBDatafile_schema.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
from schema import And, Optional, Schema

LBDatafile_schema = Schema(
{
Optional('type'): And(str, "LBDatafile", error="'LBDatafile' must be chosen."),
Optional('metadata'): {
Optional('type'): And(str, "LBDatafile", error="'LBDatafile' must be chosen."),
Optional('rank'): int,
Optional('shared_node'): {
'id': int,
'size': int,
'rank': int,
'num_nodes': int,
},
Optional('phases'): {
Optional('count'): int,
'skipped': {
'list': [int],
'range': [[int]],
},
'identical_to_previous': {
'list': [int],
'range': [[int]],
},
},
Optional('attributes'): dict
},
'phases': [
{
'id': int,
'tasks': [
{
'entity': {
Optional('collection_id'): int,
'home': int,
'id': int,
Optional('index'): [int],
'type': str,
'migratable': bool,
Optional('objgroup_id'): int
},
'node': int,
'resource': str,
Optional('subphases'): [
{
'id': int,
'time': float,
}
],
'time': float,
Optional('user_defined'): dict,
Optional('attributes'): dict
},
],
Optional('communications'): [
{
'type': str,
'to': {
'type': str,
'id': int,
Optional('home'): int,
Optional('collection_id'): int,
Optional('migratable'): bool,
Optional('index'): [int],
Optional('objgroup_id'): int,
},
'messages': int,
'from': {
'type': str,
'id': int,
Optional('home'): int,
Optional('collection_id'): int,
Optional('migratable'): bool,
Optional('index'): [int],
Optional('objgroup_id'): int,
},
'bytes': float
}
],
Optional('user_defined'): dict
},
]
}
)

0 comments on commit 6221608

Please sign in to comment.