sparclclient 1.2.6b10__tar.gz → 1.2.6b12__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {sparclclient-1.2.6b10 → sparclclient-1.2.6b12}/PKG-INFO +1 -1
- {sparclclient-1.2.6b10 → sparclclient-1.2.6b12}/sparcl/__init__.py +1 -1
- {sparclclient-1.2.6b10 → sparclclient-1.2.6b12}/sparcl/client.py +62 -58
- {sparclclient-1.2.6b10 → sparclclient-1.2.6b12}/tests/tests_api.py +2 -1
- {sparclclient-1.2.6b10 → sparclclient-1.2.6b12}/.github/workflows/django.yml +0 -0
- {sparclclient-1.2.6b10 → sparclclient-1.2.6b12}/.gitignore +0 -0
- {sparclclient-1.2.6b10 → sparclclient-1.2.6b12}/.pre-commit-config.yaml +0 -0
- {sparclclient-1.2.6b10 → sparclclient-1.2.6b12}/.readthedocs.yaml +0 -0
- {sparclclient-1.2.6b10 → sparclclient-1.2.6b12}/LICENSE +0 -0
- {sparclclient-1.2.6b10 → sparclclient-1.2.6b12}/Makefile +0 -0
- {sparclclient-1.2.6b10 → sparclclient-1.2.6b12}/README.md +0 -0
- {sparclclient-1.2.6b10 → sparclclient-1.2.6b12}/make.bat +0 -0
- {sparclclient-1.2.6b10 → sparclclient-1.2.6b12}/pyproject.toml +0 -0
- {sparclclient-1.2.6b10 → sparclclient-1.2.6b12}/requirements-client.txt +0 -0
- {sparclclient-1.2.6b10 → sparclclient-1.2.6b12}/requirements-internal.txt +0 -0
- {sparclclient-1.2.6b10 → sparclclient-1.2.6b12}/requirements.txt +0 -0
- {sparclclient-1.2.6b10 → sparclclient-1.2.6b12}/source/conf.py +0 -0
- {sparclclient-1.2.6b10 → sparclclient-1.2.6b12}/source/index.rst +0 -0
- {sparclclient-1.2.6b10 → sparclclient-1.2.6b12}/source/sparcl.rst +0 -0
- {sparclclient-1.2.6b10 → sparclclient-1.2.6b12}/sparcl/Results.py +0 -0
- {sparclclient-1.2.6b10 → sparclclient-1.2.6b12}/sparcl/benchmarks/Benchmark_SPARCL_example.ipynb +0 -0
- {sparclclient-1.2.6b10 → sparclclient-1.2.6b12}/sparcl/benchmarks/__init__.py +0 -0
- {sparclclient-1.2.6b10 → sparclclient-1.2.6b12}/sparcl/benchmarks/benchmarks.py +0 -0
- {sparclclient-1.2.6b10 → sparclclient-1.2.6b12}/sparcl/benchmarks/sparcl_benchmarking.ipynb +0 -0
- {sparclclient-1.2.6b10 → sparclclient-1.2.6b12}/sparcl/conf.py +0 -0
- {sparclclient-1.2.6b10 → sparclclient-1.2.6b12}/sparcl/exceptions.py +0 -0
- {sparclclient-1.2.6b10 → sparclclient-1.2.6b12}/sparcl/fields.py +0 -0
- {sparclclient-1.2.6b10 → sparclclient-1.2.6b12}/sparcl/gather_2d.py +0 -0
- {sparclclient-1.2.6b10 → sparclclient-1.2.6b12}/sparcl/notebooks/sparcl-examples.ipynb +0 -0
- {sparclclient-1.2.6b10 → sparclclient-1.2.6b12}/sparcl/resample_spectra.py +0 -0
- {sparclclient-1.2.6b10 → sparclclient-1.2.6b12}/sparcl/sparc.ini +0 -0
- {sparclclient-1.2.6b10 → sparclclient-1.2.6b12}/sparcl/type_conversion.py +0 -0
- {sparclclient-1.2.6b10 → sparclclient-1.2.6b12}/sparcl/unsupported.py +0 -0
- {sparclclient-1.2.6b10 → sparclclient-1.2.6b12}/sparcl/utils.py +0 -0
- {sparclclient-1.2.6b10 → sparclclient-1.2.6b12}/tests/expected_dev1.py +0 -0
- {sparclclient-1.2.6b10 → sparclclient-1.2.6b12}/tests/expected_pat.py +0 -0
- {sparclclient-1.2.6b10 → sparclclient-1.2.6b12}/tests/methods_tests.py +0 -0
- {sparclclient-1.2.6b10 → sparclclient-1.2.6b12}/tests/utils.py +0 -0
- {sparclclient-1.2.6b10 → sparclclient-1.2.6b12}/tox.ini +0 -0
|
@@ -197,9 +197,7 @@ class SparclClient: # was SparclApi()
|
|
|
197
197
|
self.verbose = verbose
|
|
198
198
|
self.show_curl = show_curl # Show CURL equivalent of client method
|
|
199
199
|
#!self.internal_names = internal_names
|
|
200
|
-
self.c_timeout = min(
|
|
201
|
-
MAX_CONNECT_TIMEOUT, float(connect_timeout)
|
|
202
|
-
) # seconds
|
|
200
|
+
self.c_timeout = min(MAX_CONNECT_TIMEOUT, float(connect_timeout)) # seconds
|
|
203
201
|
self.r_timeout = min(MAX_READ_TIMEOUT, float(read_timeout)) # seconds
|
|
204
202
|
|
|
205
203
|
# require response within this num seconds
|
|
@@ -216,7 +214,7 @@ class SparclClient: # was SparclApi()
|
|
|
216
214
|
ann = f"{self.apiurl}/announcement/"
|
|
217
215
|
annres = requests.get(ann, timeout=self.timeout)
|
|
218
216
|
annstr = annres.json()['announcement']
|
|
219
|
-
if annstr
|
|
217
|
+
if annstr:
|
|
220
218
|
print(f"announcement={annstr}")
|
|
221
219
|
|
|
222
220
|
# Get API Version
|
|
@@ -267,13 +265,13 @@ class SparclClient: # was SparclApi()
|
|
|
267
265
|
|
|
268
266
|
def token_expired(self, renew=False):
|
|
269
267
|
"""
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
268
|
+
POST http://localhost:8050/sparc/renew_token/
|
|
269
|
+
Content-Type: application/json
|
|
270
|
+
{
|
|
271
|
+
"refresh_token": "..."
|
|
272
|
+
}
|
|
275
273
|
|
|
276
|
-
|
|
274
|
+
Returns an 'access' token
|
|
277
275
|
"""
|
|
278
276
|
now = datetime.datetime.now()
|
|
279
277
|
expired = True
|
|
@@ -287,8 +285,8 @@ class SparclClient: # was SparclApi()
|
|
|
287
285
|
resp = requests.post(url, json={"refresh_token": self.renew_token})
|
|
288
286
|
resp.raise_for_status()
|
|
289
287
|
data = resp.json()
|
|
290
|
-
|
|
291
|
-
self.token = data[
|
|
288
|
+
# @print(f"{data=}")
|
|
289
|
+
self.token = data["access"]
|
|
292
290
|
self.set_token_exp()
|
|
293
291
|
expired = False
|
|
294
292
|
|
|
@@ -335,8 +333,8 @@ class SparclClient: # was SparclApi()
|
|
|
335
333
|
try:
|
|
336
334
|
res.raise_for_status()
|
|
337
335
|
#!print(f"DBG: {res.content=}")
|
|
338
|
-
self.token = res.json()[
|
|
339
|
-
self.renew_token = res.json()[
|
|
336
|
+
self.token = res.json()["access"]
|
|
337
|
+
self.renew_token = res.json()["refresh"]
|
|
340
338
|
self.session.auth = (email, password)
|
|
341
339
|
except Exception:
|
|
342
340
|
self.session.auth = None
|
|
@@ -344,8 +342,7 @@ class SparclClient: # was SparclApi()
|
|
|
344
342
|
self.renew_token = None
|
|
345
343
|
self.token_exp = None
|
|
346
344
|
msg = (
|
|
347
|
-
|
|
348
|
-
' Reverted to "Anonymous" user.'
|
|
345
|
+
'Could not login with given credentials. Reverted to "Anonymous" user.'
|
|
349
346
|
)
|
|
350
347
|
return msg
|
|
351
348
|
|
|
@@ -356,10 +353,12 @@ class SparclClient: # was SparclApi()
|
|
|
356
353
|
def set_token_exp(self):
|
|
357
354
|
decoded = jwt.decode(
|
|
358
355
|
self.token,
|
|
359
|
-
algorithms=[
|
|
360
|
-
|
|
356
|
+
algorithms=[
|
|
357
|
+
"HS256",
|
|
358
|
+
],
|
|
359
|
+
options={"verify_signature": False},
|
|
361
360
|
)
|
|
362
|
-
self.token_exp = datetime.datetime.fromtimestamp(decoded[
|
|
361
|
+
self.token_exp = datetime.datetime.fromtimestamp(decoded["exp"])
|
|
363
362
|
|
|
364
363
|
def logout(self):
|
|
365
364
|
"""Logout of the SPARCL service.
|
|
@@ -428,9 +427,9 @@ class SparclClient: # was SparclApi()
|
|
|
428
427
|
if dataset_list is None:
|
|
429
428
|
dataset_list = self.fields.all_drs
|
|
430
429
|
|
|
431
|
-
assert isinstance(
|
|
432
|
-
|
|
433
|
-
)
|
|
430
|
+
assert isinstance(dataset_list, (list, set)), (
|
|
431
|
+
f"DATASET_LIST must be a list. Found {dataset_list}"
|
|
432
|
+
)
|
|
434
433
|
|
|
435
434
|
common = set(self.fields.common(dataset_list))
|
|
436
435
|
union = self.fields.default_retrieve_fields(dataset_list=dataset_list)
|
|
@@ -471,16 +470,14 @@ class SparclClient: # was SparclApi()
|
|
|
471
470
|
drs = self.fields.all_drs if dataset_list is None else dataset_list
|
|
472
471
|
msg = (
|
|
473
472
|
f'Unknown fields "{",".join(unk)}" given '
|
|
474
|
-
f
|
|
475
|
-
f
|
|
473
|
+
f"for DataSets {','.join(drs)}. "
|
|
474
|
+
f"Allowed fields are: {','.join(all)}. "
|
|
476
475
|
)
|
|
477
476
|
raise ex.UnknownField(msg)
|
|
478
477
|
return True
|
|
479
478
|
|
|
480
479
|
def _common_internal(self, *, science_fields=None, dataset_list=None):
|
|
481
|
-
self._validate_science_fields(
|
|
482
|
-
science_fields, dataset_list=dataset_list
|
|
483
|
-
)
|
|
480
|
+
self._validate_science_fields(science_fields, dataset_list=dataset_list)
|
|
484
481
|
|
|
485
482
|
if dataset_list is None:
|
|
486
483
|
dataset_list = self.fields.all_drs
|
|
@@ -604,12 +601,9 @@ class SparclClient: # was SparclApi()
|
|
|
604
601
|
#! dataset_list=dataset_list) # DLS-401
|
|
605
602
|
dr = list(dataset_list)[0]
|
|
606
603
|
if len(constraints) > 0:
|
|
607
|
-
self._validate_science_fields(
|
|
608
|
-
constraints.keys(), dataset_list=dataset_list
|
|
609
|
-
)
|
|
604
|
+
self._validate_science_fields(constraints.keys(), dataset_list=dataset_list)
|
|
610
605
|
constraints = {
|
|
611
|
-
self.fields._internal_name(k, dr): v
|
|
612
|
-
for k, v in constraints.items()
|
|
606
|
+
self.fields._internal_name(k, dr): v for k, v in constraints.items()
|
|
613
607
|
}
|
|
614
608
|
uparams = dict(
|
|
615
609
|
limit=limit,
|
|
@@ -635,7 +629,7 @@ class SparclClient: # was SparclApi()
|
|
|
635
629
|
|
|
636
630
|
if res.status_code != 200:
|
|
637
631
|
if verbose and ("traceback" in res.json()):
|
|
638
|
-
print(f
|
|
632
|
+
print(f"DBG: Server traceback=\n{res.json()['traceback']}")
|
|
639
633
|
raise ex.genSparclException(res, verbose=self.verbose)
|
|
640
634
|
|
|
641
635
|
found = Found(res.json(), client=self)
|
|
@@ -643,9 +637,7 @@ class SparclClient: # was SparclApi()
|
|
|
643
637
|
print(f"Record key counts: {ut.count_values(found.records)}")
|
|
644
638
|
return found
|
|
645
639
|
|
|
646
|
-
def missing(
|
|
647
|
-
self, uuid_list, *, dataset_list=None, countOnly=False, verbose=False
|
|
648
|
-
):
|
|
640
|
+
def missing(self, uuid_list, *, dataset_list=None, countOnly=False, verbose=False):
|
|
649
641
|
"""Return the subset of sparcl_ids in the given uuid_list that are
|
|
650
642
|
NOT stored in the SPARCL database.
|
|
651
643
|
|
|
@@ -676,9 +668,9 @@ class SparclClient: # was SparclApi()
|
|
|
676
668
|
|
|
677
669
|
if dataset_list is None:
|
|
678
670
|
dataset_list = self.fields.all_drs
|
|
679
|
-
assert isinstance(
|
|
680
|
-
|
|
681
|
-
)
|
|
671
|
+
assert isinstance(dataset_list, (list, set)), (
|
|
672
|
+
f"DATASET_LIST must be a list. Found {dataset_list}"
|
|
673
|
+
)
|
|
682
674
|
|
|
683
675
|
verbose = verbose or self.verbose
|
|
684
676
|
uparams = dict(dataset_list=",".join(dataset_list))
|
|
@@ -731,9 +723,9 @@ class SparclClient: # was SparclApi()
|
|
|
731
723
|
"""
|
|
732
724
|
if dataset_list is None:
|
|
733
725
|
dataset_list = self.fields.all_drs
|
|
734
|
-
assert isinstance(
|
|
735
|
-
|
|
736
|
-
)
|
|
726
|
+
assert isinstance(dataset_list, (list, set)), (
|
|
727
|
+
f"DATASET_LIST must be a list. Found {dataset_list}"
|
|
728
|
+
)
|
|
737
729
|
|
|
738
730
|
verbose = verbose or self.verbose
|
|
739
731
|
uparams = dict(dataset_list=",".join(dataset_list))
|
|
@@ -769,13 +761,13 @@ class SparclClient: # was SparclApi()
|
|
|
769
761
|
unknown = inc_set.difference(avail_science)
|
|
770
762
|
if len(unknown) > 0:
|
|
771
763
|
msg = (
|
|
772
|
-
f
|
|
764
|
+
f"The INCLUDE list ({','.join(sorted(include_list))}) "
|
|
773
765
|
f"contains invalid data field names "
|
|
774
|
-
f
|
|
766
|
+
f"for Data Sets ({','.join(sorted(dataset_list))}). "
|
|
775
767
|
f"Unknown fields are: "
|
|
776
|
-
f'
|
|
768
|
+
f"{', '.join(sorted(list(unknown)))}. "
|
|
777
769
|
f"Available fields are: "
|
|
778
|
-
f'
|
|
770
|
+
f"{', '.join(sorted(avail_science))}."
|
|
779
771
|
)
|
|
780
772
|
raise ex.BadInclude(msg)
|
|
781
773
|
return True
|
|
@@ -840,9 +832,9 @@ class SparclClient: # was SparclApi()
|
|
|
840
832
|
orig_dataset_list = dataset_list
|
|
841
833
|
if dataset_list is None:
|
|
842
834
|
dataset_list = self.fields.all_drs
|
|
843
|
-
assert isinstance(
|
|
844
|
-
|
|
845
|
-
)
|
|
835
|
+
assert isinstance(dataset_list, (list, set)), (
|
|
836
|
+
f"DATASET_LIST must be a list. Found {dataset_list}"
|
|
837
|
+
)
|
|
846
838
|
|
|
847
839
|
verbose = self.verbose if verbose is None else verbose
|
|
848
840
|
|
|
@@ -933,7 +925,7 @@ class SparclClient: # was SparclApi()
|
|
|
933
925
|
print(f"DBG: Server response=\n{res.text}")
|
|
934
926
|
# @@@ FAILS on invalid JSON. Maybe not json at all !!!
|
|
935
927
|
if verbose and ("traceback" in res.json()):
|
|
936
|
-
print(f
|
|
928
|
+
print(f"DBG: Server traceback=\n{res.json()['traceback']}")
|
|
937
929
|
raise ex.genSparclException(res, verbose=verbose)
|
|
938
930
|
|
|
939
931
|
if format == "json":
|
|
@@ -957,10 +949,10 @@ class SparclClient: # was SparclApi()
|
|
|
957
949
|
count = len(results) - 1
|
|
958
950
|
print(
|
|
959
951
|
f"Got {count} spectra in "
|
|
960
|
-
f"{elapsed:.2f} seconds ({count/elapsed:.0f} "
|
|
952
|
+
f"{elapsed:.2f} seconds ({count / elapsed:.0f} "
|
|
961
953
|
"spectra/sec)"
|
|
962
954
|
)
|
|
963
|
-
print(f
|
|
955
|
+
print(f"{meta['status']}")
|
|
964
956
|
|
|
965
957
|
# Format/consolodate the server messages to one message with
|
|
966
958
|
# the count of missing files
|
|
@@ -969,14 +961,14 @@ class SparclClient: # was SparclApi()
|
|
|
969
961
|
if verbose:
|
|
970
962
|
print(f"There are {len(warnings)} warnings")
|
|
971
963
|
missingcount = 0
|
|
972
|
-
missing_message = re.sub(r
|
|
964
|
+
missing_message = re.sub(r" [0-9]+ ", " %s ", warnings[0])
|
|
973
965
|
for i in warnings:
|
|
974
|
-
matches = re.match(r
|
|
966
|
+
matches = re.match(r".* ([0-9]+) out of the ([0-9]+).*", i)
|
|
975
967
|
if matches:
|
|
976
968
|
missingcount += int(matches.groups()[0])
|
|
977
969
|
|
|
978
970
|
# using old style substitution to avoid issue with the {} in the message # noqa: E501
|
|
979
|
-
warning_message = missing_message % (missingcount, req_num, missingcount)
|
|
971
|
+
warning_message = missing_message % (missingcount, req_num, missingcount) # noqa: E501
|
|
980
972
|
warn(warning_message, stacklevel=2)
|
|
981
973
|
|
|
982
974
|
return Retrieved(results, client=self)
|
|
@@ -1029,9 +1021,9 @@ class SparclClient: # was SparclApi()
|
|
|
1029
1021
|
f'The "specid_list" parameter must be a python list. '
|
|
1030
1022
|
f"You used a value of type {type(specid_list)}."
|
|
1031
1023
|
)
|
|
1032
|
-
assert (
|
|
1033
|
-
|
|
1034
|
-
)
|
|
1024
|
+
assert len(specid_list) > 0, (
|
|
1025
|
+
f'The "specid_list" parameter value must be a non-empty list'
|
|
1026
|
+
)
|
|
1035
1027
|
assert isinstance(specid_list[0], int), (
|
|
1036
1028
|
f'The "specid_list" parameter must be a python list of INTEGERS. '
|
|
1037
1029
|
f"You used an element value of type {type(specid_list[0])}."
|
|
@@ -1039,8 +1031,10 @@ class SparclClient: # was SparclApi()
|
|
|
1039
1031
|
|
|
1040
1032
|
if dataset_list is None:
|
|
1041
1033
|
constraints = {"specid": specid_list}
|
|
1034
|
+
dr_list = self.fields.all_drs
|
|
1042
1035
|
else:
|
|
1043
1036
|
constraints = {"specid": specid_list, "data_release": dataset_list}
|
|
1037
|
+
dr_list = dataset_list
|
|
1044
1038
|
|
|
1045
1039
|
# Science Field Name for uuid.
|
|
1046
1040
|
dr = list(self.fields.all_drs)[0]
|
|
@@ -1049,6 +1043,16 @@ class SparclClient: # was SparclApi()
|
|
|
1049
1043
|
found = self.find([idfld], constraints=constraints, limit=limit)
|
|
1050
1044
|
if verbose:
|
|
1051
1045
|
print(f"Found {found.count} matches.")
|
|
1046
|
+
if found.count < len(specid_list):
|
|
1047
|
+
usrcount = len(specid_list)
|
|
1048
|
+
dbcount = found.count
|
|
1049
|
+
warn = (
|
|
1050
|
+
f"UserWarning: Some SPECIDs were not found. "
|
|
1051
|
+
f"{usrcount - dbcount} out of the {usrcount} requested "
|
|
1052
|
+
f"uuids have no records available in the SPARCL database "
|
|
1053
|
+
f"associated with DataSets {dr_list}."
|
|
1054
|
+
)
|
|
1055
|
+
print(warn)
|
|
1052
1056
|
res = self.retrieve(
|
|
1053
1057
|
found.ids,
|
|
1054
1058
|
#! svc=svc,
|
|
@@ -175,6 +175,7 @@ class SparclClientTest(unittest.TestCase):
|
|
|
175
175
|
url=serverurl,
|
|
176
176
|
verbose=clverb,
|
|
177
177
|
show_curl=showcurl,
|
|
178
|
+
announcement=False,
|
|
178
179
|
)
|
|
179
180
|
cls.timing = dict()
|
|
180
181
|
cls.doc = dict()
|
|
@@ -728,7 +729,7 @@ class AuthTest(unittest.TestCase):
|
|
|
728
729
|
)
|
|
729
730
|
|
|
730
731
|
cls.client = sparcl.client.SparclClient(
|
|
731
|
-
url=serverurl, verbose=clverb, show_curl=showcurl
|
|
732
|
+
url=serverurl, verbose=clverb, show_curl=showcurl,
|
|
732
733
|
)
|
|
733
734
|
|
|
734
735
|
global show_run_context
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{sparclclient-1.2.6b10 → sparclclient-1.2.6b12}/sparcl/benchmarks/Benchmark_SPARCL_example.ipynb
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|