dcicutils 8.8.0.1b23__py3-none-any.whl → 8.8.0.1b24__py3-none-any.whl

Sign up to get free protection for your applications and to get access to all the features.
@@ -99,7 +99,8 @@ class PortalObject:
99
99
  def compare(self, value: Union[dict, PortalObject],
100
100
  consider_refs: bool = False, resolved_refs: List[dict] = None) -> Tuple[dict, int]:
101
101
  if consider_refs and isinstance(resolved_refs, list):
102
- this_data, nlookups = self._normalized_refs(refs=resolved_refs).data
102
+ normlized_portal_object, nlookups = self._normalized_refs(refs=resolved_refs)
103
+ this_data = normlized_portal_object.data
103
104
  else:
104
105
  this_data = self.data
105
106
  nlookups = 0
@@ -213,7 +214,7 @@ class PortalObject:
213
214
  if Portal.is_lookup_root(lookup_options) and not Portal.is_lookup_root_first(lookup_options):
214
215
  identifying_paths.append(f"/{identifying_value}")
215
216
  if Portal.is_lookup_subtypes(lookup_options):
216
- for subtype_name in self._portal.get_schemas_subtype_names():
217
+ for subtype_name in self._portal.get_schema_subtype_names(self.type):
217
218
  identifying_paths.append(f"/{subtype_name}/{identifying_value}")
218
219
  return identifying_paths or None
219
220
 
@@ -249,13 +250,13 @@ class PortalObject:
249
250
  if isinstance(value, dict):
250
251
  for key in value:
251
252
  path = f"{_path}.{key}" if _path else key
252
- value[key] = PortalObject._normalize_data_refs(value[key], refs=refs,
253
- schema=schema, portal=portal, _path=path)
253
+ value[key], nlookups = PortalObject._normalize_data_refs(value[key], refs=refs,
254
+ schema=schema, portal=portal, _path=path)
254
255
  elif isinstance(value, list):
255
256
  for index in range(len(value)):
256
257
  path = f"{_path or ''}#{index}"
257
- value[index] = PortalObject._normalize_data_refs(value[index], refs=refs,
258
- schema=schema, portal=portal, _path=path)
258
+ value[index], nlookups = PortalObject._normalize_data_refs(value[index], refs=refs,
259
+ schema=schema, portal=portal, _path=path)
259
260
  elif value_type := Schema.get_property_by_path(schema, _path):
260
261
  if link_to := value_type.get("linkTo"):
261
262
  ref_path = f"/{link_to}/{value}"
dcicutils/portal_utils.py CHANGED
@@ -398,7 +398,7 @@ class Portal:
398
398
  return super_type_map_flattened
399
399
 
400
400
  @lru_cache(maxsize=64)
401
- def get_schemas_subtype_names(self, type_name: str) -> List[str]:
401
+ def get_schema_subtype_names(self, type_name: str) -> List[str]:
402
402
  if not (schemas_super_type_map := self.get_schemas_super_type_map()):
403
403
  return []
404
404
  return schemas_super_type_map.get(type_name, [])
@@ -222,6 +222,9 @@ class StructuredDataSet:
222
222
  diffs[type_name].append(create_readonly_object(path=identifying_path, uuid=None, diffs=None))
223
223
  if callable(progress):
224
224
  progress({"create": True, "lookups": nlookups})
225
+ else:
226
+ if callable(progress):
227
+ progress({"lookups": nlookups})
225
228
  if callable(progress):
226
229
  progress({"finish": True})
227
230
  return diffs
@@ -257,7 +260,7 @@ class StructuredDataSet:
257
260
  self._load_reader(CsvReader(file), type_name=Schema.type_name(file))
258
261
 
259
262
  def _load_excel_file(self, file: str) -> None:
260
- def calculate_total_rows_to_process() -> Tuple[int, int]:
263
+ def get_counts() -> Tuple[int, int]:
261
264
  nonlocal file
262
265
  excel = Excel(file)
263
266
  nrows = 0
@@ -266,18 +269,27 @@ class StructuredDataSet:
266
269
  nrows += 1
