Skip to content

Commit

Permalink
lint
Browse files Browse the repository at this point in the history
  • Loading branch information
johnkerl committed Jul 15, 2022
1 parent 52aa270 commit 8a251f0
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 7 deletions.
1 change: 0 additions & 1 deletion apis/python/src/tiledbsc/soma_collection.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
"""
Expand Down
16 changes: 11 additions & 5 deletions apis/python/src/tiledbsc/tiledb_group.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
from __future__ import annotations

from typing import Dict, Optional, Sequence
import time

import tiledb

Expand All @@ -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__(
Expand All @@ -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:
Expand All @@ -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:
"""
Expand Down Expand Up @@ -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}")
Expand Down Expand Up @@ -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
Expand All @@ -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)
Expand Down Expand Up @@ -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:
Expand Down
4 changes: 3 additions & 1 deletion apis/python/src/tiledbsc/uns_group.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions apis/python/tools/ingestor
Original file line number Diff line number Diff line change
Expand Up @@ -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, "<"
Expand Down

0 comments on commit 8a251f0

Please sign in to comment.