← Commit history

Profile preferences are listed for tools, never written as KiCad rules: KiCad applies one rule per constraint, so a warning-level preference would replace the fab's error-level limit

John Lauer ·7195b16520 · ·parent f738814
4 files changed +28−32
README.md+4−2
@@ -37,7 +37,7 @@ taking the worst case everywhere. People have different comfort margins and taste. Someone may want 1 mil of extra spacing; someone else pushes silkscreen text as small as the fab allows. Those choices are **profiles**: a file in `rules/profiles/` that names its author and says why, and either overrides limits (as errors),-adds preferences (as warnings, never errors), or freezes a reviewed set of files.+lists preferences (taste that tools warn on, never DRC errors), or freezes a reviewed set of files. `tools/generate.py` writes each profile's files beside the published ones as `<vendor>[-<process>]-<n>L-<profile>.<ext>`, and `rules/index.json` lists them under their pack. You pick a pack and a profile at the start of a design (AI Flow asks), and you can switch later.@@ -56,7 +56,9 @@ To add your own, put a profile JSON in `rules/profiles/` and open a PR: ```  `overrides` replace published limits and fail DRC. `preferences` (`silkMinTextHeight`,-`minTraceWidth`) only warn. A change to a published record needs the fab's own page as its source;+`minTraceWidth`) are taste: they are listed in `rules/index.json` and tools warn on them (AI Flow does),+but they are never written into the rules files, because KiCad applies one rule per constraint to an+item and a warning-level preference would replace the fab's error-level limit. A change to a published record needs the fab's own page as its source; anything else is a profile (`tools/test_profiles.py` refuses margin wording in a record).  ## Vendors
SKILL.md+1−1
@@ -27,7 +27,7 @@ or Altium; a bridge needs the rule files for `fusion_set_design_rules   EAGLE `.dru` text, per vendor, process and layer count. - `kicad/`: `.kicad_dru` custom rules plus `.board-setup.json` constraints. - `altium/`: `.RUL` ASCII exports (generated, not yet import-verified).-- `rules/profiles/`: opt-in profiles on top of a published record (an author, a why, overrides as errors, preferences as warnings, or frozen reviewed files). Their files sit beside the published ones as `<pack>-<profile>.<ext>` and `rules/index.json` lists them under the pack.+- `rules/profiles/`: opt-in profiles on top of a published record (an author, a why, overrides as errors, preferences that tools warn on but never write into the rules files, or frozen reviewed files). Their files sit beside the published ones as `<pack>-<profile>.<ext>` and `rules/index.json` lists them under the pack. - `tools/generate.py`: regenerates every file from the records. - `verification/`: dated proof that the generated files load in real EDA   tools, with screenshots.
tools/generate.py+16−23
@@ -601,13 +601,15 @@ def gen_table(records): # (stricter margins, smaller or bigger silkscreen text) is a profile in rules/profiles/<vendor>-<n>L-<name>.json: #   {"name", "vendorSlug", "process", "layerCount", "author", "why", #    "overrides": {<record field>: {...}},         limits that replace the published ones (errors)-#    "preferences": {"silkMinTextHeight": {"mm"}, "minTraceWidth": {"mm"}},  taste: KiCad warnings, never errors+#    "preferences": {"silkMinTextHeight": {"mm"}, "minTraceWidth": {"mm"}},  taste, never written into the+#                    rules files: KiCad applies ONE rule per constraint to an item (the last that matches), so a+#                    warning-level preference rule would replace the fab's error-level limit. Tools read them from+#                    rules/index.json and warn on their own (AI Flow does at rules use, rules check and finish). #    "frozen": {<ext>: {"file", "sha256"}}}        reviewed bytes copied as is (hash-checked) # Each profile writes <vendor>[-<process>]-<n>L-<name>.<ext> beside the published files.  OUT_DIRS = {"kicad_dru": "kicad", "board-setup.json": "kicad", "dru": "fusion", "edru": "fusion", "RUL": "altium"}-PREF_RULES = {"silkMinTextHeight": ("pref-silk-text-height", "text_height", "A.Type == 'Text' || A.Type == 'Text Box'", "*.SilkS"),-              "minTraceWidth": ("pref-track-width", "track_width", None, None)}+PREFERENCES = ("silkMinTextHeight", "minTraceWidth")   def merged(rec, overrides):@@ -617,20 +619,11 @@ def merged(rec, overrides):     return out  -def preference_rules(prefs):-    out = []+def check_preferences(prefs, where):     for key, v in (prefs or {}).items():-        if key not in PREF_RULES or not isinstance(v, dict) or v.get("mm") is None:-            sys.exit(f"profile preference {key!r}: supported preferences are {sorted(PREF_RULES)}, each {{\"mm\": value}}")-        name, kind, cond, layer = PREF_RULES[key]-        rows = [f'(rule "{name}"', "  (severity warning)", f"  (constraint {kind} (min {fmm(v['mm'])}mm))"]-        if layer:-            rows.append(f'  (layer "{layer}")')-        if cond:-            rows.append(f'  (condition "{cond}")')-        rows[-1] += ")"-        out += rows + [""]-    return "\n".join(out)+        if key not in PREFERENCES or not isinstance(v, dict) or not isinstance(v.get("mm"), (int, float)) or v["mm"] <= 0:+            sys.exit(f"{where}: preference {key!r}: supported preferences are {list(PREFERENCES)}, each {{\"mm\": positive value}}")+    return prefs or {}   def build_profiles(by_key, index):@@ -655,17 +648,17 @@ def build_profiles(by_key, index):         else:             r = merged(rec, p.get("overrides"))             v = r["vendor"]-            dru = gen_kicad_dru(v, r)-            prefs = preference_rules(p.get("preferences"))-            if prefs:-                dru = dru.rstrip("\n") + "\n\n# preferences of this profile: warnings, never errors\n" + prefs-            outs = {"kicad_dru": dru, "board-setup.json": gen_kicad_board_setup(v, r), "dru": gen_dru(v, r), "edru": gen_edru(v, r), "RUL": gen_rul(v, r)}+            outs = {"kicad_dru": gen_kicad_dru(v, r), "board-setup.json": gen_kicad_board_setup(v, r), "dru": gen_dru(v, r), "edru": gen_edru(v, r), "RUL": gen_rul(v, r)}             for ext, text in outs.items():                 (ROOT / OUT_DIRS[ext] / f"{vs}.{ext}").write_text(text)                 files[ext] = f"{OUT_DIRS[ext]}/{vs}.{ext}"         entry = next(e for e in index["vendors"] if (e["vendorSlug"], e["process"], e["layerCount"]) == (p["vendorSlug"], p["process"], p["layerCount"]))-        entry.setdefault("profiles", []).append({"name": p["name"], "author": p["author"], "why": p["why"], "frozen": bool(p.get("frozen")),-                                                 "definition": f"rules/profiles/{pf.name}", "files": files})+        row = {"name": p["name"], "author": p["author"], "why": p["why"], "frozen": bool(p.get("frozen")),+               "definition": f"rules/profiles/{pf.name}", "files": files}+        prefs = check_preferences(p.get("preferences"), pf.name)+        if prefs:+            row["preferences"] = prefs+        entry.setdefault("profiles", []).append(row)   def main():
tools/test_profiles.py+7−6
@@ -55,18 +55,19 @@ class Profiles(unittest.TestCase):         self.assertEqual(hashlib.sha256((BASE / 'kicad/pcbway-4L-circuit-forge-strict.kicad_dru').read_bytes()).hexdigest(), 'ed114795f294b9e6355627166f0d557132d848f2325389c8f54b0b7cf7ee0ef4')         self.assertEqual(hashlib.sha256((BASE / 'kicad/pcbway-4L-circuit-forge-strict.board-setup.json').read_bytes()).hexdigest(), '01edbd0b23d3bbe4807e6428dc24ca4dfe320bb4986a963db44c914e4d33a9a5') -    def test_overrides_are_errors_and_preferences_only_warn(self):+    def test_overrides_are_errors_and_preferences_stay_out_of_the_rules_files(self):         rec = [r for _, v, r in records() if v == 'PCBWay' and r['process'] == 'standard' and r['layerCount'] == 2][0]         rec = {**rec, 'vendor': 'PCBWay'}         tighter = g.merged(rec, {'minTraceWidth': {'mm': 0.2}})         self.assertEqual(tighter['minTraceWidth']['mm'], 0.2)         self.assertEqual(rec['minTraceWidth']['mm'] != 0.2, True, 'the record itself is untouched')-        prefs = g.preference_rules({'silkMinTextHeight': {'mm': 0.6}})-        self.assertIn('(severity warning)', prefs)-        self.assertIn('(constraint text_height (min 0.6mm))', prefs)-        self.assertNotIn('(severity error)', prefs)+        # preferences are validated and listed for tools, never written as KiCad rules: KiCad applies one rule per+        # constraint to an item, so a preference rule would replace the fab's error-level limit+        self.assertEqual(g.check_preferences({'silkMinTextHeight': {'mm': 0.6}}, 't'), {'silkMinTextHeight': {'mm': 0.6}})         with self.assertRaises(SystemExit):-            g.preference_rules({'unknownThing': {'mm': 1}})+            g.check_preferences({'unknownThing': {'mm': 1}}, 't')+        with self.assertRaises(SystemExit):+            g.check_preferences({'minTraceWidth': {'mm': -1}}, 't')      def test_index_lists_profiles_beside_their_published_pack(self):         idx = json.loads((BASE / 'rules' / 'index.json').read_text())