Skip to content

armgit / SOMA

Public Imported from GitHub
0

Desktop app for designing parametric 3D models in CadQuery together with the coding agent of your choice

soma: cadquery erst in Befehlen laden, die es brauchen

Kai-Jungsthoefelb677fdafbb0c
diff --git a/python/soma/__init__.py b/python/soma/__init__.py
index fcbea36..4564014 100644
--- a/python/soma/__init__.py
+++ b/python/soma/__init__.py
@@ -6,9 +6,16 @@ import time as _time
# Vor dem Import von cadquery (dauert Sekunden): `soma build` meldet die ganze Wartezeit, nicht nur das Modell
_STARTED = _time.perf_counter()
-from .registry import add_part, import_assembly, import_step # noqa: E402
-
__version__ = "0.1.0"
API_VERSION = 1 # steht in .soma/project.json, sichert Abwaertskompatibilitaet (E36)
__all__ = ["add_part", "import_assembly", "import_step", "__version__", "API_VERSION"]
+
+
+def __getattr__(name):
+ # cadquery erst laden, wenn model.py die Funktionen braucht: Befehle wie `soma --version`, `soma render` oder
+ # Fehlermeldungen sparen so rund 4 s Start
+ if name in ("add_part", "import_assembly", "import_step"):
+ from . import registry
+ return getattr(registry, name)
+ raise AttributeError(f"module {__name__!r} has no attribute {name!r}")
diff --git a/python/soma/cli.py b/python/soma/cli.py
index dff16cf..a6c0053 100644
--- a/python/soma/cli.py
+++ b/python/soma/cli.py
@@ -6,7 +6,8 @@ import sys
import time
from pathlib import Path
-from . import _STARTED, __version__, build, registry
+# build (und damit cadquery, rund 4 s) laden nur die Befehle, die es brauchen
+from . import _STARTED, __version__
EXPORT_FORMATS = ["step", "stl", "3mf", "amf", "brep", "iges", "obj", "vrml", "glb", "gltf", "dxf", "svg"]
@@ -29,6 +30,7 @@ def _print_build(res, as_json, seconds):
def cmd_build(args):
+ from . import build # vor dem Warten: der vorgewaermte Prozess soll cadquery schon geladen haben
t0 = _STARTED
if args.wait:
# Vorgewaermter Prozess der App: cadquery ist geladen, gebaut wird erst auf eine Zeile hin.
@@ -65,7 +67,7 @@ def _export_one(shape, fmt, path):
if not w.Write(str(path)):
raise RuntimeError("IGES-Schreiben fehlgeschlagen")
elif fmt == "obj":
- from . import mesher
+ from . import build, mesher
m = mesher.mesh_shape(shape, build.auto_tolerance([shape]), 0.3)
lines = [f"v {v[0]:.5f} {v[1]:.5f} {v[2]:.5f}" for v in m["positions"]]
lines += [f"vn {n[0]:.4f} {n[1]:.4f} {n[2]:.4f}" for n in m["normals"]]
@@ -81,6 +83,7 @@ def cmd_export(args):
if fmt not in EXPORT_FORMATS:
print(f"Format {fmt!r} nicht unterstuetzt. Moeglich: {', '.join(EXPORT_FORMATS)}", file=sys.stderr)
return 2
+ from . import build
try:
parts = build.run_model(root)
except build.BuildError as e:
diff --git a/python/soma/render.py b/python/soma/render.py
index ad39003..23fde69 100644
--- a/python/soma/render.py
+++ b/python/soma/render.py
@@ -10,8 +10,6 @@ import os
import re
from pathlib import Path
-from . import analysis, animrun
-
VIEWS = ("iso", "front", "back", "left", "right", "top", "bottom")
MAX_SIDE = 3840
@@ -73,6 +71,9 @@ def prepare(root, args):
raise RenderError("Nur eins von --at, --sheet und --video")
if args.anim and args.result:
raise RenderError("--anim und --result gehen nicht zusammen")
+ # analysis und animrun laden cadquery (rund 4 s), deshalb erst hier: eine Ansicht des Modells braucht es nicht
+ if args.result or args.anim:
+ from . import analysis, animrun
if args.result:
meta = analysis.find(root, args.result)
if not meta: