Skip to content
Open
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 9 additions & 9 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
repos:
- repo: https://github.com/astral-sh/ruff-pre-commit
# Ruff version.
rev: v0.14.3
hooks:
# Run the linter.
- id: ruff
args: [ --fix ]
# Run the formatter.
- id: ruff-format
- repo: https://github.com/astral-sh/ruff-pre-commit
# Ruff version.
rev: v0.14.3
hooks:
# Run the linter.
- id: ruff-check
args: [--fix]
# Run the formatter.
- id: ruff-format
90 changes: 45 additions & 45 deletions datacontract/imports/odcs_helper.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
"""Helper functions for creating ODCS (OpenDataContractStandard) objects."""

from typing import Any, Dict, List
from __future__ import annotations
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The annotations import was added to resolve test failures due to the introduction of the | option type hint. Have just tested again with that commented out to reproduce the original test error, but it looks like a subsequent commit has removed the need for it altogether as the tests are passing.


from typing import Any

from open_data_contract_standard.model import (
CustomProperty,
Expand All @@ -12,8 +14,8 @@


def create_odcs(
id: str = None,
name: str = None,
id: str | None = None,
name: str | None = None,
version: str = "1.0.0",
status: str = "draft",
) -> OpenDataContractStandard:
Expand All @@ -31,9 +33,9 @@ def create_odcs(
def create_schema_object(
name: str,
physical_type: str = "table",
description: str = None,
business_name: str = None,
properties: List[SchemaProperty] = None,
description: str | None = None,
business_name: str | None = None,
properties: list[SchemaProperty] | None = None,
) -> SchemaObject:
"""Create a SchemaObject (equivalent to DCS Model)."""
schema = SchemaObject(
Expand All @@ -54,28 +56,28 @@ def create_schema_object(
def create_property(
name: str,
logical_type: str,
physical_type: str = None,
description: str = None,
required: bool = None,
primary_key: bool = None,
primary_key_position: int = None,
unique: bool = None,
classification: str = None,
tags: List[str] = None,
examples: List[Any] = None,
min_length: int = None,
max_length: int = None,
pattern: str = None,
minimum: float = None,
maximum: float = None,
exclusive_minimum: float = None,
exclusive_maximum: float = None,
precision: int = None,
scale: int = None,
format: str = None,
properties: List["SchemaProperty"] = None,
items: "SchemaProperty" = None,
custom_properties: Dict[str, Any] = None,
physical_type: str | None = None,
description: str | None = None,
required: bool = False,
primary_key: bool = False,
primary_key_position: int | None = None,
unique: bool = False,
classification: str | None = None,
tags: list[str] | None = None,
examples: list[Any] | None = None,
min_length: int | None = None,
max_length: int | None = None,
pattern: str | None = None,
minimum: float | None = None,
maximum: float | None = None,
exclusive_minimum: float | None = None,
exclusive_maximum: float | None = None,
precision: int | None = None,
scale: int | None = None,
format: str | None = None,
properties: list[SchemaProperty] | None = None,
items: SchemaProperty | None = None,
custom_properties: dict[str, Any] | None = None,
) -> SchemaProperty:
"""Create a SchemaProperty (equivalent to DCS Field)."""
prop = SchemaProperty(name=name)
Expand All @@ -85,7 +87,7 @@ def create_property(
prop.physicalType = physical_type
if description:
prop.description = description
if required is not None:
if required:
prop.required = required
if primary_key:
prop.primaryKey = primary_key
Expand Down Expand Up @@ -130,29 +132,27 @@ def create_property(

# Custom properties
if custom_properties:
prop.customProperties = [
CustomProperty(property=k, value=v) for k, v in custom_properties.items()
]
prop.customProperties = [CustomProperty(property=k, value=v) for k, v in custom_properties.items()]

return prop


def create_server(
name: str,
server_type: str,
environment: str = None,
host: str = None,
port: int = None,
database: str = None,
schema: str = None,
account: str = None,
project: str = None,
dataset: str = None,
path: str = None,
location: str = None,
catalog: str = None,
topic: str = None,
format: str = None,
environment: str | None = None,
host: str | None = None,
port: int | None = None,
database: str | None = None,
schema: str | None = None,
account: str | None = None,
project: str | None = None,
dataset: str | None = None,
path: str | None = None,
location: str | None = None,
catalog: str | None = None,
topic: str | None = None,
format: str | None = None,
) -> Server:
"""Create a Server object."""
server = Server(server=name, type=server_type)
Expand Down
Loading