From 355a1bdc839ede3169680d78e5b24e43776243b0 Mon Sep 17 00:00:00 2001 From: Ernest Hill Date: Mon, 5 Jun 2023 17:58:49 +0300 Subject: [PATCH] Update jinja templates --- pyatlan/generator/templates/entity.jinja2 | 69 +++------- pyatlan/generator/templates/structs.jinja2 | 2 +- pyatlan/model/assets.py | 40 +++++- pyatlan/model/structs.py | 150 +++++++++++---------- 4 files changed, 131 insertions(+), 130 deletions(-) diff --git a/pyatlan/generator/templates/entity.jinja2 b/pyatlan/generator/templates/entity.jinja2 index 1f9bef27a..e70e7b7e8 100644 --- a/pyatlan/generator/templates/entity.jinja2 +++ b/pyatlan/generator/templates/entity.jinja2 @@ -10,15 +10,10 @@ from io import StringIO from typing import Any, ClassVar, Dict, List, Optional, TypeVar from urllib.parse import quote, unquote -from pydantic import Field, StrictStr, root_validator, validator +from pydantic import Field, PrivateAttr, StrictStr, root_validator, validator -from pyatlan.model.core import ( - Announcement, - AtlanObject, - Classification, - CustomMetadata, - Meaning, -) +from pyatlan.model.core import Announcement, AtlanObject, Classification, Meaning +from pyatlan.model.custom_metadata import CustomMetadataDict, CustomMetadataProxy from pyatlan.model.enums import ( ADLSAccessTier, ADLSAccountStatus, @@ -90,9 +85,16 @@ SelfAsset = TypeVar("SelfAsset", bound="Asset") class {{ entity_def.name }}({{super_classes[0]}} {%- if "Asset" in super_classes %}, type_name='{{ entity_def.name }}'{% endif %}): """Description""" {% if entity_def.name == "Referenceable" %} - def __init__(__pydantic_self__, **data:Any)->None: + def __init__(__pydantic_self__, **data: Any) -> None: super().__init__(**data) __pydantic_self__.__fields_set__.update(["attributes", "type_name"]) + __pydantic_self__._metadata_proxy = CustomMetadataProxy( + __pydantic_self__.business_attributes + ) + + def json(self, *args, **kwargs) -> str: + self.business_attributes = self._metadata_proxy.business_attributes + return super().json(**kwargs) {% endif %} def __setattr__(self, name, value): if name in {{ entity_def.name }}._convience_properties: @@ -117,6 +119,7 @@ class {{ entity_def.name }}({{super_classes[0]}} {%- if "Asset" in super_classes def validate_required(self): pass + _metadata_proxy: CustomMetadataProxy = PrivateAttr() attributes: '{{entity_def.name}}.Attributes' = Field( default_factory = lambda : {{entity_def.name}}.Attributes(), description='Map of attributes in the instance and their values. The specific keys of this map will vary ' @@ -219,51 +222,15 @@ class {{ entity_def.name }}({{super_classes[0]}} {%- if "Asset" in super_classes if not self.create_time or self.created_by: self.attributes.validate_required() - def get_custom_metadata(self, name: str) -> CustomMetadata: - from pyatlan.cache.custom_metadata_cache import CustomMetadataCache + def get_custom_metadata(self, name: str) -> CustomMetadataDict: + return self._metadata_proxy.get_custom_metadata(name=name) - ba_id = CustomMetadataCache.get_id_for_name(name) - if ba_id is None: - raise ValueError(f"No custom metadata with the name: {name} exist") - for a_type in CustomMetadataCache.types_by_asset[self.type_name]: - if ( - hasattr(a_type, "_meta_data_type_name") - and a_type._meta_data_type_name == name - ): - break - else: - raise ValueError( - f"Custom metadata attributes {name} are not applicable to {self.type_name}" - ) - if ba_type := CustomMetadataCache.get_type_for_id(ba_id): - return ( - ba_type(self.business_attributes[ba_id]) - if self.business_attributes and ba_id in self.business_attributes - else ba_type() - ) - else: - raise ValueError( - f"Custom metadata attributes {name} are not applicable to {self.type_name}" - ) + def set_custom_metadata(self, custom_metadata: CustomMetadataDict): + return self._metadata_proxy.set_custom_metadata(custom_metadata=custom_metadata) - def set_custom_metadata(self, custom_metadata: CustomMetadata) -> None: - from pyatlan.cache.custom_metadata_cache import CustomMetadataCache + def flush_custom_metadata(self): + self.business_attributes = self._metadata_proxy.business_attributes - if not isinstance(custom_metadata, CustomMetadata): - raise ValueError( - "business_attributes must be an instance of CustomMetadata" - ) - if ( - type(custom_metadata) - not in CustomMetadataCache.types_by_asset[self.type_name] - ): - raise ValueError( - f"Business attributes {custom_metadata._meta_data_type_name} are not applicable to {self.type_name}" - ) - ba_dict = dict(custom_metadata) - if not self.business_attributes: - self.business_attributes = {} - self.business_attributes[custom_metadata._meta_data_type_id] = ba_dict {%- else %} {%- if entity_def.name == "Asset" %} diff --git a/pyatlan/generator/templates/structs.jinja2 b/pyatlan/generator/templates/structs.jinja2 index f987b4672..bf77fbd02 100644 --- a/pyatlan/generator/templates/structs.jinja2 +++ b/pyatlan/generator/templates/structs.jinja2 @@ -43,6 +43,6 @@ class {{struct.name}}(AtlanObject): {% endif %} {%- for attribute_def in struct.attribute_defs %} {%- set type = attribute_def.type_name | get_type %} - {{attribute_def.name | to_snake_case }}: {% if attribute_def.is_optional %}Optional[{% endif %}{{type}}{% if attribute_def.is_optional %}]{% endif %} = Field(None, description='' , alias='{{attribute_def.name}}') + {{attribute_def.name | to_snake_case }}: {% if attribute_def.is_optional %}Optional[{% endif %}'{{type}}'{% if attribute_def.is_optional %}]{% endif %} = Field(None, description='' , alias='{{attribute_def.name}}') {%- endfor %} {% endfor %} diff --git a/pyatlan/model/assets.py b/pyatlan/model/assets.py index bcb348515..ad95dbc1e 100644 --- a/pyatlan/model/assets.py +++ b/pyatlan/model/assets.py @@ -90,15 +90,15 @@ def __init__(__pydantic_self__, **data: Any) -> None: __pydantic_self__.business_attributes ) + def json(self, *args, **kwargs) -> str: + self.business_attributes = self._metadata_proxy.business_attributes + return super().json(**kwargs) + def __setattr__(self, name, value): if name in Referenceable._convience_properties: return object.__setattr__(self, name, value) super().__setattr__(name, value) - def json(self, *args, **kwargs) -> str: - self.business_attributes = self._metadata_proxy.business_attributes - return super().json(**kwargs) - _convience_properties: ClassVar[list[str]] = [ "qualified_name", "replicated_from", @@ -6456,7 +6456,7 @@ class Attributes(ObjectStore.Attributes): ) -class ADLS(ObjectStore): +class ADLS(Azure): """Description""" def __setattr__(self, name, value): @@ -6470,6 +6470,8 @@ def __setattr__(self, name, value): "azure_location", "adls_account_secondary_location", "azure_tags", + "input_to_processes", + "output_from_processes", ] @property @@ -6526,6 +6528,26 @@ def azure_tags(self, azure_tags: Optional[list[AzureTag]]): self.attributes = self.Attributes() self.attributes.azure_tags = azure_tags + @property + def input_to_processes(self) -> Optional[list[Process]]: + return self.attributes.input_to_processes + + @input_to_processes.setter + def input_to_processes(self, input_to_processes: Optional[list[Process]]): + if self.attributes is None: + self.attributes = self.Attributes() + self.attributes.input_to_processes = input_to_processes + + @property + def output_from_processes(self) -> Optional[list[Process]]: + return self.attributes.output_from_processes + + @output_from_processes.setter + def output_from_processes(self, output_from_processes: Optional[list[Process]]): + if self.attributes is None: + self.attributes = self.Attributes() + self.attributes.output_from_processes = output_from_processes + type_name: str = Field("ADLS", allow_mutation=False) @validator("type_name") @@ -6534,7 +6556,7 @@ def validate_type_name(cls, v): raise ValueError("must be ADLS") return v - class Attributes(ObjectStore.Attributes): + class Attributes(Azure.Attributes): adls_account_qualified_name: Optional[str] = Field( None, description="", alias="adlsAccountQualifiedName" ) @@ -6550,6 +6572,12 @@ class Attributes(ObjectStore.Attributes): azure_tags: Optional[list[AzureTag]] = Field( None, description="", alias="azureTags" ) + input_to_processes: Optional[list[Process]] = Field( + None, description="", alias="inputToProcesses" + ) # relationship + output_from_processes: Optional[list[Process]] = Field( + None, description="", alias="outputFromProcesses" + ) # relationship attributes: "ADLS.Attributes" = Field( default_factory=lambda: ADLS.Attributes(), diff --git a/pyatlan/model/structs.py b/pyatlan/model/structs.py index 385b6cee1..2336a9393 100644 --- a/pyatlan/model/structs.py +++ b/pyatlan/model/structs.py @@ -16,16 +16,16 @@ class MCRuleSchedule(AtlanObject): """Description""" - mc_rule_schedule_type: Optional[str] = Field( + mc_rule_schedule_type: Optional["str"] = Field( None, description="", alias="mcRuleScheduleType" ) - mc_rule_schedule_interval_in_minutes: Optional[int] = Field( + mc_rule_schedule_interval_in_minutes: Optional["int"] = Field( None, description="", alias="mcRuleScheduleIntervalInMinutes" ) - mc_rule_schedule_start_time: Optional[datetime] = Field( + mc_rule_schedule_start_time: Optional["datetime"] = Field( None, description="", alias="mcRuleScheduleStartTime" ) - mc_rule_schedule_crontab: Optional[str] = Field( + mc_rule_schedule_crontab: Optional["str"] = Field( None, description="", alias="mcRuleScheduleCrontab" ) @@ -33,10 +33,10 @@ class MCRuleSchedule(AtlanObject): class AwsCloudWatchMetric(AtlanObject): """Description""" - aws_cloud_watch_metric_name: str = Field( + aws_cloud_watch_metric_name: "str" = Field( None, description="", alias="awsCloudWatchMetricName" ) - aws_cloud_watch_metric_scope: str = Field( + aws_cloud_watch_metric_scope: "str" = Field( None, description="", alias="awsCloudWatchMetricScope" ) @@ -44,17 +44,19 @@ class AwsCloudWatchMetric(AtlanObject): class Histogram(AtlanObject): """Description""" - boundaries: set[float] = Field(None, description="", alias="boundaries") - frequencies: set[float] = Field(None, description="", alias="frequencies") + boundaries: "set[float]" = Field(None, description="", alias="boundaries") + frequencies: "set[float]" = Field(None, description="", alias="frequencies") class KafkaTopicConsumption(AtlanObject): """Description""" - topic_name: Optional[str] = Field(None, description="", alias="topicName") - topic_partition: Optional[str] = Field(None, description="", alias="topicPartition") - topic_lag: Optional[int] = Field(None, description="", alias="topicLag") - topic_current_offset: Optional[int] = Field( + topic_name: Optional["str"] = Field(None, description="", alias="topicName") + topic_partition: Optional["str"] = Field( + None, description="", alias="topicPartition" + ) + topic_lag: Optional["int"] = Field(None, description="", alias="topicLag") + topic_current_offset: Optional["int"] = Field( None, description="", alias="topicCurrentOffset" ) @@ -62,8 +64,8 @@ class KafkaTopicConsumption(AtlanObject): class ColumnValueFrequencyMap(AtlanObject): """Description""" - column_value: Optional[str] = Field(None, description="", alias="columnValue") - column_value_frequency: Optional[int] = Field( + column_value: Optional["str"] = Field(None, description="", alias="columnValue") + column_value_frequency: Optional["int"] = Field( None, description="", alias="columnValueFrequency" ) @@ -96,67 +98,71 @@ def create( else badge_condition_colorhex, ) - badge_condition_operator: Optional[str] = Field( + badge_condition_operator: Optional["str"] = Field( None, description="", alias="badgeConditionOperator" ) - badge_condition_value: Optional[str] = Field( + badge_condition_value: Optional["str"] = Field( None, description="", alias="badgeConditionValue" ) - badge_condition_colorhex: Optional[str] = Field( + badge_condition_colorhex: Optional["str"] = Field( None, description="", alias="badgeConditionColorhex" ) -class SourceTagAttachmentValue(AtlanObject): - """Description""" - - tag_attachment_key: Optional[str] = Field( - None, description="", alias="tagAttachmentKey" - ) - tag_attachment_value: Optional[str] = Field( - None, description="", alias="tagAttachmentValue" - ) - - class SourceTagAttachment(AtlanObject): """Description""" - source_tag_name: Optional[str] = Field(None, description="", alias="sourceTagName") - source_tag_qualified_name: Optional[str] = Field( + source_tag_name: Optional["str"] = Field( + None, description="", alias="sourceTagName" + ) + source_tag_qualified_name: Optional["str"] = Field( None, description="", alias="sourceTagQualifiedName" ) - source_tag_guid: Optional[str] = Field(None, description="", alias="sourceTagGuid") - source_tag_connector_name: Optional[str] = Field( + source_tag_guid: Optional["str"] = Field( + None, description="", alias="sourceTagGuid" + ) + source_tag_connector_name: Optional["str"] = Field( None, description="", alias="sourceTagConnectorName" ) - source_tag_value: Optional[list[SourceTagAttachmentValue]] = Field( + source_tag_value: Optional["list[SourceTagAttachmentValue]"] = Field( None, description="", alias="sourceTagValue" ) - is_source_tag_synced: Optional[bool] = Field( + is_source_tag_synced: Optional["bool"] = Field( None, description="", alias="isSourceTagSynced" ) - source_tag_sync_timestamp: Optional[datetime] = Field( + source_tag_sync_timestamp: Optional["datetime"] = Field( None, description="", alias="sourceTagSyncTimestamp" ) - source_tag_sync_error: Optional[str] = Field( + source_tag_sync_error: Optional["str"] = Field( None, description="", alias="sourceTagSyncError" ) +class SourceTagAttachmentValue(AtlanObject): + """Description""" + + tag_attachment_key: Optional["str"] = Field( + None, description="", alias="tagAttachmentKey" + ) + tag_attachment_value: Optional["str"] = Field( + None, description="", alias="tagAttachmentValue" + ) + + class AzureTag(AtlanObject): """Description""" - azure_tag_key: str = Field(None, description="", alias="azureTagKey") - azure_tag_value: str = Field(None, description="", alias="azureTagValue") + azure_tag_key: "str" = Field(None, description="", alias="azureTagKey") + azure_tag_value: "str" = Field(None, description="", alias="azureTagValue") class AuthPolicyCondition(AtlanObject): """Description""" - policy_condition_type: str = Field( + policy_condition_type: "str" = Field( None, description="", alias="policyConditionType" ) - policy_condition_values: set[str] = Field( + policy_condition_values: "set[str]" = Field( None, description="", alias="policyConditionValues" ) @@ -164,23 +170,23 @@ class AuthPolicyCondition(AtlanObject): class AwsTag(AtlanObject): """Description""" - aws_tag_key: str = Field(None, description="", alias="awsTagKey") - aws_tag_value: str = Field(None, description="", alias="awsTagValue") + aws_tag_key: "str" = Field(None, description="", alias="awsTagKey") + aws_tag_value: "str" = Field(None, description="", alias="awsTagValue") class DbtMetricFilter(AtlanObject): """Description""" - dbt_metric_filter_column_qualified_name: Optional[str] = Field( + dbt_metric_filter_column_qualified_name: Optional["str"] = Field( None, description="", alias="dbtMetricFilterColumnQualifiedName" ) - dbt_metric_filter_field: Optional[str] = Field( + dbt_metric_filter_field: Optional["str"] = Field( None, description="", alias="dbtMetricFilterField" ) - dbt_metric_filter_operator: Optional[str] = Field( + dbt_metric_filter_operator: Optional["str"] = Field( None, description="", alias="dbtMetricFilterOperator" ) - dbt_metric_filter_value: Optional[str] = Field( + dbt_metric_filter_value: Optional["str"] = Field( None, description="", alias="dbtMetricFilterValue" ) @@ -188,20 +194,20 @@ class DbtMetricFilter(AtlanObject): class GoogleTag(AtlanObject): """Description""" - google_tag_key: str = Field(None, description="", alias="googleTagKey") - google_tag_value: str = Field(None, description="", alias="googleTagValue") + google_tag_key: "str" = Field(None, description="", alias="googleTagKey") + google_tag_value: "str" = Field(None, description="", alias="googleTagValue") class AuthPolicyValiditySchedule(AtlanObject): """Description""" - policy_validity_schedule_start_time: str = Field( + policy_validity_schedule_start_time: "str" = Field( None, description="", alias="policyValidityScheduleStartTime" ) - policy_validity_schedule_end_time: str = Field( + policy_validity_schedule_end_time: "str" = Field( None, description="", alias="policyValidityScheduleEndTime" ) - policy_validity_schedule_timezone: str = Field( + policy_validity_schedule_timezone: "str" = Field( None, description="", alias="policyValidityScheduleTimezone" ) @@ -209,22 +215,22 @@ class AuthPolicyValiditySchedule(AtlanObject): class MCRuleComparison(AtlanObject): """Description""" - mc_rule_comparison_type: Optional[str] = Field( + mc_rule_comparison_type: Optional["str"] = Field( None, description="", alias="mcRuleComparisonType" ) - mc_rule_comparison_field: Optional[str] = Field( + mc_rule_comparison_field: Optional["str"] = Field( None, description="", alias="mcRuleComparisonField" ) - mc_rule_comparison_metric: Optional[str] = Field( + mc_rule_comparison_metric: Optional["str"] = Field( None, description="", alias="mcRuleComparisonMetric" ) - mc_rule_comparison_operator: Optional[str] = Field( + mc_rule_comparison_operator: Optional["str"] = Field( None, description="", alias="mcRuleComparisonOperator" ) - mc_rule_comparison_threshold: Optional[float] = Field( + mc_rule_comparison_threshold: Optional["float"] = Field( None, description="", alias="mcRuleComparisonThreshold" ) - mc_rule_comparison_is_threshold_relative: Optional[bool] = Field( + mc_rule_comparison_is_threshold_relative: Optional["bool"] = Field( None, description="", alias="mcRuleComparisonIsThresholdRelative" ) @@ -232,37 +238,37 @@ class MCRuleComparison(AtlanObject): class GoogleLabel(AtlanObject): """Description""" - google_label_key: str = Field(None, description="", alias="googleLabelKey") - google_label_value: str = Field(None, description="", alias="googleLabelValue") + google_label_key: "str" = Field(None, description="", alias="googleLabelKey") + google_label_value: "str" = Field(None, description="", alias="googleLabelValue") class PopularityInsights(AtlanObject): """Description""" - record_user: Optional[str] = Field(None, description="", alias="recordUser") - record_query: Optional[str] = Field(None, description="", alias="recordQuery") - record_query_duration: Optional[int] = Field( + record_user: Optional["str"] = Field(None, description="", alias="recordUser") + record_query: Optional["str"] = Field(None, description="", alias="recordQuery") + record_query_duration: Optional["int"] = Field( None, description="", alias="recordQueryDuration" ) - record_query_count: Optional[int] = Field( + record_query_count: Optional["int"] = Field( None, description="", alias="recordQueryCount" ) - record_total_user_count: Optional[int] = Field( + record_total_user_count: Optional["int"] = Field( None, description="", alias="recordTotalUserCount" ) - record_compute_cost: Optional[float] = Field( + record_compute_cost: Optional["float"] = Field( None, description="", alias="recordComputeCost" ) - record_max_compute_cost: Optional[float] = Field( + record_max_compute_cost: Optional["float"] = Field( None, description="", alias="recordMaxComputeCost" ) - record_compute_cost_unit: Optional[SourceCostUnitType] = Field( + record_compute_cost_unit: Optional["SourceCostUnitType"] = Field( None, description="", alias="recordComputeCostUnit" ) - record_last_timestamp: Optional[datetime] = Field( + record_last_timestamp: Optional["datetime"] = Field( None, description="", alias="recordLastTimestamp" ) - record_warehouse: Optional[str] = Field( + record_warehouse: Optional["str"] = Field( None, description="", alias="recordWarehouse" ) @@ -270,12 +276,12 @@ class PopularityInsights(AtlanObject): class SourceTagAttribute(AtlanObject): """Description""" - tag_attribute_key: Optional[str] = Field( + tag_attribute_key: Optional["str"] = Field( None, description="", alias="tagAttributeKey" ) - tag_attribute_value: Optional[str] = Field( + tag_attribute_value: Optional["str"] = Field( None, description="", alias="tagAttributeValue" ) - tag_attribute_properties: Optional[dict[str, str]] = Field( + tag_attribute_properties: Optional["dict[str,str]"] = Field( None, description="", alias="tagAttributeProperties" )