a new part notebook is empty (sca new and the editor's new; the parametric cylinder is --kind sample); an empty notebook is where it starts, told as info, not a ProductNotFoundError; an operation or drawing started with no notebook open asks for one first and creates it in place
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -102,8 +102,8 @@ through a chain of cells that each return it. *Why:* every cell that returns
|
||||
the assembly caches a full copy of it (fact 2).
|
||||
|
||||
**C11. Make every edit step leave the names consistent.** A cell that reads a
|
||||
name nothing defines fails, and so do all cells after it. The `sca new`
|
||||
template has a params cell with `RADIUS` and `HEIGHT` and a `base` cell that
|
||||
name nothing defines fails, and so do all cells after it. The `sca new --kind sample`
|
||||
notebook has a params cell with `RADIUS` and `HEIGHT` and a `base` cell that
|
||||
reads them (the Part is implicit). Replacing the params cell
|
||||
with `sca cell put 1` while `base` still reads `RADIUS` fails with `NameError:
|
||||
name 'RADIUS' is not defined` until `base` is replaced too. Replace or delete
|
||||
|
||||
@@ -71,7 +71,7 @@ sca cell insert --after 3 -f new.py # add a cell (--after start|end|CELL, --nam
|
||||
sca cell rm 4
|
||||
sca cell run [CELL ...] # run cells (default all) and what they feed
|
||||
sca cell open other.py # have the editor open another notebook (waits for its kernel)
|
||||
sca new bracket --kind part # a new notebook; the open editor lists it, the person's view stays
|
||||
sca new bracket --kind part # a new, empty notebook; the open editor lists it, the person's view stays
|
||||
```
|
||||
|
||||
- A cell is named by its number in `sca cell ls`, its `key`, its function name, or its id.
|
||||
|
||||
@@ -40,7 +40,7 @@ HOLE_DIAMETER = scad.var(name="hole_diameter", default=6.0, unit="mm", comment="
|
||||
`scad.ref.<faces|edges>(...)` call so the form still reads it. An older cell with a tag-or-geometry recipe block
|
||||
(`_x_by_tag`, `_x_by_geometry`) still runs and its form keeps the block; a pick the kernel cannot name (a body
|
||||
without recorded history, `sca feature add` with geometry only) is still written that way.
|
||||
- A blank notebook (`sca new NAME --kind blank`) has no cells and a `kind = "part"` header: no product cell is written,
|
||||
- A new part notebook (`sca new NAME`, or the editor's "new") has no cells and a `kind = "part"` header: no product cell is written,
|
||||
the runtime makes the Part from the open bodies (see `docs/guides/notebook-runtime.md`; a solid made with "New body"
|
||||
is one more body of the same Part, not an assembly), so every new feature previews
|
||||
and a deleted cell cannot leave the notebook without a product. Setting connectors (or "use as product" on a body
|
||||
|
||||
+24
-7
@@ -16,6 +16,7 @@ import { AssemblyPanel } from "@/components/AssemblyPanel";
|
||||
import { ConnectorGizmos, type Gizmo } from "@/components/ConnectorGizmos";
|
||||
import { WorkplanePatches } from "@/components/WorkplanePatches";
|
||||
import { TagSplits, parseTagSplits, type TagSplit } from "@/components/TagSplits";
|
||||
import { NewNotebookPrompt } from "@/components/NewNotebookPrompt";
|
||||
import { PartialNotice } from "@/components/PartialModel";
|
||||
import { describePartial, parsePartial, samePartial, type PartialModel } from "@/lib/partial";
|
||||
import { WorkplanePlacePanel, WorkplanePlacer, type PlaceBase, type PlaceMode } from "@/components/WorkplanePlacer";
|
||||
@@ -102,6 +103,16 @@ export function App() {
|
||||
motion.go(target);
|
||||
};
|
||||
const [notebook, setNotebook] = useState<string | null>(null);
|
||||
const notebookRef = useRef(notebook);
|
||||
notebookRef.current = notebook;
|
||||
// an operation or a drawing was started with no notebook open: ask for one first
|
||||
const [needNotebook, setNeedNotebook] = useState(false);
|
||||
/** True (and the person is asked to create a notebook) when none is open: every operation is written into one. */
|
||||
const noNotebook = useCallback((): boolean => {
|
||||
if (notebookRef.current) return false;
|
||||
setNeedNotebook(true);
|
||||
return true;
|
||||
}, []);
|
||||
// The notebook the server says is open (workspace-relative): what the list
|
||||
// highlights. It changes the moment another is asked for, not when its
|
||||
// kernel is up, and a late answer of the workspace list cannot undo it.
|
||||
@@ -415,6 +426,7 @@ export function App() {
|
||||
} else if (typeof envelope["info"] === "string") {
|
||||
setStatus(envelope["info"]);
|
||||
log.push("info", envelope["info"]);
|
||||
setLoading(null); // a notice ends a wait as well (an empty notebook has no model to wait for)
|
||||
} else if (typeof envelope["working"] === "string") {
|
||||
setStatus(envelope["working"]);
|
||||
log.push("run", envelope["working"]);
|
||||
@@ -606,10 +618,11 @@ export function App() {
|
||||
|
||||
const openDialog = useCallback(
|
||||
(request: DialogRequest) => {
|
||||
if (noNotebook()) return;
|
||||
if (modeBeforeDialog.current === null) modeBeforeDialog.current = selectionMode;
|
||||
setDialog(request);
|
||||
},
|
||||
[selectionMode],
|
||||
[selectionMode, noNotebook],
|
||||
);
|
||||
const closeDialog = useCallback(() => {
|
||||
setDialog(null);
|
||||
@@ -681,13 +694,13 @@ export function App() {
|
||||
const activeWorkplaneRef = useRef(activeWorkplane);
|
||||
activeWorkplaneRef.current = activeWorkplane;
|
||||
const startSketch = useCallback(() => {
|
||||
if (sketchingRef.current) return;
|
||||
if (sketchingRef.current || noNotebook()) return;
|
||||
const active = workplanesRef.current.find((wp) => wp.name === activeWorkplaneRef.current);
|
||||
if (active) {
|
||||
const plane = workplanePlane(active); // the active workplane: the sketch cell writes plane=<it>
|
||||
beginSketch({ mode: "new", name: "", plane, doc: emptyDoc(plane) });
|
||||
} else beginSketch({ mode: "new", name: "", plane: null, doc: emptyDoc() });
|
||||
}, [beginSketch]);
|
||||
}, [beginSketch, noNotebook]);
|
||||
const endSketch = useCallback(() => {
|
||||
setSketchSession(null);
|
||||
setSketchNotice(null);
|
||||
@@ -799,11 +812,11 @@ export function App() {
|
||||
[gui.state?.features, curves],
|
||||
);
|
||||
const startDrawing = useCallback(() => {
|
||||
if (sketchingRef.current || placingRef.current) return;
|
||||
if (sketchingRef.current || placingRef.current || noNotebook()) return;
|
||||
const active = activeWorkplaneRef.current;
|
||||
setPicked([]);
|
||||
setDrawing({ plane: active && workplanesRef.current.some((wp) => wp.name === active) ? active : "XY", error: null });
|
||||
}, []);
|
||||
}, [noNotebook]);
|
||||
const commitCurve = useCallback(
|
||||
async (doc: CurveDoc, name: string) => {
|
||||
setGuiBusy(true);
|
||||
@@ -850,6 +863,7 @@ export function App() {
|
||||
/** Start placing: on the picked flat face, else on the active workplane (one after another builds a 3D frame of
|
||||
* planes), else on XY. */
|
||||
const startPlacing = useCallback(() => {
|
||||
if (noNotebook()) return;
|
||||
const items = selectionRef.current;
|
||||
const face = items.length === 1 && items[0].kind === "face" ? items[0] : null;
|
||||
const frame = face ? faceFrame(face.properties) : null;
|
||||
@@ -863,10 +877,11 @@ export function App() {
|
||||
const base = face ? "face" : activeWorkplaneRef.current && workplanesRef.current.some((wp) => wp.name === activeWorkplaneRef.current) ? activeWorkplaneRef.current : "XY";
|
||||
setBarNote(null);
|
||||
setPlacing({ kind: "workplane", base, values: ZERO_PLACE, mode: "translate", name, face: face && frame ? { item: face, frame } : null, error: null });
|
||||
}, [gui.state?.taken]);
|
||||
}, [gui.state?.taken, noNotebook]);
|
||||
|
||||
/** Start placing a connector of the part on the picked flat face: its frame there, moved and turned with the handles. */
|
||||
const startConnector = useCallback(() => {
|
||||
if (noNotebook()) return;
|
||||
const items = selectionRef.current;
|
||||
const face = items.length === 1 && items[0].kind === "face" ? items[0] : null;
|
||||
const frame = face ? connectorFrameFromFace(face) : null;
|
||||
@@ -1146,11 +1161,12 @@ export function App() {
|
||||
/** A command from the assembly panel: rejects with the server's message (shown in the panel). */
|
||||
const runPanelCommand = useCallback(
|
||||
async (command: FeatureCommand) => {
|
||||
if (noNotebook()) throw new Error("No notebook is open: create one first.");
|
||||
const result = await gui.run(command);
|
||||
log.push("ok", command.op === "set_connectors" ? "connectors set" : `${command.op} ${result.name}`);
|
||||
if (isCellCommand(command)) assertCellRan(result);
|
||||
},
|
||||
[gui.run, log.push],
|
||||
[gui.run, log.push, noNotebook],
|
||||
);
|
||||
|
||||
/** The frames the viewport draws: the selected component's connectors (all components' while a picker is armed),
|
||||
@@ -1412,6 +1428,7 @@ export function App() {
|
||||
onHover={setHoverSketch}
|
||||
/>
|
||||
{viewRef.current && workplanes.length > 0 && <WorkplanePatches view={viewRef.current} workplanes={workplanes} active={activeWorkplane} />}
|
||||
{needNotebook && <NewNotebookPrompt onCreate={(name) => handleCreate(name, "part")} onClose={() => setNeedNotebook(false)} />}
|
||||
{!sketching && !placing && !drawing && viewRef.current && <TagSplits view={viewRef.current} splits={tagSplits} sceneVersion={sceneVersion} />}
|
||||
{partial && !sketching && <PartialNotice partial={partial} titles={cellTitles} />}
|
||||
{viewRef.current && curves.length > 0 && <CurveLines view={viewRef.current} curves={curves} />}
|
||||
|
||||
@@ -0,0 +1,60 @@
|
||||
import { useState } from "react";
|
||||
import { FilePlus2, X } from "lucide-react";
|
||||
|
||||
/** Shown over the viewport when an operation or a drawing is started with no notebook open: everything the editor does
|
||||
* is written into a notebook, so one has to exist first. Creates it here (a part, empty) or sends the person away. */
|
||||
export function NewNotebookPrompt({ onCreate, onClose }: { onCreate: (name: string) => Promise<void>; onClose: () => void }) {
|
||||
const [name, setName] = useState("part");
|
||||
const [error, setError] = useState<string | null>(null);
|
||||
const [busy, setBusy] = useState(false);
|
||||
const create = async () => {
|
||||
setBusy(true);
|
||||
setError(null);
|
||||
try {
|
||||
await onCreate(name.trim());
|
||||
onClose();
|
||||
} catch (failure) {
|
||||
setError(failure instanceof Error ? failure.message : String(failure));
|
||||
} finally {
|
||||
setBusy(false);
|
||||
}
|
||||
};
|
||||
return (
|
||||
<div className="pointer-events-auto absolute inset-0 z-30 flex items-center justify-center bg-background/40" onClick={onClose}>
|
||||
<div
|
||||
role="dialog"
|
||||
aria-label="Create a notebook first"
|
||||
className="flex w-[min(380px,90%)] flex-col gap-3 border-2 border-[var(--focus)] bg-popover p-4 text-xs shadow-[4px_4px_0_var(--shadow-hard)]"
|
||||
onClick={(event) => event.stopPropagation()}
|
||||
>
|
||||
<div className="flex items-center gap-2 font-semibold">
|
||||
<FilePlus2 className="size-4 text-[var(--focus)]" />
|
||||
<span className="flex-1">No notebook is open</span>
|
||||
<button type="button" aria-label="Close" className="hover:text-foreground text-muted-foreground" onClick={onClose}>
|
||||
<X className="size-3.5" />
|
||||
</button>
|
||||
</div>
|
||||
<p className="text-muted-foreground">Every operation and drawing is written into a notebook. Create one first (it starts empty).</p>
|
||||
<form
|
||||
className="flex gap-2"
|
||||
onSubmit={(event) => {
|
||||
event.preventDefault();
|
||||
void create();
|
||||
}}
|
||||
>
|
||||
<input
|
||||
autoFocus
|
||||
value={name}
|
||||
onChange={(event) => setName(event.target.value)}
|
||||
className="min-w-0 flex-1 border border-border bg-background px-2 py-1 font-mono"
|
||||
aria-label="Notebook name"
|
||||
/>
|
||||
<button type="submit" disabled={busy || !name.trim()} className="border-2 border-foreground bg-foreground px-3 py-1 font-semibold text-background disabled:opacity-50">
|
||||
Create
|
||||
</button>
|
||||
</form>
|
||||
{error && <p className="text-destructive">{error}</p>}
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@@ -9,7 +9,7 @@
|
||||
sca viewport [WORKSPACE] [--out PATH] # the image of what the person sees
|
||||
sca cell ls|get|put|insert|rm|run # edit the cells of the notebook the editor has open
|
||||
sca cell open NOTEBOOK [--wait S] # have the editor open another notebook
|
||||
sca new NAME [--kind part|assembly|blank] # a new notebook; the editor lists it at once
|
||||
sca new NAME [--kind part|assembly|sample] # a new notebook (a part starts empty); the editor lists it at once
|
||||
sca feature specs|ls|add|edit|rm|undo|redo # the features the buttons make, from the command line
|
||||
sca sketch ls|get|put|solve|op # edit a sketch feature's document (trim, extend, ...)
|
||||
"""
|
||||
@@ -140,7 +140,7 @@ def configure(subparsers: argparse._SubParsersAction) -> None:
|
||||
"current directory). A running editor on that workspace lists it without a reload.",
|
||||
)
|
||||
new.add_argument("name")
|
||||
new.add_argument("--kind", choices=("part", "assembly", "blank"), default="part")
|
||||
new.add_argument("--kind", choices=("part", "assembly", "sample", "blank"), default="part")
|
||||
new.add_argument("--workspace", "-w", type=Path, default=None)
|
||||
new.set_defaults(handler=_new_notebook, printer=_print_json)
|
||||
_configure_features(subparsers)
|
||||
|
||||
@@ -1058,6 +1058,8 @@ class WorkspaceState:
|
||||
"""
|
||||
if not self._last_publish_error:
|
||||
return None
|
||||
if self._last_publish_error == "empty":
|
||||
return {"type": "status", "info": "empty notebook: add the first feature"}
|
||||
return {"type": "status", "error": self._last_publish_error[-300:]}
|
||||
|
||||
# -- settling: the cells ran; publish what they made -----------------------
|
||||
@@ -1177,6 +1179,12 @@ class WorkspaceState:
|
||||
self._last_publish_error = ""
|
||||
self.hub.broadcast({"type": "status", "info": "stopped"})
|
||||
return
|
||||
if not kernel.setup_errors and not any(str(cell.get("code", "")).strip() for cell in self.cells):
|
||||
# A notebook with no cells yet (a new one) has no product, and that is where it starts, not a fault.
|
||||
if self._last_publish_error != "empty":
|
||||
self._last_publish_error = "empty"
|
||||
self.hub.broadcast({"type": "status", "info": "empty notebook: add the first feature"})
|
||||
return
|
||||
# A notebook mid-edit has no product yet; say so once, not per run.
|
||||
if message != self._last_publish_error:
|
||||
self._last_publish_error = message
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
"""New notebooks: a part or an assembly, as the editor's "new" action writes them.
|
||||
|
||||
Both follow the feature tree convention (``docs/skill/.../feature-tree-convention.md``):
|
||||
a ``# ---- params ----`` cell, one cell per feature. The header says the kind; a part needs no cell that builds its ``Part``
|
||||
(the runtime makes it from the one open body), an assembly ends with its layout.
|
||||
The parameters carry ``# ui:`` comments so the editor offers sliders.
|
||||
A new part is empty: the header and nothing else (no cell builds its ``Part``: the runtime makes it from the one open
|
||||
body), and the person or agent adds the first feature. ``sample`` writes a small parametric part instead (a
|
||||
``# ---- params ----`` cell with ``# ui:`` sliders and one feature, after the feature tree convention), for a first look
|
||||
or a test; an assembly ends with its layout.
|
||||
"""
|
||||
|
||||
from __future__ import annotations
|
||||
@@ -29,7 +29,7 @@ with app.setup:
|
||||
import simplecadapi as scad
|
||||
'''
|
||||
|
||||
_PART = '''
|
||||
_SAMPLE = '''
|
||||
|
||||
@app.cell
|
||||
def _():
|
||||
@@ -88,13 +88,14 @@ def render_notebook(name: str, kind: str = "part", parts: list[tuple[str, str]]
|
||||
if not _NAME.fullmatch(name):
|
||||
raise ValueError(f"invalid notebook name: {name!r}")
|
||||
variable = name.replace("-", "_")
|
||||
# The kind is fixed when the notebook is made (a blank one is a part the GUI fills in).
|
||||
# The kind is fixed when the notebook is made.
|
||||
header = _HEADER.format(id=name).replace('# id = "', f'# kind = "{"assembly" if kind == "assembly" else "part"}"\n# id = "', 1)
|
||||
if kind == "blank":
|
||||
# No cells: the GUI adds the first feature. A part notebook needs no product cell: its open body is the Part.
|
||||
if kind in ("part", "blank"):
|
||||
# No cells: the first feature is added by whoever models it. A part notebook needs no product cell: its open
|
||||
# body is the Part. ("blank" is the former name of this.)
|
||||
return header + _RUNNER
|
||||
if kind == "part":
|
||||
return header + _PART + _RUNNER
|
||||
if kind == "sample":
|
||||
return header + _SAMPLE + _RUNNER
|
||||
if kind != "assembly":
|
||||
raise ValueError(f"unknown notebook kind: {kind}")
|
||||
if not parts:
|
||||
|
||||
@@ -47,7 +47,7 @@ class LineageGraphTest(unittest.TestCase):
|
||||
from simplecadapi.editor.templates import create_notebook
|
||||
|
||||
with tempfile.TemporaryDirectory() as tmp:
|
||||
notebook = create_notebook(Path(tmp), "child", "part")
|
||||
notebook = create_notebook(Path(tmp), "child", "sample")
|
||||
source = Path(notebook).read_text().replace(" return (base,)", CELL, 1)
|
||||
Path(notebook).write_text(source)
|
||||
for ident in ("child", "member"):
|
||||
@@ -84,7 +84,7 @@ class MissingRecordHealsTest(unittest.TestCase):
|
||||
from simplecadapi.editor.templates import create_notebook
|
||||
|
||||
with tempfile.TemporaryDirectory() as tmp:
|
||||
notebook = create_notebook(Path(tmp), "child", "part")
|
||||
notebook = create_notebook(Path(tmp), "child", "sample")
|
||||
Path(notebook).write_text(Path(notebook).read_text().replace(" return (base,)", CELL, 1))
|
||||
run_notebook(notebook)
|
||||
config = read_notebook_config(notebook)
|
||||
|
||||
+43
-25
@@ -29,9 +29,17 @@ def specs_of(code: str) -> dict[str, ParamSpec]:
|
||||
|
||||
|
||||
class TemplatesTest(unittest.TestCase):
|
||||
def test_new_part_runs_and_offers_sliders(self) -> None:
|
||||
def test_a_new_part_is_empty(self) -> None:
|
||||
with tempfile.TemporaryDirectory() as tmp:
|
||||
path = create_notebook(Path(tmp), "bracket", "part")
|
||||
for kind in ("part", "blank"):
|
||||
path = create_notebook(Path(tmp), f"bracket_{kind}", kind)
|
||||
text = path.read_text()
|
||||
self.assertIn('kind = "part"', text)
|
||||
self.assertNotIn("@app.cell", text) # no cells: whoever models it adds the first feature
|
||||
|
||||
def test_the_sample_part_runs_and_offers_sliders(self) -> None:
|
||||
with tempfile.TemporaryDirectory() as tmp:
|
||||
path = create_notebook(Path(tmp), "bracket", "sample")
|
||||
run = run_notebook(path)
|
||||
self.assertEqual(run.definition.definition_kind, "single_solid")
|
||||
self.assertEqual(run.definition.definition_id, "bracket")
|
||||
@@ -45,8 +53,8 @@ class TemplatesTest(unittest.TestCase):
|
||||
root = Path(tmp)
|
||||
with self.assertRaisesRegex(ValueError, "create a part first"):
|
||||
create_notebook(root, "unit", "assembly")
|
||||
create_notebook(root, "bracket", "part")
|
||||
create_notebook(root, "pin-a", "part")
|
||||
create_notebook(root, "bracket", "sample")
|
||||
create_notebook(root, "pin-a", "sample")
|
||||
path = create_notebook(root, "unit", "assembly")
|
||||
run = run_notebook(path)
|
||||
self.assertEqual(run.definition.definition_kind, "assembly")
|
||||
@@ -69,8 +77,8 @@ class PickNotebookTest(unittest.TestCase):
|
||||
with tempfile.TemporaryDirectory() as tmp:
|
||||
root = Path(tmp)
|
||||
self.assertIsNone(pick_notebook(root))
|
||||
create_notebook(root, "a-part", "part")
|
||||
create_notebook(root, "b-part", "part")
|
||||
create_notebook(root, "a-part", "sample")
|
||||
create_notebook(root, "b-part", "sample")
|
||||
self.assertEqual(pick_notebook(root), (root / "a-part.py").resolve())
|
||||
create_notebook(root, "top", "assembly")
|
||||
self.assertEqual(pick_notebook(root), (root / "top.py").resolve())
|
||||
@@ -151,7 +159,7 @@ class EditorEndToEndTest(unittest.TestCase):
|
||||
|
||||
with tempfile.TemporaryDirectory() as tmp:
|
||||
root = Path(tmp)
|
||||
path = create_notebook(root, "bracket", "part")
|
||||
path = create_notebook(root, "bracket", "sample")
|
||||
state = WorkspaceState(root)
|
||||
state.port = 17731
|
||||
app = create_app(state)
|
||||
@@ -345,7 +353,7 @@ class ModulesTest(unittest.TestCase):
|
||||
"from dataclasses import dataclass\n\n@dataclass(frozen=True)\nclass D:\n L: float = 80.0\n\nDIMS = D()\n"
|
||||
)
|
||||
(root / "helper.py").write_text("def helper():\n return 1\n")
|
||||
notebook = create_notebook(root, "part", "part")
|
||||
notebook = create_notebook(root, "part", "sample")
|
||||
notebook.write_text(
|
||||
notebook.read_text().replace(
|
||||
"with app.setup:\n import simplecadapi as scad\n",
|
||||
@@ -574,7 +582,7 @@ class RestoreTest(unittest.TestCase):
|
||||
|
||||
def _workspace(self, root: Path) -> Path:
|
||||
(root / "dims.py").write_text("L = 10.0\n")
|
||||
path = create_notebook(root, "part", "part")
|
||||
path = create_notebook(root, "part", "sample")
|
||||
path.write_text(path.read_text().replace("import simplecadapi as scad\n", "import simplecadapi as scad\n import dims\n", 1))
|
||||
return path
|
||||
|
||||
@@ -627,7 +635,7 @@ class RestoreTest(unittest.TestCase):
|
||||
from simplecadapi.editor.server import _static_cells
|
||||
|
||||
with tempfile.TemporaryDirectory() as tmp:
|
||||
path = create_notebook(Path(tmp), "part", "part")
|
||||
path = create_notebook(Path(tmp), "part", "sample")
|
||||
names = [cell["name"] for cell in _static_cells(path)]
|
||||
self.assertNotIn("setup", names)
|
||||
self.assertEqual(len(names), 2) # params and base: a part needs no product cell (kind = "part")
|
||||
@@ -669,8 +677,8 @@ class SwitchOrderTest(unittest.TestCase):
|
||||
try:
|
||||
with tempfile.TemporaryDirectory() as tmp:
|
||||
root = Path(tmp).resolve()
|
||||
a = create_notebook(root, "alpha", "part")
|
||||
b = create_notebook(root, "beta", "part")
|
||||
a = create_notebook(root, "alpha", "sample")
|
||||
b = create_notebook(root, "beta", "sample")
|
||||
state = WorkspaceState(root, a)
|
||||
sent: list[dict] = []
|
||||
state.hub.broadcast = sent.append # type: ignore[method-assign]
|
||||
@@ -717,8 +725,8 @@ class SwitchOrderTest(unittest.TestCase):
|
||||
try:
|
||||
with tempfile.TemporaryDirectory() as tmp:
|
||||
root = Path(tmp).resolve()
|
||||
create_notebook(root, "alpha", "part")
|
||||
b = create_notebook(root, "beta", "part")
|
||||
create_notebook(root, "alpha", "sample")
|
||||
b = create_notebook(root, "beta", "sample")
|
||||
state = WorkspaceState(root, None)
|
||||
state.hub.broadcast = lambda message: None # type: ignore[method-assign]
|
||||
errors: list[BaseException] = []
|
||||
@@ -923,11 +931,11 @@ class WorkspaceWatchTest(unittest.TestCase):
|
||||
with tempfile.TemporaryDirectory() as tmp:
|
||||
root = Path(tmp)
|
||||
state = WorkspaceState(root)
|
||||
create_notebook(root, "first", "part")
|
||||
create_notebook(root, "first", "sample")
|
||||
before = state._workspace_stamps()
|
||||
(root / ".sca-editor").mkdir()
|
||||
(root / ".sca-editor" / "x.py").write_text("x = 1\n")
|
||||
create_notebook(root, "second", "part")
|
||||
create_notebook(root, "second", "sample")
|
||||
after = state._workspace_stamps()
|
||||
self.assertEqual({p.name for p in after} - {p.name for p in before}, {"second.py"})
|
||||
|
||||
@@ -937,14 +945,14 @@ class CellCliTest(unittest.TestCase):
|
||||
from simplecadapi.cli import main
|
||||
|
||||
with tempfile.TemporaryDirectory() as tmp:
|
||||
path = create_notebook(Path(tmp), "bracket", "part")
|
||||
path = create_notebook(Path(tmp), "bracket", "sample")
|
||||
self.assertEqual(main(["cell", "rm", "1", "--notebook", str(path)]), 2)
|
||||
|
||||
def test_cell_ls_reads_the_file_when_no_editor_runs(self) -> None:
|
||||
from simplecadapi.editor import cli
|
||||
|
||||
with tempfile.TemporaryDirectory() as tmp:
|
||||
path = create_notebook(Path(tmp), "bracket", "part")
|
||||
path = create_notebook(Path(tmp), "bracket", "sample")
|
||||
cells = cli._cells_from_file(path)
|
||||
self.assertTrue(cells)
|
||||
self.assertEqual(cells[0]["index"], 1)
|
||||
@@ -956,7 +964,7 @@ class ExternalEditTest(unittest.TestCase):
|
||||
def test_an_edit_of_the_file_is_taken_in_and_not_written_over(self) -> None:
|
||||
with tempfile.TemporaryDirectory() as tmp:
|
||||
root = Path(tmp)
|
||||
path = create_notebook(root, "bracket", "part")
|
||||
path = create_notebook(root, "bracket", "sample")
|
||||
state = WorkspaceState(root)
|
||||
state.port = 17733
|
||||
state.hub.attach_loop(__import__("asyncio").new_event_loop())
|
||||
@@ -994,15 +1002,25 @@ class PublishErrorReportingTest(unittest.TestCase):
|
||||
self.root = Path(tmp.name).resolve()
|
||||
|
||||
def state(self) -> tuple[WorkspaceState, list[dict]]:
|
||||
path = create_notebook(self.root, "bracket", "part")
|
||||
path = create_notebook(self.root, "bracket", "sample")
|
||||
state = WorkspaceState(self.root, path)
|
||||
sent: list[dict] = []
|
||||
state.hub.broadcast = sent.append # type: ignore[method-assign]
|
||||
state.push_cells = lambda: None # type: ignore[method-assign]
|
||||
state._signature = lambda notebook: None # type: ignore[method-assign]
|
||||
state.cells = [{"id": "c1", "code": "base = scad.make_box_rsolid(10, 10, 10)"}]
|
||||
self.fail_kernel(state)
|
||||
return state, sent
|
||||
|
||||
def test_an_empty_notebook_is_where_it_starts_not_an_error(self) -> None:
|
||||
state, sent = self.state()
|
||||
state.cells = [] # a new notebook: no cells, so no product
|
||||
state.settle()
|
||||
state.settle()
|
||||
self.assertEqual(self.told(sent), 0)
|
||||
self.assertEqual([m["info"] for m in sent if m.get("info")], ["empty notebook: add the first feature"])
|
||||
self.assertEqual(state.settled_error(), {"type": "status", "info": "empty notebook: add the first feature"})
|
||||
|
||||
def fail_kernel(self, state: WorkspaceState) -> None:
|
||||
state_error = self.ERROR
|
||||
state.kernel = type( # type: ignore[assignment]
|
||||
@@ -1165,7 +1183,7 @@ class EndpointDiscoveryTest(unittest.TestCase):
|
||||
from simplecadapi.editor.cli import _find_editor
|
||||
from simplecadapi.editor.server import create_app
|
||||
|
||||
path = create_notebook(self.root, "bracket", "part")
|
||||
path = create_notebook(self.root, "bracket", "sample")
|
||||
state = WorkspaceState(self.root, path)
|
||||
state.port = 17613
|
||||
server = uvicorn.Server(uvicorn.Config(create_app(state), port=state.port, log_level="error"))
|
||||
@@ -1209,7 +1227,7 @@ class EndpointDiscoveryTest(unittest.TestCase):
|
||||
|
||||
from simplecadapi.editor import cli
|
||||
|
||||
path = create_notebook(self.root, "bracket", "part")
|
||||
path = create_notebook(self.root, "bracket", "sample")
|
||||
args = argparse.Namespace(notebook=path, workspace=None, cell="1")
|
||||
err = io.StringIO()
|
||||
with contextlib.redirect_stderr(err):
|
||||
@@ -1274,7 +1292,7 @@ class CellOpenAndViewportTest(unittest.TestCase):
|
||||
tmp = tempfile.TemporaryDirectory()
|
||||
self.addCleanup(tmp.cleanup)
|
||||
self.root = Path(tmp.name).resolve()
|
||||
self.other = create_notebook(self.root, "other", "part")
|
||||
self.other = create_notebook(self.root, "other", "sample")
|
||||
|
||||
@staticmethod
|
||||
def _fake_call(responses: list[dict]) -> object:
|
||||
@@ -1443,8 +1461,8 @@ class DeleteNotebookTest(unittest.TestCase):
|
||||
|
||||
with tempfile.TemporaryDirectory() as tmp:
|
||||
root = Path(tmp)
|
||||
first = create_notebook(root, "first", "part")
|
||||
create_notebook(root, "second", "part")
|
||||
first = create_notebook(root, "first", "sample")
|
||||
create_notebook(root, "second", "sample")
|
||||
state = WorkspaceState(root, first)
|
||||
client = TestClient(create_app(state))
|
||||
gone = client.post("/api/workspace/delete", json={"path": "second.py"}).json()
|
||||
|
||||
@@ -221,7 +221,7 @@ def test_the_commands_add_edit_undo_and_redo_against_the_real_editor(tmp_path):
|
||||
from simplecadapi.editor.server import WorkspaceState, create_app
|
||||
from simplecadapi.editor.templates import create_notebook
|
||||
|
||||
path = create_notebook(tmp_path, "bracket", "part")
|
||||
path = create_notebook(tmp_path, "bracket", "sample")
|
||||
state = WorkspaceState(tmp_path)
|
||||
state.port = 17732
|
||||
server = uvicorn.Server(uvicorn.Config(create_app(state), port=state.port, log_level="error"))
|
||||
|
||||
@@ -216,7 +216,7 @@ class RepeatedParamTest(unittest.TestCase):
|
||||
tmp = tempfile.TemporaryDirectory()
|
||||
self.addCleanup(tmp.cleanup)
|
||||
root = Path(tmp.name).resolve()
|
||||
state = WorkspaceState(root, create_notebook(root, "bracket", "part"))
|
||||
state = WorkspaceState(root, create_notebook(root, "bracket", "sample"))
|
||||
state.specs = {"RADIUS": ParamSpec("RADIUS", "", "c1", 1, "float", "literal", 10.0, "slider", 1.0, 50.0, 1.0)}
|
||||
self.runs: list[list[str]] = []
|
||||
state.emit_params = lambda: None # type: ignore[method-assign]
|
||||
@@ -261,7 +261,7 @@ class SignatureBesideTheBuildTest(unittest.TestCase):
|
||||
tmp = tempfile.TemporaryDirectory()
|
||||
self.addCleanup(tmp.cleanup)
|
||||
root = Path(tmp.name).resolve()
|
||||
state = WorkspaceState(root, create_notebook(root, "bracket", "part"))
|
||||
state = WorkspaceState(root, create_notebook(root, "bracket", "sample"))
|
||||
self.filed: list[tuple[str, bytes]] = []
|
||||
state.remember_model = lambda notebook, signature, data: self.filed.append((signature, data)) # type: ignore[method-assign]
|
||||
state.write_snapshot = lambda: None # type: ignore[method-assign]
|
||||
@@ -321,7 +321,7 @@ class StoredModelTest(unittest.TestCase):
|
||||
tmp = tempfile.TemporaryDirectory()
|
||||
self.addCleanup(tmp.cleanup)
|
||||
root = Path(tmp.name).resolve()
|
||||
self.path = create_notebook(root, "bracket", "part")
|
||||
self.path = create_notebook(root, "bracket", "sample")
|
||||
return WorkspaceState(root, self.path)
|
||||
|
||||
def scene(self):
|
||||
|
||||
@@ -141,7 +141,7 @@ class NativeWithoutOcpTest(unittest.TestCase):
|
||||
(cls.work / "plate.py").write_text(NOTEBOOK, encoding="utf-8")
|
||||
from simplecadapi.editor.templates import create_notebook
|
||||
|
||||
create_notebook(cls.work, "bracket", "part")
|
||||
create_notebook(cls.work, "bracket", "sample")
|
||||
|
||||
@classmethod
|
||||
def tearDownClass(cls) -> None:
|
||||
|
||||
@@ -20,7 +20,7 @@ class UseMemoTest(unittest.TestCase):
|
||||
tmp = tempfile.TemporaryDirectory()
|
||||
self.addCleanup(tmp.cleanup)
|
||||
self.root = Path(tmp.name).resolve()
|
||||
self.child = Path(create_notebook(self.root, "child", "part"))
|
||||
self.child = Path(create_notebook(self.root, "child", "sample"))
|
||||
self.runs: list[tuple] = []
|
||||
original = runner.run_notebook
|
||||
|
||||
@@ -85,7 +85,7 @@ class UseMemoTest(unittest.TestCase):
|
||||
self.assertIn(self.child.resolve(), {path.resolve() for path in recorded[1]})
|
||||
|
||||
def test_two_children_under_one_id_do_not_both_stay_kept(self) -> None:
|
||||
other = Path(create_notebook(self.root, "other", "part"))
|
||||
other = Path(create_notebook(self.root, "other", "sample"))
|
||||
first = runner.use(self.child, id="shared")
|
||||
runner.use(other, id="shared") # registers its nodes under "shared", replacing the first run's
|
||||
again = runner.use(self.child, id="shared")
|
||||
|
||||
Reference in New Issue
Block a user