Coverage for backend/ahuora-compounds/ahuora_compounds/CompoundDB.py: 70%
26 statements
« prev ^ index » next coverage.py v7.10.7, created at 2026-03-26 20:57 +0000
« prev ^ index » next coverage.py v7.10.7, created at 2026-03-26 20:57 +0000
1from ahuora_compounds import deprecated
2from ahuora_compounds.CompoundRegistry import CompoundRegistry
3from ahuora_compounds.packages.chemsep import ChemsepCompound, ChemsepCompoundData
4from ahuora_compounds.RegistrySearch import RegistrySearch
5from ahuora_compounds.packages import packages_list
8__author__ = "Mahaki Leach"
10# Build the registry by running each package's registration function
11_registry = CompoundRegistry()
13for _load in packages_list:
14 _load(_registry)
16# Public read-only view of the registry
17db = RegistrySearch(_registry)
19@deprecated("get_compound")
20def get_compound(name: str) -> ChemsepCompound | None:
21 """
22 Get a compound by its name.
24 Args:
25 name (str): Name of the compound to retrieve.
27 Returns:
28 compound (dict): the compound chem-sep source data if found, otherwise None.
29 """
30 return ChemsepCompoundData.get(name, None)
32def get_compounds(names: list[str]) -> list[ChemsepCompound]:
33 """
34 Get a list of all compounds in the registry.
36 Returns:
37 list: List of all compounds.
38 """
39 compounds = [get_compound(name) for name in names]
40 if any(compound is None for compound in compounds):
41 missing_compounds = [name for name, compound in zip(names, compounds) if compound is None]
42 raise ValueError(f"Compounds not found: {', '.join(missing_compounds)}")
43 return compounds
46@deprecated("get_compound_names")
47def get_compound_names() -> list:
48 """
49 Returns a list of all compound names.
51 Returns:
52 list: List of compound names.
53 """
54 return db.get_compound_names()
57@deprecated("search_compounds")
58def search_compounds(query: str) -> list:
59 """
60 Searches for compounds based on the query.
62 Args:
63 query (str): The search query.
65 Returns:
66 list: List of compound names that match the query.
67 """
68 return db.search_compounds(query)
70# Restricting what can be imported from this module
71__all__ = ["db", "get_compound", "get_compound_names", "search_compounds"]