diff options
author | Trygve Laugstøl <trygvis@inamo.no> | 2019-05-27 15:16:12 +0200 |
---|---|---|
committer | Trygve Laugstøl <trygvis@inamo.no> | 2019-05-27 15:16:12 +0200 |
commit | d8bb3aa6f51b331ef6ce3558707627be7a50c7ad (patch) | |
tree | 780e426f8286fe9223d1fa6235464868bbef3d7c /src | |
parent | 94e8537430ab7496e4b8e697581d65b06cf8b979 (diff) | |
download | ee-python-d8bb3aa6f51b331ef6ce3558707627be7a50c7ad.tar.gz ee-python-d8bb3aa6f51b331ef6ce3558707627be7a50c7ad.tar.bz2 ee-python-d8bb3aa6f51b331ef6ce3558707627be7a50c7ad.tar.xz ee-python-d8bb3aa6f51b331ef6ce3558707627be7a50c7ad.zip |
souffle:
o Allowing to set MPNs when importing facts.
o ninja: Allowing the user to have its own datalog files under
ee/custom/kicad-souffle.dl and ee/custom/$supplier-souffle.dl.
make_bom: Generate per-field URIs for custom URIs. Better than making
values that contain custom field name + value.
Diffstat (limited to 'src')
-rw-r--r-- | src/ee/kicad/make_bom.py | 2 | ||||
-rw-r--r-- | src/ee/kicad/sch_fact_types.py | 5 | ||||
-rw-r--r-- | src/ee/souffle/digikey.dl | 3 | ||||
-rw-r--r-- | src/ee/souffle/kicad-mpn.dl | 8 | ||||
-rw-r--r-- | src/ee/souffle/kicad.dl | 1 | ||||
-rw-r--r-- | src/ee/tools/ninja.py | 7 | ||||
-rw-r--r-- | src/ee/tools/part_apply_souffle_post.py | 13 | ||||
-rw-r--r-- | src/ee/tools/templates/build.ninja.j2 | 7 |
8 files changed, 40 insertions, 6 deletions
diff --git a/src/ee/kicad/make_bom.py b/src/ee/kicad/make_bom.py index aa735b3..6069fcc 100644 --- a/src/ee/kicad/make_bom.py +++ b/src/ee/kicad/make_bom.py @@ -67,7 +67,7 @@ def work(sch, out: Path, project_uuid: UUID, new_mode, pretty): for f in c.named_fields: if f.value is not None and len(f.value): - part.facts.add(sch_fact_types.field, "{}:{}".format(f.name, f.value)) + part.facts.add(sch_fact_types.make_custom_field_key(f.name), f.value) parts.add_entry(part, True) diff --git a/src/ee/kicad/sch_fact_types.py b/src/ee/kicad/sch_fact_types.py index c9ea918..0e6ee1c 100644 --- a/src/ee/kicad/sch_fact_types.py +++ b/src/ee/kicad/sch_fact_types.py @@ -4,6 +4,9 @@ from ee.part import FactType def make_fact_key(key: str): return "http://purl.org/ee/kicad-sch-fact-type#{}".format(key) +def make_custom_field_key(field_name: str): + return "http://purl.org/ee/kicad-sch-custom-fact-type#{}".format(field_name) + value = FactType(make_fact_key("value"), "Value") component = FactType(make_fact_key("component"), "Value") @@ -14,5 +17,3 @@ symbol_name = FactType(make_fact_key("symbol-name"), "Value") footprint = FactType(make_fact_key("footprint"), "Value") footprint_library = FactType(make_fact_key("footprint-library"), "Value") footprint_name = FactType(make_fact_key("footprint-name"), "Value") - -field = FactType(make_fact_key("field"), "Value") diff --git a/src/ee/souffle/digikey.dl b/src/ee/souffle/digikey.dl index 735dd2d..06123ea 100644 --- a/src/ee/souffle/digikey.dl +++ b/src/ee/souffle/digikey.dl @@ -1,3 +1,6 @@ #include "facts.dl" .output fact + +fact(part, "http://purl.org/ee/fact-type/footprint", "1005") :- + fact(part, "http://purl.org/ee/digikey-fact-key#16", "0402 (1005 Metric)"). diff --git a/src/ee/souffle/kicad-mpn.dl b/src/ee/souffle/kicad-mpn.dl new file mode 100644 index 0000000..5f92dd9 --- /dev/null +++ b/src/ee/souffle/kicad-mpn.dl @@ -0,0 +1,8 @@ +.decl mpn(part:symbol, mpn:symbol) +.output mpn + +mpn(part, value) :- + fact(part, "http://purl.org/ee/kicad-sch-custom-fact-type#mpn", value). + +mpn(part, value) :- + fact(part, "http://purl.org/ee/kicad-sch-custom-fact-type#MPN", value). diff --git a/src/ee/souffle/kicad.dl b/src/ee/souffle/kicad.dl index 5448b05..16b76dd 100644 --- a/src/ee/souffle/kicad.dl +++ b/src/ee/souffle/kicad.dl @@ -1,4 +1,5 @@ #include "facts.dl" +#include "kicad-mpn.dl" .output fact diff --git a/src/ee/tools/ninja.py b/src/ee/tools/ninja.py index c5ee959..a58f0ed 100644 --- a/src/ee/tools/ninja.py +++ b/src/ee/tools/ninja.py @@ -58,9 +58,14 @@ def generate(project: Project): "ee": "{} -m ee".format(os.path.relpath(sys.executable, Path("."))), "project": project, "part_dbs": part_dbs, - "souffle_ee_src": Path(__file__).parent.parent / "souffle", + "souffle_ee_src": str(Path(__file__).parent.parent / "souffle"), + "is_file": lambda p: os.path.isfile(str(p)), } + kicad_souffle_dl = project.project_dir / "ee" / "custom" / "kicad-souffle.dl" + if kicad_souffle_dl.is_file(): + params["kicad_souffle_dl"] = str(kicad_souffle_dl) + gerber_zip = None if project.cfg.has_section("kicad-project"): diff --git a/src/ee/tools/part_apply_souffle_post.py b/src/ee/tools/part_apply_souffle_post.py index 4c23128..961b0c0 100644 --- a/src/ee/tools/part_apply_souffle_post.py +++ b/src/ee/tools/part_apply_souffle_post.py @@ -19,6 +19,8 @@ def work(in_path: Path, out_path: Path, work_dir: Path): for part in in_parts: out_parts.add_entry(part, False) + mpn_csv = work_dir / "out" / "mpn.csv" + with (work_dir / "out" / "fact.csv").open("r") as f: reader = csv.reader(f, dialect="excel-tab") for uri, key, value in reader: @@ -33,6 +35,17 @@ def work(in_path: Path, out_path: Path, work_dir: Path): print("New fact for {}: {}={}".format(uri, key, value)) part.facts.add(key, value) + if mpn_csv.is_file(): + with mpn_csv.open("r") as f: + reader = csv.reader(f, dialect="excel-tab") + for uri, mpn in reader: + try: + part = uri_idx.get_single(uri) + except KeyError: + raise EeException("Unknown part found in output: uri={}".format(uri)) + + part.add_mpn(mpn) + save_db(out_path, out_parts) diff --git a/src/ee/tools/templates/build.ninja.j2 b/src/ee/tools/templates/build.ninja.j2 index 894365b..5ae6085 100644 --- a/src/ee/tools/templates/build.ninja.j2 +++ b/src/ee/tools/templates/build.ninja.j2 @@ -98,8 +98,9 @@ build ee/sch.xml: part-apply-function ee/kicad/sch.xml build ee/kicad/souffle/facts.dl: part-apply-souffle-pre ee/kicad/sch.xml work = ee/kicad/souffle -build ee/kicad/souffle/out/fact.csv: souffle {{ souffle_ee_src }}/kicad.dl | ee/kicad/souffle/facts.dl +build ee/kicad/souffle/out/fact.csv: souffle {{ kicad_souffle_dl if kicad_souffle_dl else souffle_ee_src + "/kicad.dl" }} | ee/kicad/souffle/facts.dl work = ee/kicad/souffle +{#- includes = {{ (souffle_ee_src + "/kicad.dl") if kicad_souffle_dl else "" }}#} build ee/sch.xml: part-apply-souffle-post ee/kicad/souffle/out/fact.csv in_sch = ee/kicad/sch.xml @@ -135,7 +136,9 @@ build ee/{{ s }}/parts.xml: part-apply-function ee/{{ s }}/downloaded.xml build ee/{{ s }}/souffle/facts.dl: part-apply-souffle-pre ee/{{ s }}/downloaded.xml work = ee/{{ s }}/souffle -build ee/{{ s }}/souffle/out/fact.csv: souffle {{ souffle_ee_src }}/{{ s }}.dl | ee/{{ s }}/souffle/facts.dl +{%- set main=souffle_ee_src + "/" + s + ".dl" %} +{%- set alt="ee/custom/" + s + "-souffle.dl" %} +build ee/{{ s }}/souffle/out/fact.csv: souffle {{ alt if is_file(alt) else main }} | ee/{{ s }}/souffle/facts.dl work = ee/{{ s }}/souffle build ee/{{ s }}/parts.xml: part-apply-souffle-post ee/{{ s }}/souffle/out/fact.csv |