267
270
  return nrows, len(excel.sheet_names)
268
271
  if self._progress:
269
- self._progress_update(calculate_total_rows_to_process)
272
+ nrows, nsheets = get_counts()
273
+ self._progress({"start": True, "sheets": nsheets, "rows": nrows})
274
+ """
275
+ if self._progress:
276
+ self._progress_update(get_counts)
277
+ """
270
278
  excel = Excel(file) # Order the sheet names by any specified ordering (e.g. ala snovault.loadxl).
271
279
  order = {Schema.type_name(key): index for index, key in enumerate(self._order)} if self._order else {}
272
280
  for sheet_name in sorted(excel.sheet_names, key=lambda key: order.get(Schema.type_name(key), sys.maxsize)):
273
281
  self._load_reader(excel.sheet_reader(sheet_name), type_name=Schema.type_name(sheet_name))
282
+ if self._progress:
283
+ self._progress({"finish": True})
284
+ # TODO: Do we really need progress reporting for the below?
274
285
  # Check for unresolved reference errors which really are not because of ordering.
275
286
  # Yes such internal references will be handled correctly on actual database update via snovault.loadxl.
276
287
  if ref_errors := self.ref_errors:
277
288
  ref_errors_actual = []
278
289
  for ref_error in ref_errors:
279
290
  if not (resolved := self.portal.ref_exists(ref := ref_error["error"])):
280
- # if not (resolved := self.portal.ref_exists_internally(ref := ref_error["error"])): # TODO
291
+ # TODO: Probably do this instead; and if so then no progress needed (per question above).
292
+ # if not (resolved := self.portal.ref_exists_internally(ref := ref_error["error"])):
281
293
  ref_errors_actual.append(ref_error)
282
294
  else:
283
295
  self._resolved_refs.add((ref, resolved.get("uuid")))
@@ -310,13 +322,15 @@ class StructuredDataSet:
310
322
  self._add_properties(structured_row, self._autoadd_properties, schema)
311
323
  self._add(type_name, structured_row)
312
324
  if self._progress:
313
- self._progress_update(-1,
314
- self.ref_total_count,
315
- self.ref_total_found_count,
316
- self.ref_total_notfound_count,
317
- self.ref_lookup_count,
318
- self.ref_lookup_cache_hit_count,
319
- self.ref_invalid_identifying_property_count)
325
+ self._progress({
326
+ "parse": True,
327
+ "refs": self.ref_total_count,
328
+ "refs_found": self.ref_total_found_count,
329
+ "refs_not_found": self.ref_total_notfound_count,
330
+ "refs_lookup": self.ref_lookup_count,
331
+ "refs_cache_hit": self.ref_lookup_cache_hit_count,
332
+ "refs_invalid": self.ref_invalid_identifying_property_count
333
+ })
320
334
  self._note_warning(reader.warnings, "reader")
321
335
  if schema:
322
336
  self._note_error(schema._unresolved_refs, "ref")
@@ -850,7 +864,7 @@ class Portal(PortalBase):
850
864
  return schemas
851
865
 
852
866
  @lru_cache(maxsize=64)
853
- def _get_schema_subtypes_names(self, type_name: str) -> List[str]:
867
+ def _get_schema_subtype_names(self, type_name: str) -> List[str]:
854
868
  if not (schemas_super_type_map := self.get_schemas_super_type_map()):
855
869
  return []
856
870
  return schemas_super_type_map.get(type_name, [])
@@ -913,7 +927,7 @@ class Portal(PortalBase):
913
927
  lookup_paths.append(f"/{type_name}/{value}")
914
928
  if is_ref_lookup_root and not is_ref_lookup_root_first:
915
929
  lookup_paths.append(f"/{value}")
916
- subtype_names = self._get_schema_subtypes_names(type_name) if is_ref_lookup_subtypes else []
930
+ subtype_names = self._get_schema_subtype_names(type_name) if is_ref_lookup_subtypes else []
917
931
  for subtype_name in subtype_names:
