From 8a251f021e7f6ce4b95eaf9be0dcaf60e9c69ce1 Mon Sep 17 00:00:00 2001 From: John Kerl Date: Fri, 15 Jul 2022 00:17:21 -0400 Subject: [PATCH] lint --- apis/python/src/tiledbsc/soma_collection.py | 1 - apis/python/src/tiledbsc/tiledb_group.py | 16 +++++++++++----- apis/python/src/tiledbsc/uns_group.py | 4 +++- apis/python/tools/ingestor | 2 ++ 4 files changed, 16 insertions(+), 7 deletions(-) diff --git a/apis/python/src/tiledbsc/soma_collection.py b/apis/python/src/tiledbsc/soma_collection.py index 069e381e20..b0763d2c94 100644 --- a/apis/python/src/tiledbsc/soma_collection.py +++ b/apis/python/src/tiledbsc/soma_collection.py @@ -132,7 +132,6 @@ def __iter__(self) -> Iterator[SOMA]: self._somas[name] = SOMA(uri=uri, name=name, parent=self, ctx=self._ctx) yield self._somas[name] - # ---------------------------------------------------------------- def __contains__(self, name: str) -> bool: """ diff --git a/apis/python/src/tiledbsc/tiledb_group.py b/apis/python/src/tiledbsc/tiledb_group.py index f6ff937367..35f3f822fe 100644 --- a/apis/python/src/tiledbsc/tiledb_group.py +++ b/apis/python/src/tiledbsc/tiledb_group.py @@ -1,7 +1,6 @@ from __future__ import annotations from typing import Dict, Optional, Sequence -import time import tiledb @@ -16,6 +15,7 @@ class TileDBGroup(TileDBObject): Wraps groups from TileDB-Py by retaining a URI, options, etc. """ + _cached_exists: bool _cached_member_names_to_uris: Dict[str, str] def __init__( @@ -33,6 +33,7 @@ def __init__( See the TileDBObject constructor. """ super().__init__(uri, name, parent=parent, soma_options=soma_options, ctx=ctx) + self._cached_exists = None self._cached_member_names_to_uris = None def exists(self) -> bool: @@ -41,7 +42,12 @@ def exists(self) -> bool: object has not yet been populated, e.g. before calling `from_anndata` -- or, if the SOMA has been populated but doesn't have this member (e.g. not all SOMAs have a `varp`). """ - return bool(tiledb.object_type(self.uri, ctx=self._ctx) == "group") + # TODO: NOTE WHAT IF VFS.DELETE AFTER INSTANTIATION + if self._cached_exists is None: + self._cached_exists = bool( + tiledb.object_type(self.uri, ctx=self._ctx) == "group" + ) + return self._cached_exists def create_unless_exists(self) -> None: """ @@ -83,6 +89,7 @@ def _open(self, mode: str = "r") -> tiledb.Group: This is just a convenience wrapper around tiledb group-open. It works asa `with self._open() as G:` as well as `G = self._open(); ...; G.close()`. """ + print("OPEN", self.uri) assert mode in ("r", "w") if mode == "r" and not self.exists(): raise Exception(f"Does not exist: {self.uri}") @@ -181,8 +188,7 @@ def _add_object(self, obj: TileDBObject, relative: Optional[bool] = None) -> Non child_uri = obj.name self._cached_member_names_to_uris = None # invalidate with self._open("w") as G: - retval = G.add(uri=child_uri, relative=relative, name=obj.name) - #####print("RETVAL ", retval) + G.add(uri=child_uri, relative=relative, name=obj.name) # See _get_child_uri. Key point is that, on TileDB Cloud, URIs change from pre-creation to # post-creation. Example: # * Upload to pre-creation URI tiledb://namespace/s3://bucket/something/something/somaname @@ -191,7 +197,6 @@ def _add_object(self, obj: TileDBObject, relative: Optional[bool] = None) -> Non # * Member pre-creation URI tiledb://namespace/s3://bucket/something/something/somaname/obs # * Member post-creation URI tiledb://somaname/e4de581a-1353-4150-b1f4-6ed12548e497 obj.uri = self._get_child_uri(obj.name) - ####print("REMAP", child_uri, "TO", obj.uri) def _remove_object(self, obj: TileDBObject) -> None: self._remove_object_by_name(obj.name) @@ -231,6 +236,7 @@ def _get_member_names_to_uris(self) -> Dict[str, str]: if self._cached_member_names_to_uris is None: with self._open("r") as G: self._cached_member_names_to_uris = {obj.name: obj.uri for obj in G} + print("GMN2U", self.uri) return self._cached_member_names_to_uris def show_metadata(self, recursively: bool = True, indent: str = "") -> None: diff --git a/apis/python/src/tiledbsc/uns_group.py b/apis/python/src/tiledbsc/uns_group.py index 84b327289b..2d8a00e7a5 100644 --- a/apis/python/src/tiledbsc/uns_group.py +++ b/apis/python/src/tiledbsc/uns_group.py @@ -143,7 +143,9 @@ def from_anndata_uns(self, uns: Mapping[str, Any]) -> None: # Must be done first, to create the parent directory self.create_unless_exists() - child_uris = self._get_child_uris(list(uns.keys())) # See comments in that function + child_uris = self._get_child_uris( + list(uns.keys()) + ) # See comments in that function for key in uns.keys(): component_uri = child_uris[key] # See comments in that function diff --git a/apis/python/tools/ingestor b/apis/python/tools/ingestor index 9662b18f62..db307a0e05 100755 --- a/apis/python/tools/ingestor +++ b/apis/python/tools/ingestor @@ -231,6 +231,8 @@ def ingest_one( f"Already exists; replacing: {output_path}" ) shutil.rmtree(output_path) # Overwrite + # TODO: COMMENT + soma = tiledbsc.SOMA(uri=output_path, soma_options=soma_options) else: raise Exception( "Internal coding error in --ifexists handling.", ifexists, "<"