usetraces 0.1.0__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
usetraces/__init__.py ADDED
@@ -0,0 +1,3 @@
1
+ """Installer helpers for the traces KiCad plugin."""
2
+
3
+ __version__ = "0.1.0"
usetraces/cli.py ADDED
@@ -0,0 +1,87 @@
1
+ from __future__ import annotations
2
+
3
+ import argparse
4
+ import shutil
5
+ from contextlib import ExitStack
6
+ from importlib.resources import as_file, files
7
+ from pathlib import Path
8
+
9
+
10
+ PLUGIN_FILES = ("traces.py", "traces.png")
11
+ OLD_PLUGIN_FILES = (
12
+ "backend_ping.py",
13
+ "part_link_check.py",
14
+ "prop_editor.py",
15
+ "schematic_0402_check.py",
16
+ "schematic_snapshot.py",
17
+ )
18
+ PROD_BACKEND = 'BACKEND_URL = "https://usetraces.com"'
19
+ DEV_BACKEND = 'BACKEND_URL = "http://127.0.0.1:8000"'
20
+
21
+
22
+ def _default_kicad_dir() -> Path:
23
+ return Path.home() / "Documents" / "KiCad" / "10.0" / "scripting" / "plugins"
24
+
25
+
26
+ def install(args: argparse.Namespace) -> int:
27
+ plugin_dir = Path(args.plugin_dir).expanduser() if args.plugin_dir else _default_kicad_dir()
28
+ kicad_root = plugin_dir.parents[1] if len(plugin_dir.parents) >= 2 else None
29
+ if not args.force and kicad_root and not kicad_root.exists():
30
+ print(f"KiCad 10.0 not found at {kicad_root}. Use --plugin-dir to choose a plugin directory.")
31
+ return 1
32
+
33
+ plugin_dir.mkdir(parents=True, exist_ok=True)
34
+ resource_dir = files("usetraces").joinpath("kicad_plugin")
35
+ with ExitStack() as stack:
36
+ for plugin_file in PLUGIN_FILES:
37
+ source = stack.enter_context(as_file(resource_dir.joinpath(plugin_file)))
38
+ dest = plugin_dir / plugin_file
39
+ shutil.copy2(source, dest)
40
+ if plugin_file == "traces.py" and args.dev:
41
+ text = dest.read_text(encoding="utf-8")
42
+ dest.write_text(text.replace(PROD_BACKEND, DEV_BACKEND), encoding="utf-8")
43
+
44
+ if args.cleanup_old:
45
+ for plugin_file in OLD_PLUGIN_FILES:
46
+ (plugin_dir / plugin_file).unlink(missing_ok=True)
47
+ shutil.rmtree(plugin_dir / "__pycache__", ignore_errors=True)
48
+
49
+ mode = "dev -> localhost:8000" if args.dev else "prod -> usetraces.com"
50
+ print(f"Installed traces KiCad plugin to {plugin_dir} ({mode}). Restart KiCad.")
51
+ return 0
52
+
53
+
54
+ def uninstall(args: argparse.Namespace) -> int:
55
+ plugin_dir = Path(args.plugin_dir).expanduser() if args.plugin_dir else _default_kicad_dir()
56
+ if not plugin_dir.exists():
57
+ print(f"KiCad plugin directory not found at {plugin_dir}. Nothing to uninstall.")
58
+ return 0
59
+
60
+ for plugin_file in PLUGIN_FILES:
61
+ (plugin_dir / plugin_file).unlink(missing_ok=True)
62
+ shutil.rmtree(plugin_dir / "__pycache__", ignore_errors=True)
63
+ print(f"Uninstalled traces KiCad plugin from {plugin_dir}. Restart KiCad.")
64
+ return 0
65
+
66
+ def build_parser() -> argparse.ArgumentParser:
67
+ parser = argparse.ArgumentParser(prog="usetraces")
68
+ subparsers = parser.add_subparsers(dest="command", required=True)
69
+
70
+ install_parser = subparsers.add_parser("install", help="Install the traces KiCad plugin.")
71
+ install_parser.add_argument("--dev", action="store_true", help="Point the plugin at localhost:8000.")
72
+ install_parser.add_argument("--force", action="store_true", help="Create the plugin directory even if KiCad is not found.")
73
+ install_parser.add_argument("--cleanup-old", action="store_true", help="Remove legacy traces plugin filenames.")
74
+ install_parser.add_argument("--plugin-dir", help="Override KiCad's scripting plugins directory.")
75
+ install_parser.set_defaults(func=install)
76
+
77
+ uninstall_parser = subparsers.add_parser("uninstall", help="Uninstall the traces KiCad plugin.")
78
+ uninstall_parser.add_argument("--plugin-dir", help="Override KiCad's scripting plugins directory.")
79
+ uninstall_parser.set_defaults(func=uninstall)
80
+
81
+ return parser
82
+
83
+
84
+ def main(argv: list[str] | None = None) -> int:
85
+ parser = build_parser()
86
+ args = parser.parse_args(argv)
87
+ return args.func(args)
Binary file