Skip to content
This repository has been archived by the owner on Dec 10, 2024. It is now read-only.

Commit

Permalink
Protect indexing files
Browse files Browse the repository at this point in the history
  • Loading branch information
mawildoer committed Oct 31, 2024
1 parent e73886d commit e0fa9c1
Showing 1 changed file with 12 additions and 5 deletions.
17 changes: 12 additions & 5 deletions src/faebryk/exporters/schematic/kicad/transformer.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ def __init__(
self.sch = sch
self.graph = graph
self.app = app
self._symbol_files_index: dict[str, Path] = {}
self._symbol_files_index: dict[str, Path] | None = None

self.missing_symbols: list[F.Symbol] = []

Expand Down Expand Up @@ -185,6 +185,12 @@ def attach_symbol(self, f_symbol: F.Symbol, sym_inst: SCH.C_symbol_instance):
def index_symbol_files(
self, fp_lib_tables: PathLike | list[PathLike], load_globals: bool = True
) -> None:
"""
Index the symbol files in the given library tables
"""
if self._symbol_files_index is None:
self._symbol_files_index = {}

if isinstance(fp_lib_tables, (str, Path)):
fp_lib_table_paths = [Path(fp_lib_tables)]
else:
Expand Down Expand Up @@ -229,8 +235,11 @@ def get_all_symbols(self) -> List[tuple[Module, F.Symbol]]:
@once
def get_symbol_file(self, lib_name: str) -> C_kicad_sym_file:
# primary caching handled by @once
if self._symbol_files_index is None:
raise ValueError("Symbol files index not indexed")

if lib_name not in self._symbol_files_index:
raise FaebrykException(f"Symbol file {lib_name} not found")
raise FaebrykException(f"Symbol file \"{lib_name}\" not found")

path = self._symbol_files_index[lib_name]
return C_kicad_sym_file.loads(path)
Expand Down Expand Up @@ -369,9 +378,7 @@ def _mark[R: _HasUUID | _HasPropertys](cls, obj: R) -> R:

if hasattr(obj, "propertys"):
obj.propertys[cls.MARK_NAME] = C_property(
name=cls.MARK_NAME,
value=hashed_contents,
effects=C_effects(hide=True)
name=cls.MARK_NAME, value=hashed_contents, effects=C_effects(hide=True)
)
return obj

Expand Down

0 comments on commit e0fa9c1

Please sign in to comment.