Skip to content

Commit 31bd2cc

Browse files
authored
NickAkhmetov/Copy requestInit when using from_dict (#352)
1 parent 5ae1dae commit 31bd2cc

File tree

3 files changed

+26
-7
lines changed

3 files changed

+26
-7
lines changed

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
44

55
[project]
66
name = "vitessce"
7-
version = "3.2.7"
7+
version = "3.2.8"
88
authors = [
99
{ name="Mark Keller", email="[email protected]" },
1010
]

tests/test_config.py

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -522,7 +522,12 @@ def test_config_from_dict():
522522
'files': [
523523
{
524524
'url': 'http://cells.json',
525-
'fileType': 'cells.json'
525+
'fileType': 'cells.json',
526+
'requestInit': {
527+
'headers': {
528+
'Authorization': 'Bearer token'
529+
}
530+
}
526531
}
527532
]
528533
}
@@ -568,7 +573,12 @@ def test_config_from_dict():
568573
'files': [
569574
{
570575
'url': 'http://cells.json',
571-
'fileType': 'cells.json'
576+
'fileType': 'cells.json',
577+
'requestInit': {
578+
'headers': {
579+
'Authorization': 'Bearer token'
580+
}
581+
}
572582
}
573583
]
574584
},

vitessce/config.py

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ class VitessceConfigDatasetFile:
5050
A class to represent a file (described by a URL, data type, and file type) in a Vitessce view config dataset.
5151
"""
5252

53-
def __init__(self, file_type, url=None, coordination_values=None, options=None, data_type=None):
53+
def __init__(self, file_type, url=None, coordination_values=None, options=None, data_type=None, request_init=None):
5454
"""
5555
Not meant to be instantiated directly, but instead created and returned by the ``VitessceConfigDataset.add_file()`` method.
5656
@@ -62,6 +62,8 @@ def __init__(self, file_type, url=None, coordination_values=None, options=None,
6262
:param options: Extra options to pass to the file loader class.
6363
:type options: dict or list or None
6464
:param data_type: Deprecated / not used. Only included for backwards compatibility with the old API.
65+
:param request_init: Optional request init object to pass to the fetch API.
66+
:type request_init: dict or None
6567
"""
6668
self.file = {
6769
"fileType": file_type
@@ -72,6 +74,8 @@ def __init__(self, file_type, url=None, coordination_values=None, options=None,
7274
self.file["options"] = options
7375
if coordination_values:
7476
self.file["coordinationValues"] = coordination_values
77+
if request_init:
78+
self.file["requestInit"] = request_init
7579

7680
def __repr__(self):
7781
repr_dict = {
@@ -83,6 +87,8 @@ def __repr__(self):
8387
repr_dict["coordination_values"] = self.file["coordinationValues"]
8488
if "options" in self.file:
8589
repr_dict["options"] = self.file["options"]
90+
if "requestInit" in self.file:
91+
repr_dict["request_init"] = self.file["requestInit"]
8692

8793
return make_repr(repr_dict, class_def=self.__class__)
8894

@@ -135,7 +141,7 @@ def get_uid(self):
135141
"""
136142
return self.dataset["uid"]
137143

138-
def add_file(self, file_type, url=None, coordination_values=None, options=None, data_type=None):
144+
def add_file(self, file_type, url=None, coordination_values=None, options=None, data_type=None, request_init=None):
139145
"""
140146
Add a new file definition to this dataset instance.
141147
@@ -148,6 +154,8 @@ def add_file(self, file_type, url=None, coordination_values=None, options=None,
148154
:param options: Extra options to pass to the file loader class. Optional.
149155
:type options: dict or list or None
150156
:param data_type: Deprecated / not used. Only included for backwards compatibility with the old API.
157+
:param request_init: Optional request init object to pass to the fetch API.
158+
:type request_init: dict or None
151159
152160
:returns: Self, to allow function chaining.
153161
:rtype: VitessceConfigDataset
@@ -171,7 +179,7 @@ def add_file(self, file_type, url=None, coordination_values=None, options=None,
171179
file_type_str = norm_enum(file_type, ft)
172180

173181
self._add_file(VitessceConfigDatasetFile(
174-
url=url, file_type=file_type_str, coordination_values=coordination_values, options=options))
182+
url=url, file_type=file_type_str, coordination_values=coordination_values, options=options, request_init=request_init))
175183
return self
176184

177185
def _add_file(self, obj):
@@ -1606,7 +1614,8 @@ def from_dict(config):
16061614
file_type=f["fileType"],
16071615
url=f.get("url"),
16081616
coordination_values=f.get("coordinationValues"),
1609-
options=f.get("options")
1617+
options=f.get("options"),
1618+
request_init=f.get("requestInit")
16101619
)
16111620
if 'coordinationSpace' in config:
16121621
for c_type in config['coordinationSpace'].keys():

0 commit comments

Comments
 (0)