918
932
  lookup_paths.append(f"/{subtype_name}/{value}")
919
933
  if not lookup_paths:
@@ -952,7 +966,7 @@ class Portal(PortalBase):
952
966
  ref_lookup_strategy, ref_validator = (
953
967
  self._ref_lookup_strategy(type_name, self.get_schema(type_name), value))
954
968
  is_ref_lookup_subtypes = StructuredDataSet._is_ref_lookup_subtypes(ref_lookup_strategy)
955
- subtype_names = self._get_schema_subtypes_names(type_name) if is_ref_lookup_subtypes else []
969
+ subtype_names = self._get_schema_subtype_names(type_name) if is_ref_lookup_subtypes else []
956
970
  for type_name in [type_name] + subtype_names:
957
971
  is_resolved, resolved_item = self._ref_exists_single_internally(type_name, value)
958
972
  if is_resolved:
@@ -1014,7 +1028,7 @@ class Portal(PortalBase):
1014
1028
  if not is_uuid(property_value):
1015
1029
  return False
1016
1030
  return True
1017
- for schema_name in [type_name] + self._get_schema_subtypes_names(type_name):
1031
+ for schema_name in [type_name] + self._get_schema_subtype_names(type_name):
1018
1032
  if schema := self.get_schema(schema_name):
1019
1033
  if identifying_properties := schema.get("identifyingProperties"):
1020
1034
  for identifying_property in identifying_properties:
@@ -1039,7 +1053,7 @@ class Portal(PortalBase):
1039
1053
 
1040
1054
  def _cache_ref(self, type_name: str, value: str, resolved: List[str]) -> None:
1041
1055
  if self._ref_cache is not None:
1042
- subtype_names = self._get_schema_subtypes_names(type_name)
1056
+ subtype_names = self._get_schema_subtype_names(type_name)
1043
1057
  for type_name in [type_name] + subtype_names:
1044
1058
  self._ref_cache[f"/{type_name}/{value}"] = resolved
1045
1059
 
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: dcicutils
3
- Version: 8.8.0.1b23
3
+ Version: 8.8.0.1b24
4
4
  Summary: Utility package for interacting with the 4DN Data Portal and other 4DN resources
5
5
  Home-page: https://github.com/4dn-dcic/utils
6
6
  License: MIT
@@ -46,8 +46,8 @@ dcicutils/log_utils.py,sha256=7pWMc6vyrorUZQf-V-M3YC6zrPgNhuV_fzm9xqTPph0,10883
46
46
  dcicutils/misc_utils.py,sha256=zVc4urdVGgnWjQ4UQlrGH-URAzr2l_PwZWI3u_GJdFE,102210
47
47
  dcicutils/obfuscation_utils.py,sha256=fo2jOmDRC6xWpYX49u80bVNisqRRoPskFNX3ymFAmjw,5963
48
48
  dcicutils/opensearch_utils.py,sha256=V2exmFYW8Xl2_pGFixF4I2Cc549Opwe4PhFi5twC0M8,1017
49
- dcicutils/portal_object_utils.py,sha256=5FEE334DXWDUsl-RAQbV9-QZr-uwvKGqzXFZLZUJ87I,15264
50
- dcicutils/portal_utils.py,sha256=tG-rq-0oZws14XbUcuTnSjvdoH07KfJb0TWsaUug3g4,30051
49
+ dcicutils/portal_object_utils.py,sha256=7gteQ5CM6IVDfHx-UPFiOfeE1fJYOir_uwWdRTykExQ,15374
50
+ dcicutils/portal_utils.py,sha256=trM8L9J1CPXntdsKSL56hy7SMpftNNpIReAn5iihGes,30050
51
51
  dcicutils/project_utils.py,sha256=qPdCaFmWUVBJw4rw342iUytwdQC0P-XKpK4mhyIulMM,31250
52
52
  dcicutils/qa_checkers.py,sha256=cdXjeL0jCDFDLT8VR8Px78aS10hwNISOO5G_Zv2TZ6M,20534
