Skip to content

Commit

Permalink
Ruff format
Browse files Browse the repository at this point in the history
  • Loading branch information
jochenchrist committed May 4, 2024
1 parent e9231f3 commit 4b43220
Show file tree
Hide file tree
Showing 6 changed files with 53 additions and 30 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
```
Expand Down
28 changes: 16 additions & 12 deletions datacontract/catalog/catalog.py
Original file line number Diff line number Diff line change
@@ -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):
Expand All @@ -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
Expand All @@ -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
Expand All @@ -67,4 +71,4 @@ def create_index_html(contracts, path):
contracts_size=len(contracts),
)
f.write(html_string)
print(f"Created {index_filepath}")
print(f"Created {index_filepath}")
4 changes: 3 additions & 1 deletion datacontract/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -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/",
):
"""
Expand Down
40 changes: 27 additions & 13 deletions datacontract/data_contract.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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

Expand Down Expand Up @@ -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:
Expand Down
7 changes: 5 additions & 2 deletions datacontract/lint/resolve.py
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand All @@ -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:
Expand Down
2 changes: 1 addition & 1 deletion tests/test_catalog.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
assert os.path.exists(tmp_path / "fixtures/catalog/datacontract-1.html")

0 comments on commit 4b43220

Please sign in to comment.