From 92db4981b88cb6e36fc833894c96265d5d5b193f Mon Sep 17 00:00:00 2001 From: Dan Allan Date: Mon, 26 Feb 2024 20:32:34 -0500 Subject: [PATCH] Rename contents -> parts. --- tiled/_tests/test_writing.py | 24 ++++++++++++------------ tiled/catalog/adapter.py | 11 +++++------ tiled/client/union.py | 8 ++++---- tiled/server/links.py | 6 +++--- tiled/server/pydantic_union.py | 9 +++------ tiled/server/router.py | 6 +++--- tiled/structures/union.py | 9 +++------ 7 files changed, 33 insertions(+), 40 deletions(-) diff --git a/tiled/_tests/test_writing.py b/tiled/_tests/test_writing.py index 82b840e29..e499a1282 100644 --- a/tiled/_tests/test_writing.py +++ b/tiled/_tests/test_writing.py @@ -490,10 +490,10 @@ def test_union_two_tables(tree): ], key="x", ) - x.contents["table1"].write(df1) - x.contents["table2"].write(df2) - x.contents["table1"].read() - x.contents["table2"].read() + x.parts["table1"].write(df1) + x.parts["table2"].write(df2) + x.parts["table1"].read() + x.parts["table2"].read() def test_union_two_tables_colliding_names(tree): @@ -583,16 +583,16 @@ def test_union_two_tables_two_arrays(tree): key="x", ) # Write by data source. - x.contents["table1"].write(df1) - x.contents["table2"].write(df2) - x.contents["F"].write_block(arr1, (0, 0)) - x.contents["G"].write_block(arr2, (0, 0)) + x.parts["table1"].write(df1) + x.parts["table2"].write(df2) + x.parts["F"].write_block(arr1, (0, 0)) + x.parts["G"].write_block(arr2, (0, 0)) # Read by data source. - x.contents["table1"].read() - x.contents["table2"].read() - x.contents["F"].read() - x.contents["G"].read() + x.parts["table1"].read() + x.parts["table2"].read() + x.parts["F"].read() + x.parts["G"].read() # Read by column. for column in ["A", "B", "C", "D", "E", "F", "G"]: diff --git a/tiled/catalog/adapter.py b/tiled/catalog/adapter.py index 4214a3bc5..357c99ec0 100644 --- a/tiled/catalog/adapter.py +++ b/tiled/catalog/adapter.py @@ -43,7 +43,7 @@ ) from ..query_registration import QueryTranslationRegistry from ..server.pydantic_container import ContainerStructure -from ..server.pydantic_union import UnionStructure, UnionStructureItem +from ..server.pydantic_union import UnionStructure, UnionStructurePart from ..server.schemas import Asset, DataSource, Management, Revision, Spec from ..structures.core import StructureFamily from ..utils import ( @@ -353,12 +353,11 @@ def structure(self): # Give no inlined contents. return ContainerStructure(contents=None, count=None) if self.structure_family == StructureFamily.union: - contents = [] + parts = [] all_keys = [] for data_source in self.data_sources: - contents.append( - UnionStructureItem( - data_source_id=data_source.id, + parts.append( + UnionStructurePart( structure=data_source.structure, structure_family=data_source.structure_family, name=data_source.name, @@ -368,7 +367,7 @@ def structure(self): all_keys.extend(data_source.structure.columns) else: all_keys.append(data_source.name) - return UnionStructure(contents=contents, all_keys=all_keys) + return UnionStructure(parts=parts, all_keys=all_keys) if self.data_sources: assert len(self.data_sources) == 1 # more not yet implemented return self.data_sources[0].structure diff --git a/tiled/client/union.py b/tiled/client/union.py index 28df62bab..6d313a813 100644 --- a/tiled/client/union.py +++ b/tiled/client/union.py @@ -13,7 +13,7 @@ def __repr__(self): ) @property - def contents(self): + def parts(self): return UnionContents(self) def __getitem__(self, key): @@ -53,12 +53,12 @@ def __init__(self, node): def __repr__(self): return ( f"<{type(self).__name__} {{" - + ", ".join(f"'{item.name}'" for item in self.node.structure().contents) + + ", ".join(f"'{item.name}'" for item in self.node.structure().parts) + "}>" ) def __getitem__(self, name): - for index, union_item in enumerate(self.node.structure().contents): + for index, union_item in enumerate(self.node.structure().parts): if union_item.name == name: structure_family = union_item.structure_family structure_dict = union_item.structure @@ -68,7 +68,7 @@ def __getitem__(self, name): item = copy.deepcopy(self.node.item) item["attributes"]["structure_family"] = structure_family item["attributes"]["structure"] = structure_dict - item["links"] = item["links"]["contents"][index] + item["links"] = item["links"]["parts"][index] structure_type = STRUCTURE_TYPES[structure_family] structure = structure_type.from_json(structure_dict) return client_for_item( diff --git a/tiled/server/links.py b/tiled/server/links.py index 9dac4eca4..957264f42 100644 --- a/tiled/server/links.py +++ b/tiled/server/links.py @@ -59,8 +59,8 @@ def links_for_table(structure_family, structure, base_url, path_str, data_source def links_for_union(structure_family, structure, base_url, path_str): links = {} # This contains the links for each structure. - links["contents"] = [] - for item in structure.contents: + links["parts"] = [] + for item in structure.parts: item_links = LINKS_BY_STRUCTURE_FAMILY[item.structure_family]( item.structure_family, item.structure, @@ -69,7 +69,7 @@ def links_for_union(structure_family, structure, base_url, path_str): data_source=item.name, ) item_links["self"] = f"{base_url}/metadata/{path_str}" - links["contents"].append(item_links) + links["parts"].append(item_links) return links diff --git a/tiled/server/pydantic_union.py b/tiled/server/pydantic_union.py index 18fc2ab42..7d13645df 100644 --- a/tiled/server/pydantic_union.py +++ b/tiled/server/pydantic_union.py @@ -5,8 +5,7 @@ from ..structures.core import StructureFamily -class UnionStructureItem(pydantic.BaseModel): - data_source_id: Optional[int] +class UnionStructurePart(pydantic.BaseModel): structure_family: StructureFamily structure: Any # Union of Structures, but we do not want to import them... name: str @@ -17,14 +16,12 @@ def from_json(cls, item): class UnionStructure(pydantic.BaseModel): - contents: List[UnionStructureItem] + parts: List[UnionStructurePart] all_keys: Optional[List[str]] @classmethod def from_json(cls, structure): return cls( - contents=[ - UnionStructureItem.from_json(item) for item in structure["contents"] - ], + parts=[UnionStructurePart.from_json(item) for item in structure["parts"]], all_keys=structure["all_keys"], ) diff --git a/tiled/server/router.py b/tiled/server/router.py index fc1c3a551..8ec2b2ac9 100644 --- a/tiled/server/router.py +++ b/tiled/server/router.py @@ -14,7 +14,7 @@ from starlette.responses import FileResponse from .. import __version__ -from ..server.pydantic_union import UnionStructure, UnionStructureItem +from ..server.pydantic_union import UnionStructure, UnionStructurePart from ..structures.core import StructureFamily from ..utils import ensure_awaitable, path_from_uri from ..validation_registration import ValidationError @@ -1127,8 +1127,8 @@ async def _create_node( metadata_modified = False if structure_family == StructureFamily.union: structure = UnionStructure( - contents=[ - UnionStructureItem( + parts=[ + UnionStructurePart( data_source_id=data_source.id, structure=data_source.structure, structure_family=data_source.structure_family, diff --git a/tiled/structures/union.py b/tiled/structures/union.py index daee138e4..3d4a6cc4b 100644 --- a/tiled/structures/union.py +++ b/tiled/structures/union.py @@ -5,8 +5,7 @@ @dataclasses.dataclass -class UnionStructureItem: - data_source_id: int +class UnionStructurePart: structure_family: StructureFamily structure: Any # Union of Structures, but we do not want to import them... name: Optional[str] @@ -18,14 +17,12 @@ def from_json(cls, item): @dataclasses.dataclass class UnionStructure: - contents: List[UnionStructureItem] + parts: List[UnionStructurePart] all_keys: List[str] @classmethod def from_json(cls, structure): return cls( - contents=[ - UnionStructureItem.from_json(item) for item in structure["contents"] - ], + parts=[UnionStructurePart.from_json(item) for item in structure["parts"]], all_keys=structure["all_keys"], )