aboutsummaryrefslogtreecommitdiff
path: root/src/ee/tools/ninja.py
diff options
context:
space:
mode:
Diffstat (limited to 'src/ee/tools/ninja.py')
-rw-r--r--src/ee/tools/ninja.py41
1 files changed, 22 insertions, 19 deletions
diff --git a/src/ee/tools/ninja.py b/src/ee/tools/ninja.py
index f04b174..a5bbe5b 100644
--- a/src/ee/tools/ninja.py
+++ b/src/ee/tools/ninja.py
@@ -40,7 +40,7 @@ def noext_filter(s: Union[str, Path]) -> str:
return os.path.splitext(os.path.basename(str(s)))[0]
-def generate(project: Project, sch_path: Path, kicad_bom_strategy: Optional[str]):
+def generate(project: Project, kicad_bom_strategy: Optional[str]):
def _create_env():
e = Environment(
loader=PackageLoader(__name__, "templates"),
@@ -53,22 +53,31 @@ def generate(project: Project, sch_path: Path, kicad_bom_strategy: Optional[str]
e.filters["noext"] = noext_filter
return e
- gerber_zip = "prod/gerber.zip"
-
- sch = read_schematics(str(sch_path))
-
- sch_files = sorted([s.path for s in sch.schematics])
-
part_dbs = []
params = {
"ee": "{} -m ee".format(os.path.relpath(sys.executable, Path("."))),
"project": project,
- "sch": sch_path,
- "sch_files": sch_files, "kicad_bom_strategy": kicad_bom_strategy,
- "pcb": str(sch_path).replace(".sch", ".kicad_pcb"),
"part_dbs": part_dbs,
}
+ gerber_zip = None
+
+ if project.cfg.has_section("kicad-project"):
+ kp = project.cfg["kicad-project"]
+ if "sch" in kp:
+ sch_path = Path(project.cfg["kicad-project"]["sch"])
+ sch = read_schematics(str(sch_path))
+
+ sch_files = sorted([s.path for s in sch.schematics])
+
+ params["sch"] = sch_path
+ params["sch_files"] = sch_files
+ params["kicad_bom_strategy"] = kicad_bom_strategy
+
+ if "pcb" in kp:
+ params["pcb"] = Path(project.cfg["kicad-project"]["pcb"])
+ gerber_zip = "prod/gerber.zip"
+
# TODO: read from config
distributors = ["digikey"]
params["distributors"] = distributors
@@ -77,10 +86,9 @@ def generate(project: Project, sch_path: Path, kicad_bom_strategy: Optional[str]
params["gerber_zip"] = gerber_zip
# ee_dir = sch_path.parent / "ee"
- ee_dir = Path(".")
- build_ninja = ee_dir / "build.ninja"
+ build_ninja = project.project_dir / "build.ninja"
- parts_yaml_files = [path for path in ee_dir.iterdir() if str(path).endswith("-parts.yaml")]
+ parts_yaml_files = [path for path in project.project_dir.iterdir() if str(path).endswith("-parts.yaml")]
params["parts_yaml_files"] = parts_yaml_files
# Local part databases first
@@ -95,15 +103,10 @@ def generate(project: Project, sch_path: Path, kicad_bom_strategy: Optional[str]
parser = argparse.ArgumentParser()
-parser.add_argument("--sch",
- required=True,
- metavar="FILE")
-
parser.add_argument("--kicad-bom-strategy",
required=False,
metavar="PY CALLABLE")
args = parser.parse_args()
-project = Project.load()
-generate(project, Path(args.sch), args.kicad_bom_strategy)
+generate(Project.load(), args.kicad_bom_strategy)