diff --git a/CHANGELOG.rst b/CHANGELOG.rst index b4a3d6c06..f206702b4 100644 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst @@ -6,6 +6,12 @@ dcicutils Change Log ---------- +8.18.3 +====== +* dmichaels / 2025-03-05 / branch: dmichaels-20250305-add-portal-get-schema-super-types / PR-328 + - Added method portal_utils.get_schema_super_type_names (for use by smaht-submitr). + + 8.18.1 ====== * dmichaels / 2025-02-28 / branch: dmichaels-20250228-correct-submitr-config-path / PR-327 diff --git a/dcicutils/portal_utils.py b/dcicutils/portal_utils.py index b2378c75a..5dde8614d 100644 --- a/dcicutils/portal_utils.py +++ b/dcicutils/portal_utils.py @@ -471,6 +471,19 @@ def list_breadth_first(super_type_map: dict, super_type_name: str) -> dict: super_type_map_flattened[super_type_name] = list_breadth_first(super_type_map, super_type_name) return super_type_map_flattened + @lru_cache(maxsize=100) + def get_schema_super_type_names(self, schema_name: str, include_schema_name: bool = False) -> List[str]: + super_types = set() + if isinstance(schema_name, str) and (schema_name := self.schema_name(schema_name)): + if isinstance(super_type_map := self.get_schemas_super_type_map(), dict): + for super_type_name in super_type_map: + if schema_name in super_type_map[super_type_name]: + super_types.add(super_type_name) + super_types = list(super_types) + if (include_schema_name is True) and self.get_schema(schema_name): + super_types.insert(0, schema_name) + return super_types + @lru_cache(maxsize=100) def get_schema_subtype_names(self, type_name: str) -> List[str]: if not (schemas_super_type_map := self.get_schemas_super_type_map()): diff --git a/dcicutils/submitr/custom_excel.py b/dcicutils/submitr/custom_excel.py index fdf8b5cbb..9f4ea5291 100644 --- a/dcicutils/submitr/custom_excel.py +++ b/dcicutils/submitr/custom_excel.py @@ -95,7 +95,8 @@ def sheet_reader(self, sheet_name: str) -> ExcelSheetReader: return CustomExcelSheetReader(self, sheet_name=sheet_name, workbook=self._workbook, custom_column_mappings=self._custom_column_mappings) - def effective_sheet_name(self, sheet_name: str) -> str: + @staticmethod + def effective_sheet_name(sheet_name: str) -> str: if (underscore := sheet_name.find("_")) > 1: return sheet_name[underscore + 1:] return sheet_name @@ -151,11 +152,21 @@ def __init__(self, *args, **kwargs) -> None: ARGUMENT_NAME_CUSTOM_COLUMN_MAPPINGS = "custom_column_mappings" self._custom_column_mappings = None if ARGUMENT_NAME_CUSTOM_COLUMN_MAPPINGS in kwargs: + def lookup_custom_column_mappings(custom_column_mappings: dict, sheet_name: str) -> Optional[dict]: + if isinstance(custom_column_mappings, dict) and isinstance(sheet_name, str): + if isinstance(found_custom_column_mappings := custom_column_mappings.get(sheet_name), dict): + return found_custom_column_mappings + if (effective_sheet_name := CustomExcel.effective_sheet_name(sheet_name)) != sheet_name: + if isinstance(found_custom_column_mappings := + custom_column_mappings.get(effective_sheet_name), dict): + return found_custom_column_mappings + return None custom_column_mappings = kwargs[ARGUMENT_NAME_CUSTOM_COLUMN_MAPPINGS] del kwargs[ARGUMENT_NAME_CUSTOM_COLUMN_MAPPINGS] if not (isinstance(custom_column_mappings, dict) and isinstance(sheet_name := kwargs.get(ARGUMENT_NAME_SHEET_NAME, None), str) and - isinstance(custom_column_mappings := custom_column_mappings.get(sheet_name), dict)): + isinstance(custom_column_mappings := + lookup_custom_column_mappings(custom_column_mappings, sheet_name), dict)): custom_column_mappings = None self._custom_column_mappings = custom_column_mappings super().__init__(*args, **kwargs) diff --git a/pyproject.toml b/pyproject.toml index 6ebeb31cb..6e2a22878 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [tool.poetry] name = "dcicutils" -version = "8.18.1" +version = "8.18.3" description = "Utility package for interacting with the 4DN Data Portal and other 4DN resources" authors = ["4DN-DCIC Team "] license = "MIT"