diff options
author | Trygve Laugstøl <trygvis@inamo.no> | 2019-03-28 21:23:27 +0100 |
---|---|---|
committer | Trygve Laugstøl <trygvis@inamo.no> | 2019-03-28 21:23:27 +0100 |
commit | b462f533cba12d58c4b265c0a658909b0752153e (patch) | |
tree | 516491980acc26c6da4e953704563f842d7aea0a | |
parent | f0c1785f42b17b5024c3e76681c603351013c780 (diff) | |
download | ee-python-b462f533cba12d58c4b265c0a658909b0752153e.tar.gz ee-python-b462f533cba12d58c4b265c0a658909b0752153e.tar.bz2 ee-python-b462f533cba12d58c4b265c0a658909b0752153e.tar.xz ee-python-b462f533cba12d58c4b265c0a658909b0752153e.zip |
create-distributor-search-list: Ignore mechanical parts.
create-order: Adding an option for a strategy to ignore/modify parts.
ninja/init: Moving strategy from ninja to init so they're more
persistent.
-rw-r--r-- | src/ee/kicad/make_bom.py | 4 | ||||
-rw-r--r-- | src/ee/order/__init__.py | 22 | ||||
-rw-r--r-- | src/ee/part/create_distributor_search_list.py | 11 | ||||
-rw-r--r-- | src/ee/part/fact_keys.py | 2 | ||||
-rw-r--r-- | src/ee/tools/create_order.py | 7 | ||||
-rw-r--r-- | src/ee/tools/init.py | 27 | ||||
-rw-r--r-- | src/ee/tools/ninja.py | 9 | ||||
-rw-r--r-- | src/ee/tools/templates/build.ninja.j2 | 11 |
8 files changed, 69 insertions, 24 deletions
diff --git a/src/ee/kicad/make_bom.py b/src/ee/kicad/make_bom.py index ca335cd..db4f80e 100644 --- a/src/ee/kicad/make_bom.py +++ b/src/ee/kicad/make_bom.py @@ -90,10 +90,10 @@ class MakeBomStrategy(): dpn_strategy_factory(self.dpn_mappings), ] - def process_part(self, component: Component, part: types.Part): + def process_part(self, component: Component, part: Part): return self.default_process_part(component, part) - def default_process_part(self, component: Component, part: types.Part): + def default_process_part(self, component: Component, part: Part): return apply_strategies(component, part, self.default_strategies) diff --git a/src/ee/order/__init__.py b/src/ee/order/__init__.py index fc112d1..1624870 100644 --- a/src/ee/order/__init__.py +++ b/src/ee/order/__init__.py @@ -1,6 +1,7 @@ import os.path +import pydoc from pathlib import Path -from typing import List, MutableMapping +from typing import List, MutableMapping, Optional from ee import EeException from ee.db import ObjDb @@ -29,8 +30,18 @@ def make_report(out_file, unresolved_parts, order_parts: ObjDb[OrderPart], suppl report.save_report("ee.order", "order.rst.j2", out_file, **kwargs) +def default_strategy(x): + return x + + def create_order(project: Project, schematic_path: Path, out_path: Path, part_dbs: List[Path], - fail_on_missing_parts: bool): + fail_on_missing_parts: bool, strategy_name: Optional[str]): + strategy = default_strategy + if strategy_name: + strategy = pydoc.locate(strategy_name) + if not callable(strategy): + raise EeException("Not a callable: {}, is a {}".format(strategy_name, type(strategy))) + supplier_parts = ObjDb[Part]() supplier_parts.add_unique_index("uri", lambda p: p.uri) supplier_parts.add_index("spn", lambda p: [ref.valueProp for ref in p.get_spns()], @@ -54,7 +65,12 @@ def create_order(project: Project, schematic_path: Path, out_path: Path, part_db op.part.get_mpns()] if op.part.supplier else None, multiple=True) for sch_part in sch_db.iterparts(): - order_parts.add(OrderPart(sch_part)) + part = OrderPart(sch_part) + part.part = strategy(part.part) + if part.part is None: + continue + + order_parts.add(part) for order_part in order_parts: sch_part_numbers = [pn.valueProp for pn in order_part.part.get_mpns()] diff --git a/src/ee/part/create_distributor_search_list.py b/src/ee/part/create_distributor_search_list.py index fef1690..8d70e3e 100644 --- a/src/ee/part/create_distributor_search_list.py +++ b/src/ee/part/create_distributor_search_list.py @@ -1,10 +1,14 @@ from pathlib import Path -from ee.part import PartDb, load_db, save_db, Part +from ee.part import PartDb, load_db, save_db, Part, fact_keys from ee.xml import types __all__ = ["create_distributor_search_list"] +ignored_part_classes = [ + "mechanical" +] + def create_distributor_search_list(in_path: Path, out_path: Path): in_parts = load_db(in_path) @@ -16,6 +20,11 @@ def create_distributor_search_list(in_path: Path, out_path: Path): part = Part(xml) pn_value = next((p.valueProp for p in part.get_mpns()), None) + part_class = part.find_fact(fact_keys.part_class) + if part_class: + if part_class.valueProp in ignored_part_classes: + continue + if pn_value is None: refs = [ref.referenceProp for ref in part.get_schematic_references()] print("Skipping part with no part number: schematic reference: {}".format(", ".join(refs))) diff --git a/src/ee/part/fact_keys.py b/src/ee/part/fact_keys.py index 5ca3c5b..f1f02c5 100644 --- a/src/ee/part/fact_keys.py +++ b/src/ee/part/fact_keys.py @@ -11,3 +11,5 @@ value = "http://purl.org/ee/fact-type/value" place_part = "http://purl.org/ee/fact-type/place-part" imperial_footprint_size = "http://purl.org/ee/fact-type/imperial-footprint-size" + +part_class = "http://purl.org/ee/fact-type/part-class" diff --git a/src/ee/tools/create_order.py b/src/ee/tools/create_order.py index f2143a8..d740ff2 100644 --- a/src/ee/tools/create_order.py +++ b/src/ee/tools/create_order.py @@ -8,7 +8,7 @@ parser = argparse.ArgumentParser() parser.add_argument("--schematic", required=True, - metavar="DIR") + metavar="PART DB") parser.add_argument("--out", required=True, @@ -19,10 +19,13 @@ parser.add_argument("--part-db", required=True, metavar="PART DB") +parser.add_argument("--strategy", + metavar="FUNC") + args = parser.parse_args() project = Project.load() part_db_dirs = [Path(part_db) for part_db in args.part_db] fail_on_missing_parts = False -create_order(project, Path(args.schematic), Path(args.out), part_db_dirs, fail_on_missing_parts) +create_order(project, Path(args.schematic), Path(args.out), part_db_dirs, fail_on_missing_parts, args.strategy) diff --git a/src/ee/tools/init.py b/src/ee/tools/init.py index f87c958..74a67d1 100644 --- a/src/ee/tools/init.py +++ b/src/ee/tools/init.py @@ -6,19 +6,19 @@ from ee.project import Project import configparser -def init_kicad_project(basedir: Path, cfg): +def init_kicad_project(basedir: Path, cfg, args): pro_files: List[Path] = [f for f in basedir.iterdir() if f.name.endswith(".pro")] if len(pro_files) == 0: return + cfg.add_section("kicad-project") + if len(pro_files) == 1: pro_file = pro_files[0] sch_file: Path = pro_file.parent / (pro_file.name[0:-4] + ".sch") pcb_file: Path = pro_file.parent / (pro_file.name[0:-4] + ".kicad_pcb") - cfg.add_section("kicad-project") - if sch_file.is_file(): print("Found KiCAD project and schematic") cfg["kicad-project"]["sch"] = str(sch_file) @@ -28,19 +28,26 @@ def init_kicad_project(basedir: Path, cfg): else: print("Found more than one kicad project file.") + if args.kicad_bom_strategy: + cfg["kicad-project"]["strategy"] = args.kicad_bom_strategy + def init_seeed_opl(project: Project): import ee.supplier.seeed ee.supplier.seeed.init_project(project) -def init(project_dir: Path, basedir: Path): +def init(project_dir: Path, basedir: Path, args): cfg = configparser.ConfigParser() project = Project(project_dir, cfg) - init_kicad_project(basedir, cfg) + init_kicad_project(basedir, cfg, args) init_seeed_opl(project) + if args.create_order_strategy: + project.cfg.add_section("create-order") + project.cfg["create-order"]["strategy"] = args.create_order_strategy + print("Saving project. Now run 'ee ninja' to generate Ninja build file") project.save() @@ -50,9 +57,17 @@ parser = argparse.ArgumentParser() parser.add_argument("--basedir", metavar="DIR") +parser.add_argument("--kicad-bom-strategy", + required=False, + metavar="PY CALLABLE") + +parser.add_argument("--create-order-strategy", + required=False, + metavar="PY CALLABLE") + args = parser.parse_args() if not args.basedir: args.basedir = "." -init(Path("."), Path(args.basedir)) +init(Path("."), Path(args.basedir), args) diff --git a/src/ee/tools/ninja.py b/src/ee/tools/ninja.py index a5bbe5b..c53b5da 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, kicad_bom_strategy: Optional[str]): +def generate(project: Project): def _create_env(): e = Environment( loader=PackageLoader(__name__, "templates"), @@ -72,7 +72,6 @@ def generate(project: Project, kicad_bom_strategy: Optional[str]): 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"]) @@ -103,10 +102,6 @@ def generate(project: Project, kicad_bom_strategy: Optional[str]): parser = argparse.ArgumentParser() -parser.add_argument("--kicad-bom-strategy", - required=False, - metavar="PY CALLABLE") - args = parser.parse_args() -generate(Project.load(), args.kicad_bom_strategy) +generate(Project.load()) diff --git a/src/ee/tools/templates/build.ninja.j2 b/src/ee/tools/templates/build.ninja.j2 index 227b68c..6efe20b 100644 --- a/src/ee/tools/templates/build.ninja.j2 +++ b/src/ee/tools/templates/build.ninja.j2 @@ -43,7 +43,7 @@ rule element14-normalize-facts rule create-order description = create-order - command = $ee create-order --schematic $schematic --part-db $part_dbs --out $out + command = $ee create-order --schematic $schematic --part-db $part_dbs --out $out $strategy rule import-parts-yaml description = import-parts-yaml $in @@ -57,8 +57,10 @@ build {{ gerber_zip }}: kicad-gerber $pcb {% if sch is defined -%} build ee/sch.xml: kicad-make-bom $sch - strategy ={{ " --strategy " + kicad_bom_strategy if kicad_bom_strategy else "" }} -{% endif -%} +{%- if project.cfg["kicad-project"]["strategy"] %} + strategy = --strategy {{ project.cfg["kicad-project"]["strategy"] }} +{%- endif %} +{%- endif %} {% for d in distributors %} # Distributor {{ d }} build ee/{{ d }}/search-list.xml: part-create-distributor-search-list ee/sch.xml @@ -80,6 +82,9 @@ build {{ out }}: import-parts-yaml {{ f }} build ee/order.xml | $report_dir/order.rst: create-order ee/sch.xml {%- for p in part_dbs %} {{ p }}.xml{% endfor %} schematic = ee/sch.xml part_dbs ={%- for p in part_dbs %} {{ p }}.xml{% endfor %} +{%- if project.cfg["create-order"]["strategy"] %} + strategy = --strategy {{ project.cfg["create-order"]["strategy"] }} +{%- endif %} default ee/order.xml |