53
53
  dcicutils/qa_utils.py,sha256=TT0SiJWiuxYvbsIyhK9VO4uV_suxhB6CpuC4qPacCzQ,160208
@@ -62,15 +62,15 @@ dcicutils/secrets_utils.py,sha256=8dppXAsiHhJzI6NmOcvJV5ldvKkQZzh3Fl-cb8Wm7MI,19
62
62
  dcicutils/sheet_utils.py,sha256=VlmzteONW5VF_Q4vo0yA5vesz1ViUah1MZ_yA1rwZ0M,33629
63
63
  dcicutils/snapshot_utils.py,sha256=ymP7PXH6-yEiXAt75w0ldQFciGNqWBClNxC5gfX2FnY,22961
64
64
  dcicutils/ssl_certificate_utils.py,sha256=F0ifz_wnRRN9dfrfsz7aCp4UDLgHEY8LaK7PjnNvrAQ,9707
65
- dcicutils/structured_data.py,sha256=B8TdvOMA4i2Spq05JAz5xr6jrFKMswyBxTOAJPdILDI,57025
65
+ dcicutils/structured_data.py,sha256=aXyLqYlgp5DInGiWw6WZk08vfvKI0IW2eWW57n0zhz0,57549
66
66
  dcicutils/task_utils.py,sha256=MF8ujmTD6-O2AC2gRGPHyGdUrVKgtr8epT5XU8WtNjk,8082
67
67
  dcicutils/tmpfile_utils.py,sha256=n95XF8dZVbQRSXBZTGToXXfSs3JUVRyN6c3ZZ0nhAWI,1403
68
68
  dcicutils/trace_utils.py,sha256=g8kwV4ebEy5kXW6oOrEAUsurBcCROvwtZqz9fczsGRE,1769
69
69
  dcicutils/validation_utils.py,sha256=cMZIU2cY98FYtzK52z5WUYck7urH6JcqOuz9jkXpqzg,14797
70
70
  dcicutils/variant_utils.py,sha256=2H9azNx3xAj-MySg-uZ2SFqbWs4kZvf61JnK6b-h4Qw,4343
71
71
  dcicutils/zip_utils.py,sha256=rnjNv_k6L9jT2SjDSgVXp4BEJYLtz9XN6Cl2Fy-tqnM,2027
72
- dcicutils-8.8.0.1b23.dist-info/LICENSE.txt,sha256=qnwSmfnEWMl5l78VPDEzAmEbLVrRqQvfUQiHT0ehrOo,1102
73
- dcicutils-8.8.0.1b23.dist-info/METADATA,sha256=zF1tJk8HgMrWpLI8ah39bG8vJi2egOZ8OqRJ33H9e1o,3357
74
- dcicutils-8.8.0.1b23.dist-info/WHEEL,sha256=7Z8_27uaHI_UZAc4Uox4PpBhQ9Y5_modZXWMxtUi4NU,88
75
- dcicutils-8.8.0.1b23.dist-info/entry_points.txt,sha256=51Q4F_2V10L0282W7HFjP4jdzW4K8lnWDARJQVFy_hw,270
76
- dcicutils-8.8.0.1b23.dist-info/RECORD,,
72
+ dcicutils-8.8.0.1b24.dist-info/LICENSE.txt,sha256=qnwSmfnEWMl5l78VPDEzAmEbLVrRqQvfUQiHT0ehrOo,1102
73
+ dcicutils-8.8.0.1b24.dist-info/METADATA,sha256=z5fS6VG0wLUCd3NTEvsMF5rdWwLg7TmWlTs1Syg-7Sk,3357
74
+ dcicutils-8.8.0.1b24.dist-info/WHEEL,sha256=7Z8_27uaHI_UZAc4Uox4PpBhQ9Y5_modZXWMxtUi4NU,88
75
+ dcicutils-8.8.0.1b24.dist-info/entry_points.txt,sha256=51Q4F_2V10L0282W7HFjP4jdzW4K8lnWDARJQVFy_hw,270
76
+ dcicutils-8.8.0.1b24.dist-info/RECORD,,