Skip to content

Commit

Permalink
Set up lattice directory structure for schema-source.
Browse files Browse the repository at this point in the history
  • Loading branch information
tanaya-mankad committed Jan 29, 2025
1 parent d1f3999 commit dc2bf75
Show file tree
Hide file tree
Showing 61 changed files with 1,137 additions and 204 deletions.
118 changes: 61 additions & 57 deletions dodo.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,54 +10,67 @@
from lattice import Lattice
from lattice.cpp.header_entry_extension_loader import load_extensions

DOIT_CONFIG = {'default_tasks': ['generate_meta_schemas', 'validate_schemas', 'generate_markdown']}

BUILD_PATH = os.path.join(os.path.dirname(__file__), 'build')
create_folder(BUILD_PATH)
SOURCE_PATH = os.path.join(os.path.dirname(__file__), 'schema-source')
DOCS_PATH = os.path.join(BUILD_PATH,"docs")
SCHEMA_PATH = os.path.join(BUILD_PATH,"schema")
HEADER_PATH = os.path.join(BUILD_PATH, "include")
CPP_PATH = os.path.join(BUILD_PATH, "cpp")
RENDERED_TEMPLATE_PATH = os.path.realpath(
os.path.join(BUILD_PATH,"rendered_template"))

data_model_205 = Lattice(SOURCE_PATH, BUILD_PATH, build_output_directory_name=None, build_validation=False)

def collect_target_files(target_dir, extension):
file_list = []
for file_name in sorted(os.listdir('schema-source')):
if '.schema.yaml' in file_name:
file_name_root = os.path.splitext(os.path.splitext(file_name)[0])[0]
file_list.append(os.path.join(target_dir,f'{file_name_root}.schema.{extension}'))
return file_list
def task_generate_meta_schemas():
'''Generates JSON meta-schema from source-schema and meta.schema.yaml'''
return {
'file_dep': [schema.file_path for schema in data_model_205.schemas],
'targets': [schema.meta_schema_path for schema in data_model_205.schemas],
'actions': [
(data_model_205.generate_meta_schemas,[])
],
'clean': True
}

def collect_lib_target_files(target_dir, extension):
file_list = []
for file_name in sorted(os.listdir('schema-source')):
if '.schema.yaml' in file_name:
file_name_root = snake_style(os.path.splitext(os.path.splitext(file_name)[0])[0])
file_list.append(os.path.join(target_dir,f'{file_name_root}.{extension}'))
file_list.append(os.path.join(target_dir,f'{file_name_root}_factory.{extension}'))
return file_list
def task_validate_schemas():
"""Validate the data model schemas against the JSON meta schema"""
return {
'file_dep': [schema.file_path for schema in data_model_205.schemas],
'task_dep': ["generate_meta_schemas"],
'actions': [(data_model_205.validate_schemas, [])]
}

def task_generate_json_schemas():
"""Generate JSON schemas"""
return {
"task_dep": [f"validate_schemas"],
"file_dep": [schema.file_path for schema in data_model_205.schemas]
+ [schema.meta_schema_path for schema in data_model_205.schemas],
"targets": [schema.json_schema_path for schema in data_model_205.schemas],
"actions": [(data_model_205.generate_json_schemas, [])],
"clean": True,
}

def task_validate_example_files():
"""Validate example files against JSON schema"""
return {
"file_dep": [schema.json_schema_path for schema in data_model_205.schemas]
+ data_model_205.examples,
"task_dep": [f"generate_json_schemas"],
"actions": [(data_model_205.validate_example_files, [])],
}

# def task_doc():
# '''Generates Markdown tables from source-schema'''
# return {
# 'file_dep': collect_source_files() + [
# os.path.join('schema205','markdown.py'),
# os.path.join('schema205','md','__init__.py'),
# os.path.join('schema205','md','schema_table.py'),
# os.path.join('schema205','md','grid_table.py'),
# ],
# 'targets': collect_target_files(DOCS_PATH,'md'),
# 'task_dep': ['validate_schemas'],
# 'actions': [
# (create_folder, [DOCS_PATH]),
# (schema205.markdown.write_dir,[SOURCE_PATH, DOCS_PATH])
# ],
# 'clean': True
# }

def task_generate_markdown():
"""Generate markdown documentation from templates"""
return {
"targets": [template.markdown_output_path for template in data_model_205.doc_templates],
"file_dep": [schema.file_path for schema in data_model_205.schemas]
+ [template.path for template in data_model_205.doc_templates],
"task_dep": [f"validate_schemas"],
"actions": [(data_model_205.generate_markdown_documents, [])],
"clean": True,
}

# def task_render_template():
# '''
Expand Down Expand Up @@ -86,26 +99,19 @@ def collect_lib_target_files(target_dir, extension):
# 'clean': True,
# }

def task_generate_meta_schemas():
'''Generates JSON meta-schema from source-schema and meta.schema.yaml'''
return {
'file_dep': [schema.file_path for schema in data_model_205.schemas],
'targets': [schema.meta_schema_path for schema in data_model_205.schemas],
'actions': [
(data_model_205.generate_meta_schemas,[])
],
'clean': True
}

def task_validate_schemas():
"""Validate the data model schemas against the JSON meta schema"""
def task_generate_web_docs():
"""Generate markdown documentation from templates"""
return {
'file_dep': [schema.file_path for schema in data_model_205.schemas],
'task_dep': ["generate_meta_schemas"],
'actions': [(data_model_205.validate_schemas, [])]
"task_dep": [f"validate_schemas", f"generate_json_schemas", f"validate_example_files"],
"file_dep": [schema.file_path for schema in data_model_205.schemas]
+ [template.path for template in data_model_205.doc_templates],
"targets": [Path(data_model_205.web_docs_directory_path, "public")],
"actions": [(data_model_205.generate_web_documentation, [])],
"clean": True,
}

def task_cpp():

def task_generate_cpp_code():
'''Generates CPP source files from common-schema'''
return {
'file_dep': [schema.file_path for schema in data_model_205.schemas],
Expand All @@ -120,9 +126,7 @@ def task_cpp():
'clean': True
}


# def task_test():
# '''Performs unit tests and example file validation tests'''
# return {
# 'task_dep': ['schema'],
# 'actions': ['pytest -v test']
# }
# """Run unit tests"""
# return {"actions": ["pytest -v test"]}
Loading

0 comments on commit dc2bf75

Please sign in to comment.