以下为本文档的中文说明library 是 Faebryk 硬件描述语言HDL的标准库模块位于 src/faebryk/library/ 目录下包含了可复用的电子元器件组件、特征Traits和接口Interfaces的集合。该技能的核心是描述这个库的结构组织方式、自动生成的 _F.py 文件的生成机制、以及添加新库模块时需遵守的约定和不变规则。Faebryk 是一个用 Python 描述硬件设计的框架而 library 模块就是它的“标准库”提供各种常用的电子元件模型。使用场景包括使用 Faebryk 进行电路设计时需要引用电阻、电容、IC 等标准元件扩展 Faebryk 生态时需要为新元件编写库模块或者理解 Faebryk 项目中 import faebryk.library._F as F 这种导入模式背后的机制。核心文件包括_F.py 是自动生成的 facade 文件它会快速导入并重新导出所有库模块供用户以 F.Resistor 的形式方便地访问gen_F.py 是生成器脚本它会扫描库目录下的所有 Python 文件检测其中的类和依赖关系然后自动生成 _F.py。核心特点在于(1) 自动生成机制避免了手动维护导入列表的繁琐和错误(2) 标准的组件接口定义确保了不同元件的一致使用体验(3) 模块化的组织方式使得库易于扩展和维护。Library ModuleThelibrarymodule (located insrc/faebryk/library/) contains the collection of reusable components, traits, and interfaces that form the “standard library” of the hardware design language.Quick Startimportfaebryk.core.faebrykpyasfbrkimportfaebryk.core.graphasgraphimportfaebryk.library._FasF ggraph.GraphView.create()tgfbrk.TypeGraph.create(gg)resistorF.Resistor.bind_typegraph(tgtg).create_instance(gg)Relevant FilesFacade (auto-generated):src/faebryk/library/_F.pyEagerly imports and re-exports library modules/types for theimport faebryk.library._F as Fpattern.This file is generated; do not hand-edit it.Generator:tools/library/gen_F.pyScanssrc/faebryk/library/*.py, detects whether the file contains a same-named class, and writes_F.py.Orders exports via a topological sort ofF.Namereferences to avoid import-order cycles.Components:src/faebryk/library/contains specific component definitions (e.g.Resistor.py,Capacitor.py,LED.py).Traits/Interfaces: Also contains trait definitions (e.g.can_bridge.py,is_power.py).Dependants (Call Sites)User Code: atopile projects heavily import fromfaebryk.library._F(aliased asF).Compiler: The compiler mapsatobuilt-ins to these classes.How to Work With / Develop / TestCore ConceptsTraits vs Components: Use Traits for behavior (what itcan dolikecan_bridge) and Components for physical things (what itislikeResistor).Export model:_F.pyis a generated “barrel” module; importing it is intentionally convenient but can be heavyweight.Development WorkflowNew Component: Create a new fileMyComponent.pyinsrc/faebryk/library/. Inherit fromNode(or a more specific base).Naming Convention: Class names should match the file basename (usually).Regenerate_F.py: runpython tools/library/gen_F.pyand commit the updatedsrc/faebryk/library/_F.py.TestingLibrary tests live undertest/library/(includingtest/library/nodes/).A good smoke test for new modules is:ato dev test --llm test/library/test_instance_library_modules.py -qBest PracticesAtomic Parts: Mark leaf components (specifically verified part numbers) with theis_atomic_parttrait.Parameters: UseF.Parametersto define physical properties likeresistance,capacitance, etc.Documentation: Add docstrings to components explaining their ports and parameters.