Skip to content

Commit 18b73a6

Browse files
committed
WIP: add prefer_local option
1 parent 424ed66 commit 18b73a6

File tree

3 files changed

+19
-8
lines changed

3 files changed

+19
-8
lines changed

src/vitessce/config.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -242,12 +242,12 @@ def get_artifacts(self):
242242

243243
return artifacts
244244

245-
def get_stores(self, base_url=None):
245+
def get_stores(self, base_url=None, prefer_local=False):
246246
stores = {}
247247
for obj in self.objs:
248248
stores = {
249249
**stores,
250-
**obj.get_stores(base_url)
250+
**obj.get_stores(base_url, prefer_local=prefer_local)
251251
}
252252

253253
return stores
@@ -1615,7 +1615,7 @@ def get_artifacts(self):
16151615
artifacts.update(d.get_artifacts())
16161616
return artifacts
16171617

1618-
def get_stores(self, base_url=None):
1618+
def get_stores(self, base_url=None, prefer_local=False):
16191619
"""
16201620
Convert the routes for this view config from the datasets.
16211621
@@ -1626,7 +1626,7 @@ def get_stores(self, base_url=None):
16261626
for d in self.config["datasets"]:
16271627
stores = {
16281628
**stores,
1629-
**d.get_stores(base_url)
1629+
**d.get_stores(base_url, prefer_local=prefer_local)
16301630
}
16311631
return stores
16321632

src/vitessce/widget.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -472,7 +472,7 @@ class VitessceWidget(anywidget.AnyWidget):
472472

473473
store_urls = List(trait=Unicode(''), default_value=[]).tag(sync=True)
474474

475-
def __init__(self, config, height=600, theme='auto', uid=None, port=None, proxy=False, js_package_version='3.5.4', js_dev_mode=False, custom_js_url='', plugins=None, remount_on_uid_change=True, invoke_timeout=30000):
475+
def __init__(self, config, height=600, theme='auto', uid=None, port=None, proxy=False, js_package_version='3.5.4', js_dev_mode=False, custom_js_url='', plugins=None, remount_on_uid_change=True, prefer_local=True, invoke_timeout=30000):
476476
"""
477477
Construct a new Vitessce widget.
478478
@@ -506,7 +506,7 @@ def __init__(self, config, height=600, theme='auto', uid=None, port=None, proxy=
506506
config_dict = config.to_dict(base_url=base_url)
507507
routes = config.get_routes()
508508

509-
self._stores = config.get_stores(base_url=base_url)
509+
self._stores = config.get_stores(base_url=base_url, prefer_local=prefer_local)
510510
self._plugins = plugins or []
511511

512512
plugin_esm = [p.plugin_esm for p in self._plugins]

src/vitessce/wrappers.py

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -126,8 +126,17 @@ def get_artifacts(self):
126126
:rtype: dict[str, lamindb.Artifact]
127127
"""
128128
return self.artifacts
129-
130-
def get_stores(self, base_url):
129+
130+
def try_getting_artifact_stores(self):
131+
artifact_stores = dict()
132+
for artifact_url, artifact in self.artifacts.items():
133+
local_path = artifact._local_filepath
134+
if os.path.isdir(local_path):
135+
store = zarr.DirectoryStore(local_path)
136+
artifact_stores[artifact_url] = store
137+
return artifact_stores
138+
139+
def get_stores(self, base_url, prefer_local=False):
131140
"""
132141
Obtain the stores that have been created for this wrapper class.
133142
@@ -139,6 +148,8 @@ def get_stores(self, base_url):
139148
for relative_url, store in relative_stores.items():
140149
absolute_url = base_url + relative_url
141150
absolute_stores[absolute_url] = store
151+
if prefer_local:
152+
absolute_stores.update(self.try_getting_artifact_stores())
142153
return absolute_stores
143154

144155
def get_file_defs(self, base_url):

0 commit comments

Comments
 (0)