diff --git a/README.md b/README.md index b8556e04..4d7170de 100644 --- a/README.md +++ b/README.md @@ -909,7 +909,7 @@ source venv/bin/activate pip install --upgrade pip setuptools wheel pip install -e '.[dev]' ruff check --fix -ruff format --check +ruff format pytest ``` diff --git a/datacontract/catalog/catalog.py b/datacontract/catalog/catalog.py index 1de3c264..952af153 100644 --- a/datacontract/catalog/catalog.py +++ b/datacontract/catalog/catalog.py @@ -1,13 +1,14 @@ from dataclasses import dataclass +from datetime import datetime from pathlib import Path -from jinja2 import PackageLoader, Environment, select_autoescape import pytz -from datetime import datetime +from jinja2 import PackageLoader, Environment, select_autoescape -from datacontract.export.html_export import get_version from datacontract.data_contract import DataContract -from datacontract.model.data_contract_specification import DataContractSpecification +from datacontract.export.html_export import get_version +from datacontract.model.data_contract_specification import \ + DataContractSpecification def create_data_contract_html(contracts, file: Path, path: Path): @@ -19,17 +20,20 @@ def create_data_contract_html(contracts, file: Path, path: Path): 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_link=file_without_suffix, - spec=spec, - )) + contracts.append( + DataContractView( + html_filepath=html_filepath, + html_link=file_without_suffix, + spec=spec, + ) + ) print(f"Created {html_filepath}") @dataclass class DataContractView: """Class for keeping track of an item in inventory.""" + html_filepath: Path html_link: Path spec: DataContractSpecification @@ -53,9 +57,9 @@ def create_index_html(contracts, path): style_content, _, _ = package_loader.get_source(env, "style/output.css") - tz = pytz.timezone('UTC') + tz = pytz.timezone("UTC") now = datetime.now(tz) - formatted_date = now.strftime('%d %b %Y %H:%M:%S UTC') + formatted_date = now.strftime("%d %b %Y %H:%M:%S UTC") datacontract_cli_version = get_version() # Render the template with necessary data @@ -67,4 +71,4 @@ def create_index_html(contracts, path): contracts_size=len(contracts), ) f.write(html_string) - print(f"Created {index_filepath}") \ No newline at end of file + print(f"Created {index_filepath}") diff --git a/datacontract/cli.py b/datacontract/cli.py index 8fc06bc7..8151d741 100644 --- a/datacontract/cli.py +++ b/datacontract/cli.py @@ -221,7 +221,9 @@ def import_( @app.command(name="catalog") def catalog( - files: Annotated[Optional[str], typer.Option(help="Glob pattern for the data contract files to include in the catalog.")] = "*.yaml", + files: Annotated[ + Optional[str], typer.Option(help="Glob pattern for the data contract files to include in the catalog.") + ] = "*.yaml", output: Annotated[Optional[str], typer.Option(help="Output directory for the catalog html files.")] = "catalog/", ): """ diff --git a/datacontract/data_contract.py b/datacontract/data_contract.py index dbddbbc0..46493274 100644 --- a/datacontract/data_contract.py +++ b/datacontract/data_contract.py @@ -6,16 +6,20 @@ import yaml from pyspark.sql import SparkSession -from datacontract.breaking.breaking import models_breaking_changes, quality_breaking_changes +from datacontract.breaking.breaking import models_breaking_changes, \ + quality_breaking_changes from datacontract.engines.datacontract.check_that_datacontract_contains_valid_servers_configuration import ( check_that_datacontract_contains_valid_server_configuration, ) -from datacontract.engines.fastjsonschema.check_jsonschema import check_jsonschema +from datacontract.engines.fastjsonschema.check_jsonschema import \ + check_jsonschema from datacontract.engines.soda.check_soda_execute import check_soda_execute from datacontract.export.avro_converter import to_avro_schema_json from datacontract.export.avro_idl_converter import to_avro_idl -from datacontract.export.dbt_converter import to_dbt_models_yaml, to_dbt_sources_yaml, to_dbt_staging_sql -from datacontract.export.great_expectations_converter import to_great_expectations +from datacontract.export.dbt_converter import to_dbt_models_yaml, \ + to_dbt_sources_yaml, to_dbt_staging_sql +from datacontract.export.great_expectations_converter import \ + to_great_expectations from datacontract.export.html_export import to_html from datacontract.export.jsonschema_converter import to_jsonschema_json from datacontract.export.odcs_converter import to_odcs_yaml @@ -26,20 +30,26 @@ from datacontract.export.sql_converter import to_sql_ddl, to_sql_query from datacontract.export.terraform_converter import to_terraform from datacontract.imports.avro_importer import import_avro -from datacontract.imports.sql_importer import import_sql from datacontract.imports.glue_importer import import_glue -from datacontract.integration.publish_datamesh_manager import publish_datamesh_manager +from datacontract.imports.sql_importer import import_sql +from datacontract.integration.publish_datamesh_manager import \ + publish_datamesh_manager from datacontract.integration.publish_opentelemetry import publish_opentelemetry from datacontract.lint import resolve from datacontract.lint.linters.description_linter import DescriptionLinter from datacontract.lint.linters.example_model_linter import ExampleModelLinter from datacontract.lint.linters.field_pattern_linter import FieldPatternLinter -from datacontract.lint.linters.field_reference_linter import FieldReferenceLinter +from datacontract.lint.linters.field_reference_linter import \ + FieldReferenceLinter from datacontract.lint.linters.notice_period_linter import NoticePeriodLinter -from datacontract.lint.linters.quality_schema_linter import QualityUsesSchemaLinter -from datacontract.lint.linters.valid_constraints_linter import ValidFieldConstraintsLinter -from datacontract.model.breaking_change import BreakingChanges, BreakingChange, Severity -from datacontract.model.data_contract_specification import DataContractSpecification, Server +from datacontract.lint.linters.quality_schema_linter import \ + QualityUsesSchemaLinter +from datacontract.lint.linters.valid_constraints_linter import \ + ValidFieldConstraintsLinter +from datacontract.model.breaking_change import BreakingChanges, BreakingChange, \ + Severity +from datacontract.model.data_contract_specification import \ + DataContractSpecification, Server from datacontract.model.exceptions import DataContractException from datacontract.model.run import Run, Check @@ -267,12 +277,16 @@ def get_data_contract_specification(self) -> DataContractSpecification: data_contract=self._data_contract, schema_location=self._schema_location, inline_definitions=self._inline_definitions, - inline_quality=self._inline_quality + inline_quality=self._inline_quality, ) def export(self, export_format, model: str = "all", rdf_base: str = None, sql_server_type: str = "auto") -> str: data_contract = resolve.resolve_data_contract( - self._data_contract_file, self._data_contract_str, self._data_contract, inline_definitions=True, inline_quality=True + self._data_contract_file, + self._data_contract_str, + self._data_contract, + inline_definitions=True, + inline_quality=True, ) if export_format == "jsonschema": if data_contract.models is None: diff --git a/datacontract/lint/resolve.py b/datacontract/lint/resolve.py index cf24640a..2616c1c1 100644 --- a/datacontract/lint/resolve.py +++ b/datacontract/lint/resolve.py @@ -8,7 +8,8 @@ from datacontract.lint.files import read_file from datacontract.lint.schema import fetch_schema from datacontract.lint.urls import fetch_resource -from datacontract.model.data_contract_specification import DataContractSpecification, Definition, Quality +from datacontract.model.data_contract_specification import \ + DataContractSpecification, Definition, Quality from datacontract.model.exceptions import DataContractException @@ -21,7 +22,9 @@ def resolve_data_contract( inline_quality: bool = False, ) -> DataContractSpecification: if data_contract_location is not None: - return resolve_data_contract_from_location(data_contract_location, schema_location, inline_definitions, inline_quality) + return resolve_data_contract_from_location( + data_contract_location, schema_location, inline_definitions, inline_quality + ) elif data_contract_str is not None: return resolve_data_contract_from_str(data_contract_str, schema_location, inline_definitions, inline_quality) elif data_contract is not None: diff --git a/tests/test_catalog.py b/tests/test_catalog.py index cf1be610..b677ea11 100644 --- a/tests/test_catalog.py +++ b/tests/test_catalog.py @@ -14,4 +14,4 @@ def test_cli(tmp_path: PosixPath): result = runner.invoke(app, ["catalog", "--files", "fixtures/catalog/*.yaml", "--output", tmp_path]) assert result.exit_code == 0 assert os.path.exists(tmp_path / "index.html") - assert os.path.exists(tmp_path / "fixtures/catalog/datacontract-1.html") \ No newline at end of file + assert os.path.exists(tmp_path / "fixtures/catalog/datacontract-1.html")