Skip to content
This repository has been archived by the owner on Jan 17, 2025. It is now read-only.

Commit

Permalink
Initial update to pydantic 1.10.12
Browse files Browse the repository at this point in the history
  • Loading branch information
ErnestoLoma committed Aug 31, 2023
1 parent 2069bfd commit bbeedb4
Show file tree
Hide file tree
Showing 73 changed files with 2,174 additions and 1,875 deletions.
1 change: 1 addition & 0 deletions mypy.ini
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
[mypy]
plugins = pydantic.mypy
1 change: 1 addition & 0 deletions pyatlan/client/atlan.py
Original file line number Diff line number Diff line change
Expand Up @@ -1259,6 +1259,7 @@ def purge_entity_by_guid(
guids.append(guid)
query_params = {"deleteType": AtlanDeleteType.PURGE.value, "guid": guids}
raw_json = self._call_api(DELETE_ENTITIES_BY_GUIDS, query_params=query_params)
print("raw_json", raw_json)
return AssetMutationResponse(**raw_json)

def delete_entity_by_guid(
Expand Down
39 changes: 39 additions & 0 deletions pyatlan/generator/separate.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import inspect
from enum import Enum
from pathlib import Path

import pyatlan.model.enums
from pyatlan.generator.class_generator import get_type, get_type_defs

PARENT = Path(__file__).parent
HEADER = """# SPDX-License-Identifier: Apache-2.0
# Copyright 2022 Atlan Pte. Ltd.
# Based on original code from https://github.com/apache/atlas (under Apache-2.0 license)
from datetime import datetime
from enum import Enum
"""
WARNING = """# **************************************
# CODE BELOW IS GENERATED NOT MODIFY **
# **************************************
"""

type_defs = get_type_defs()
enum_def_names = {get_type(enum_def.name) for enum_def in type_defs.enum_defs}
enums_by_name = {
cls_name: cls_obj
for cls_name, cls_obj in inspect.getmembers(pyatlan.model.enums)
if inspect.isclass(cls_obj) and issubclass(cls_obj, Enum) and cls_name != "Enum"
}
all_enum_names = set(enums_by_name.keys())
generated_enum_names = sorted(enum_def_names.intersection(all_enum_names))
manual_enum_names = sorted(all_enum_names.difference(enum_def_names))
with (PARENT / "generated").open("w") as output:
output.write(HEADER)
for name in manual_enum_names:
source = inspect.getsource(enums_by_name[name])
output.write(source)
output.write(WARNING)
for name in generated_enum_names:
source = inspect.getsource(enums_by_name[name])
output.write(source)
4 changes: 2 additions & 2 deletions pyatlan/generator/templates/macros.jinja2
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{%- macro gen_properties(attribute_defs) %}
{%- macro gen_properties(entity_def, attribute_defs) %}
_convenience_properties: ClassVar[list[str]] = [
{%- for attribute_def in attribute_defs %}
"{{ 'assigned_terms' if attribute_def.name == 'meanings' else attribute_def.name | to_snake_case }}",
Expand All @@ -16,7 +16,7 @@
@{{ property_name }}.setter
def {{ property_name }}(self, {{ property_name }}:{{ property_type }}):
if self.attributes is None:
self.attributes = self.Attributes()
self.attributes = self.Attributes({% if entity_def.name != "Referenceable" %}name=""{% endif %})
self.attributes.{{ attribute_name }} = {{ property_name }}

{%- endfor %}
Expand Down
4 changes: 2 additions & 2 deletions pyatlan/generator/templates/methods/asset/asset.jinja2
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,14 @@

@classmethod
def ref_by_guid(cls: type[SelfAsset], guid: str) -> SelfAsset:
retval: SelfAsset = cls(attributes=cls.Attributes())
retval: SelfAsset = cls(attributes=cls.Attributes(name=""))
retval.guid = guid
return retval

@classmethod
def ref_by_qualified_name(cls: type[SelfAsset], qualified_name: str) -> SelfAsset:
ret_value: SelfAsset = cls(
attributes=cls.Attributes(qualified_name=qualified_name)
attributes=cls.Attributes(name="", qualified_name=qualified_name)
)
ret_value.unique_attributes = {"qualifiedName": qualified_name}
return ret_value
Expand Down
10 changes: 7 additions & 3 deletions pyatlan/generator/templates/module.jinja2
Original file line number Diff line number Diff line change
Expand Up @@ -48,18 +48,22 @@ class {{ entity_def.name }}({{super_classes[0]}} {%- if "Asset" in super_classes
class Attributes({{super_classes[0]}}.Attributes):
{%- for attribute_def in entity_def.attribute_defs %}
{%- set type = attribute_def.typeName | get_type %}
{{attribute_def.name | to_snake_case }}: {% if attribute_def.isOptional %}Optional[{% endif %}{{type}}{% if attribute_def.isOptional %}]{% endif %} = Field(None, description='' , alias='{{attribute_def.name}}')
{{attribute_def.name | to_snake_case }}: {% if attribute_def.isOptional %}Optional[{% endif %}{{type}}{% if attribute_def.isOptional %}]{% endif %} = Field({% if attribute_def.isOptional %}None,{% endif %} description='' , alias='{{attribute_def.name}}')
{%- endfor %}
{%- for attribute_def in entity_def.relationship_attribute_defs %}
{%- set type = attribute_def.typeName | get_type %}
{{attribute_def.name | to_snake_case }}: {% if attribute_def.isOptional %}Optional[{% endif %}{{type}}{% if attribute_def.isOptional %}]{% endif %} = Field(None, description='', alias='{{attribute_def.name}}') # relationship
{{attribute_def.name | to_snake_case }}: {% if attribute_def.isOptional %}Optional[{% endif %}{{type}}{% if attribute_def.isOptional %}]{% endif %} = Field({% if attribute_def.isOptional %}None,{% endif %} description='', alias='{{attribute_def.name}}') # relationship
{%- endfor %}
{% set file_name = 'methods/attribute/' + entity_def.name | to_snake_case + '.jinja2' %}
{% if existz('templates/' + file_name) %}
{% include file_name %}
{% endif %}
attributes: '{{entity_def.name}}.Attributes' = Field(
default_factory = lambda: {{entity_def.name}}.Attributes(),
default_factory = lambda: {{entity_def.name}}.Attributes({% if entity_def.name != 'Referenceable' %}name="",{% endif %}
{% if entity_def.name == 'AtlasGlossaryTerm' or entity_def.name == 'AtlasGlossaryCategory' %} anchor=AtlasGlossary(){% endif %}
{% if entity_def.name == 'Folder' or entity_def.name == 'Query' %} parent_qualified_name="", collection_qualified_name="", parent=Namespace(){% endif %}
{% if entity_def.name == 'Procedure' %} definition=""{% endif %}
),
description='Map of attributes in the instance and their values. The specific keys of this map will vary by '
'type, so are described in the sub-types of this schema.\n',
)
Expand Down
2 changes: 1 addition & 1 deletion pyatlan/generator/templates/properties.jinja2
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,4 @@
{{ gen_property_relationship_class_vars(entity_def.name, entity_def.relationship_attribute_defs) }}
{%- endif %}

{{ gen_properties(entity_def.attribute_defs + entity_def.relationship_attribute_defs) }}
{{ gen_properties(entity_def, (entity_def.attribute_defs + entity_def.relationship_attribute_defs)) }}
7 changes: 3 additions & 4 deletions pyatlan/generator/templates/referenceable_attributes.jinja2
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
{%- endfor %}
{%- for attribute_def in entity_def.relationship_attribute_defs %}
{%- set type = attribute_def.typeName | get_type %}
{{attribute_def.name | to_snake_case }}: {% if attribute_def.isOptional %}Optional[{% endif %}{{type}}{% if attribute_def.isOptional %}]{% endif %} = Field(None, description='', alias='{{attribute_def.name}}') # relationship
{{attribute_def.name | to_snake_case }}: {% if attribute_def.isOptional %}Optional[{% endif %}{{type}}{% if attribute_def.isOptional %}]{% endif %} = Field({% if attribute_def.isOptional %}None,{% endif %} description='', alias='{{attribute_def.name}}') # relationship
{%- endfor %}

def validate_required(self):
Expand Down Expand Up @@ -59,6 +59,8 @@
)
"""Unique fully-qualified name of the asset in Atlan."""

type_name: str = Field("Referenceable", description='Name of the type definition that defines this instance.\n'
)
_metadata_proxy: CustomMetadataProxy = PrivateAttr()
attributes: '{{entity_def.name}}.Attributes' = Field(
default_factory = lambda : {{entity_def.name}}.Attributes(),
Expand Down Expand Up @@ -102,9 +104,6 @@
description="Status of the entity",
example=EntityStatus.ACTIVE
)
type_name: str = Field(
None, description='Name of the type definition that defines this instance.\n'
)
updated_by: Optional[str] = Field(
None,
description='Username of the user who last assets_updated the object.\n',
Expand Down
2 changes: 1 addition & 1 deletion pyatlan/generator/templates/structs.jinja2
Original file line number Diff line number Diff line change
Expand Up @@ -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({% if attribute_def.is_optional %}None,{% endif %} description='' , alias='{{attribute_def.name}}')
{%- endfor %}
{% endfor %}
Loading

0 comments on commit bbeedb4

Please sign in to comment.