Coverage for backend/ahuora-compounds/ahuora_compounds/CompoundDB.py: 67%
25 statements
« prev ^ index » next coverage.py v7.10.7, created at 2026-05-13 02:47 +0000
« prev ^ index » next coverage.py v7.10.7, created at 2026-05-13 02:47 +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 load_packages # Load all the packages to populate the registry
8__author__ = "Mahaki Leach"
10# Build the registry by running each package's registration function
11_registry = CompoundRegistry()
13load_packages(_registry)
15# Public read-only view of the registry
16db = RegistrySearch(_registry)
18@deprecated("get_compound")
19def get_compound(name: str) -> ChemsepCompound | None:
20 """
21 Get a compound by its name.
23 Args:
24 name (str): Name of the compound to retrieve.
26 Returns:
27 compound (dict): the compound chem-sep source data if found, otherwise None.
28 """
29 return ChemsepCompoundData.get(name, None)
31def get_compounds(names: list[str]) -> list[ChemsepCompound]:
32 """
33 Get a list of all compounds in the registry.
35 Returns:
36 list: List of all compounds.
37 """
38 compounds = [get_compound(name) for name in names]
39 if any(compound is None for compound in compounds):
40 missing_compounds = [name for name, compound in zip(names, compounds) if compound is None]
41 raise ValueError(f"Compounds not found: {', '.join(missing_compounds)}")
42 return compounds
45@deprecated("get_compound_names")
46def get_compound_names() -> list:
47 """
48 Returns a list of all compound names.
50 Returns:
51 list: List of compound names.
52 """
53 return db.get_compound_names()
56@deprecated("search_compounds")
57def search_compounds(query: str) -> list:
58 """
59 Searches for compounds based on the query.
61 Args:
62 query (str): The search query.
64 Returns:
65 list: List of compound names that match the query.
66 """
67 return db.search_compounds(query)
69# Restricting what can be imported from this module
70__all__ = ["db", "get_compound", "get_compound_names", "search_compounds"]