diff --git a/datacontract/catalog/catalog.py b/datacontract/catalog/catalog.py index 74703e60..4320aa0e 100644 --- a/datacontract/catalog/catalog.py +++ b/datacontract/catalog/catalog.py @@ -1,4 +1,5 @@ from dataclasses import dataclass +from pathlib import Path from jinja2 import PackageLoader, Environment, select_autoescape import pytz @@ -9,19 +10,18 @@ from datacontract.model.data_contract_specification import DataContractSpecification -def create_data_contract_html(contracts, file, path): +def create_data_contract_html(contracts, file: Path, path: Path): data_contract = DataContract(data_contract_file=f"{file.absolute()}", inline_definitions=True) html = data_contract.export(export_format="html") spec = data_contract.get_data_contract_specification() - # html_filename = f"dc-{spec.id}-{spec.info.version}.html" - file_without_suffix = file.name.removesuffix(".yaml").removesuffix(".yml") - html_filename = f"{file_without_suffix}.html" - html_filepath = path / html_filename + file_without_suffix = file.with_suffix(".html") + html_filepath = path / file_without_suffix + html_filepath.parent.mkdir(parents=True, exist_ok=True) with open(html_filepath, "w") as f: f.write(html) contracts.append(DataContractView( html_filepath=html_filepath, - html_filename=html_filename, + html_link=file_without_suffix, spec=spec, )) print(f"Created {html_filepath}") @@ -30,8 +30,8 @@ def create_data_contract_html(contracts, file, path): @dataclass class DataContractView: """Class for keeping track of an item in inventory.""" - html_filepath: str - html_filename: str + html_filepath: Path + html_link: Path spec: DataContractSpecification diff --git a/datacontract/cli.py b/datacontract/cli.py index 09716f46..0c8937d2 100644 --- a/datacontract/cli.py +++ b/datacontract/cli.py @@ -232,7 +232,10 @@ def catalog( contracts = [] for file in Path().glob(files): - create_data_contract_html(contracts, file, path) + try: + create_data_contract_html(contracts, file, path) + except Exception as e: + console.print(f"Skipped {file} due to error: {e}") create_index_html(contracts, path) diff --git a/datacontract/templates/index.html b/datacontract/templates/index.html index ed2fb0eb..9e5d5fc4 100644 --- a/datacontract/templates/index.html +++ b/datacontract/templates/index.html @@ -57,7 +57,7 @@