Skip to content

Commit

Permalink
minor code cleanup to structured_data
Browse files Browse the repository at this point in the history
  • Loading branch information
dmichaels-harvard committed Mar 11, 2024
1 parent 1abc397 commit 9ba4ef8
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 12 deletions.
16 changes: 5 additions & 11 deletions dcicutils/structured_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -885,12 +885,7 @@ def ref_exists(self, type_name: str, value: Optional[str] = None,
# self._data can change, i.e. as data (e.g. spreadsheet sheets) are parsed.
return self.ref_exists_internally(type_name, value, update_counts=called_from_map_ref) or {}
# Reference is NOT cached here; lookup INTERNALLY first.
if (resolved := self.ref_exists_internally(type_name, value, update_counts=called_from_map_ref)) is None:
# Reference was resolved (internally) INCORRECTLY.
if called_from_map_ref:
self._ref_total_notfound_count += 1
return None
if resolved:
if resolved := self.ref_exists_internally(type_name, value, update_counts=called_from_map_ref):
# Reference was resolved internally (note: here only if resolved is not an empty dictionary).
if called_from_map_ref:
self._ref_total_found_count += 1
Expand Down Expand Up @@ -939,15 +934,14 @@ def ref_exists_internally(self, type_name: str, value: Optional[str] = None,
update_counts: bool = False) -> Optional[dict]:
"""
Looks up the given reference (type/value) internally (i.e. with this data parsed thus far).
If found then returns a list of a single dictionary containing the (given) type name and
the uuid (if any) of the resolved item. If not found then returns an empty list; however,
if not found, but found using an invalid identifying property, then returns None.
If found then returns a dictionary containing the (given) type name and the uuid (if any)
of the resolved item.
"""
# print(f"\033[Kxyzzy:ref_exists_internally({type_name}/{value})")
if not value:
type_name, value = Portal._get_type_name_and_value_from_path(type_name)
if not type_name or not value:
return None
return None # Should not happen.
# Note that root lookup not applicable here.
ref_lookup_strategy, ref_validator = (
self._ref_lookup_strategy(type_name, self.get_schema(type_name), value))
Expand Down Expand Up @@ -1038,8 +1032,8 @@ def _ref_exists_from_cache(self, type_name: str, value: str) -> Optional[List[di
return None

def _cache_ref(self, type_name: str, value: str, resolved: List[str]) -> None:
subtype_names = self._get_schema_subtypes_names(type_name)
if self._ref_cache is not None:
subtype_names = self._get_schema_subtypes_names(type_name)
for type_name in [type_name] + subtype_names:
self._ref_cache[f"/{type_name}/{value}"] = resolved

Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "dcicutils"
version = "8.8.0.1b21" # TODO: To become 8.8.1
version = "8.8.0.1b22" # TODO: To become 8.8.1
description = "Utility package for interacting with the 4DN Data Portal and other 4DN resources"
authors = ["4DN-DCIC Team <support@4dnucleome.org>"]
license = "MIT"
Expand Down

0 comments on commit 9ba4ef8

Please sign in to comment.