fcbuild 0.0.1__tar.gz

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.
@@ -0,0 +1,44 @@
1
+ FROM mcr.microsoft.com/devcontainers/base:bookworm
2
+
3
+ # FreeCAD release to bake in. The design doc's floor is 1.0; bump these to test another version.
4
+ # The Python tag is part of the official AppImage file name.
5
+ ARG FREECAD_VERSION=1.1.4
6
+ ARG FREECAD_PYTAG=py311
7
+
8
+ # python3: system Python (3.11 on bookworm) for testing install.sh / the zipapp outside uv.
9
+ # xvfb + xauth: the GUI pass (TechDraw PDF, PNG renders) runs under xvfb-run.
10
+ # The GL/X/font libraries are what the extracted AppImage expects from the host.
11
+ RUN apt-get update && export DEBIAN_FRONTEND=noninteractive \
12
+ && apt-get install -y --no-install-recommends \
13
+ python3 \
14
+ xvfb \
15
+ xauth \
16
+ libgl1 \
17
+ libegl1 \
18
+ libglib2.0-0 \
19
+ libfontconfig1 \
20
+ libdbus-1-3 \
21
+ libxkbcommon-x11-0 \
22
+ && rm -rf /var/lib/apt/lists/*
23
+
24
+ # FreeCAD from the official AppImage, extracted so it runs without FUSE inside the container.
25
+ # This mirrors how the published fcbuild Docker image will get FreeCAD.
26
+ RUN set -eux; \
27
+ arch="$(uname -m)"; \
28
+ name="FreeCAD_${FREECAD_VERSION}-Linux-${arch}-${FREECAD_PYTAG}.AppImage"; \
29
+ base="https://github.com/FreeCAD/FreeCAD/releases/download/${FREECAD_VERSION}"; \
30
+ cd /tmp; \
31
+ curl -fsSL -o "$name" "$base/$name"; \
32
+ curl -fsSL -o "$name.sha256" "$base/$name-SHA256.txt"; \
33
+ echo "$(awk '{print $1}' "$name.sha256") $name" | sha256sum -c -; \
34
+ chmod +x "$name"; \
35
+ "./$name" --appimage-extract >/dev/null; \
36
+ mv squashfs-root /opt/freecad; \
37
+ rm -f "$name" "$name.sha256"; \
38
+ for bin in FreeCADCmd freecadcmd FreeCAD freecad; do \
39
+ if [ -e "/opt/freecad/usr/bin/$bin" ]; then ln -s "/opt/freecad/usr/bin/$bin" "/usr/local/bin/$bin"; fi; \
40
+ done; \
41
+ command -v freecadcmd || command -v FreeCADCmd
42
+
43
+ # uv manages the project's Python, virtualenv and dependencies.
44
+ COPY --from=ghcr.io/astral-sh/uv:latest /uv /uvx /usr/local/bin/
@@ -0,0 +1,19 @@
1
+ {
2
+ "features": {
3
+ "ghcr.io/devcontainers-extra/features/go-task:1": {
4
+ "version": "1.0.6",
5
+ "resolved": "ghcr.io/devcontainers-extra/features/go-task@sha256:4d1db153919976cadd3209ca05d655a761a01707767716994dad677b4538dc1b",
6
+ "integrity": "sha256:4d1db153919976cadd3209ca05d655a761a01707767716994dad677b4538dc1b"
7
+ },
8
+ "ghcr.io/devcontainers/features/git:1": {
9
+ "version": "1.3.8",
10
+ "resolved": "ghcr.io/devcontainers/features/git@sha256:fd75977de13a9979000e0e78baf949adb0ca71d2398995fa22e0a36d7e7e7fe2",
11
+ "integrity": "sha256:fd75977de13a9979000e0e78baf949adb0ca71d2398995fa22e0a36d7e7e7fe2"
12
+ },
13
+ "ghcr.io/devcontainers/features/github-cli:1": {
14
+ "version": "1.1.3",
15
+ "resolved": "ghcr.io/devcontainers/features/github-cli@sha256:bd7ab48a832228f633239277552c30b353867fef2e5b037e064b4e64f0b843f2",
16
+ "integrity": "sha256:bd7ab48a832228f633239277552c30b353867fef2e5b037e064b4e64f0b843f2"
17
+ }
18
+ }
19
+ }
@@ -0,0 +1,73 @@
1
+ {
2
+ "name": "fcbuild (Python / FreeCAD)",
3
+
4
+ // FreeCAD is large, so it is baked into the image instead of installed on every create.
5
+ "build": {
6
+ "dockerfile": "Dockerfile",
7
+ "args": {
8
+ "FREECAD_VERSION": "1.1.4",
9
+ "FREECAD_PYTAG": "py311"
10
+ }
11
+ },
12
+
13
+ "features": {
14
+ "ghcr.io/devcontainers/features/git:1": {},
15
+ "ghcr.io/devcontainers/features/github-cli:1": {},
16
+ // Task runner for the verb:noun commands in Taskfile.yml.
17
+ "ghcr.io/devcontainers-extra/features/go-task:1": {}
18
+ },
19
+
20
+ // Tokens come from the host environment so nothing is mounted across OSes.
21
+ // GH_TOKEN: `gh auth token`
22
+ // CLAUDE_CODE_OAUTH_TOKEN: `claude setup-token`
23
+ // Set them in your shell profile / system env BEFORE launching VS Code.
24
+ "remoteEnv": {
25
+ "GH_TOKEN": "${localEnv:GH_TOKEN}",
26
+ "CLAUDE_CONFIG_DIR": "/home/vscode/.claude",
27
+ "CLAUDE_CODE_OAUTH_TOKEN": "${localEnv:CLAUDE_CODE_OAUTH_TOKEN}",
28
+ // fcbuild's own FreeCAD discovery reads this (see the design doc, "Usage modes").
29
+ "FCBUILD_FREECAD": "/usr/local/bin/freecadcmd",
30
+ // Keep uv's virtualenv in the workspace so VS Code finds the interpreter.
31
+ "UV_PROJECT_ENVIRONMENT": ".venv",
32
+ "UV_LINK_MODE": "copy"
33
+ },
34
+
35
+ // Persists Claude Code config/login across container rebuilds.
36
+ // ${devcontainerId} is unique per container, so no per-project slug is needed.
37
+ "mounts": [
38
+ "source=claude-config-${devcontainerId},target=/home/vscode/.claude,type=volume"
39
+ ],
40
+
41
+ "postCreateCommand": "bash .devcontainer/post-create.sh",
42
+
43
+ // Docker creates the volume mount point root-owned; hand it to vscode so Claude Code can save history.
44
+ "postStartCommand": "sudo chown -R vscode:vscode /home/vscode/.claude",
45
+
46
+ "customizations": {
47
+ "vscode": {
48
+ "extensions": [
49
+ "ms-python.python",
50
+ "ms-python.vscode-pylance",
51
+ "charliermarsh.ruff",
52
+ // fcbuild.yaml is validated against a JSON Schema; this gives autocomplete and inline errors.
53
+ "redhat.vscode-yaml",
54
+ "tamasfe.even-better-toml",
55
+ "Anthropic.claude-code",
56
+ "streetsidesoftware.code-spell-checker"
57
+ ],
58
+ "settings": {
59
+ "editor.formatOnSave": true,
60
+ "python.defaultInterpreterPath": "${workspaceFolder}/.venv/bin/python",
61
+ "python.analysis.typeCheckingMode": "strict",
62
+ "[python]": {
63
+ "editor.defaultFormatter": "charliermarsh.ruff",
64
+ "editor.codeActionsOnSave": {
65
+ "source.organizeImports": "explicit"
66
+ }
67
+ }
68
+ }
69
+ }
70
+ },
71
+
72
+ "remoteUser": "vscode"
73
+ }
@@ -0,0 +1,17 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+
4
+ cd "$(dirname "${BASH_SOURCE[0]}")/.."
5
+
6
+ # The project isn't scaffolded yet on first build, so only sync when there's something to sync.
7
+ if [ -f pyproject.toml ]; then
8
+ uv sync
9
+ fi
10
+
11
+ uv --version
12
+ python3 --version
13
+ "${FCBUILD_FREECAD}" --version || echo "FreeCAD at ${FCBUILD_FREECAD} did not report a version."
14
+
15
+ if [ -z "${CLAUDE_CODE_OAUTH_TOKEN:-}" ]; then
16
+ echo "CLAUDE_CODE_OAUTH_TOKEN not set on the host; run 'claude' to log in manually."
17
+ fi
@@ -0,0 +1,8 @@
1
+ .venv/
2
+ __pycache__/
3
+ *.egg-info/
4
+ dist/
5
+ build/
6
+ .mypy_cache/
7
+ .ruff_cache/
8
+ .pytest_cache/
@@ -0,0 +1,249 @@
1
+ # FreeCAD Build System — Design Doc
2
+
3
+ Dec 2, 2026 · @Andrew
4
+
5
+ ## Overview
6
+
7
+ A declarative build tool for FreeCAD: one YAML file says which `.FCStd` sources to open, which parameters to set per variant, and which objects to export in which formats. The same command runs on a laptop and in GitHub Actions. Working name: `fcbuild` (see open questions).
8
+
9
+ **Goals**
10
+
11
+ - No bespoke per-repo scripts: everything a build needs lives in the config.
12
+ - Variants: one source, many parameter sets, many outputs.
13
+ - A `verify` command that proves the config matches the model before anything exports.
14
+ - Fails loudly: a recompute error or invalid shape stops the build, never ships a broken STL.
15
+ - Easy to install and update locally; a ready-made Docker image and GitHub Action for CI.
16
+
17
+ **Non-goals (v1)**
18
+
19
+ - Editing or authoring models. The tool only drives existing FCStd files.
20
+ - Assembly solving beyond what a plain recompute does.
21
+ - Slicing or G-code generation.
22
+
23
+ **Prior art**
24
+
25
+ | Tool | What it does | Gap |
26
+ | --- | --- | --- |
27
+ | [FCBot](https://github.com/asymworks/fcbot) | KiBot-style YAML; STEP, STL, PDF, screenshot outputs; GitHub Action + Docker image | No parameter overrides or variants; very early (no releases) |
28
+ | [freecad-build](https://github.com/khimaros/freecad-build) | Makefile-driven CLI export plus visual mesh diffs | Not declarative; one file in, one file out |
29
+ | [KiBot](https://kibot.readthedocs.io/en/latest/configuration.html) | The model to copy: preflight checks + declarative outputs for KiCad | KiCad only |
30
+
31
+ ## Usage modes
32
+
33
+ Local and CI runs use the same CLI and the same config; CI just runs it inside the published Docker image.
34
+
35
+ ```bash
36
+ fcbuild verify # check config against the models, export nothing
37
+ fcbuild build # all variants, all outputs
38
+ fcbuild build enclosure # one build
39
+ fcbuild build enclosure:small # one variant of one build
40
+ fcbuild list # show variants x outputs that would be produced
41
+ fcbuild inspect cad/enclosure.FCStd # dump objects, spreadsheet aliases, VarSet properties
42
+ ```
43
+
44
+ - **Config discovery:** `fcbuild.yaml` in the current directory or a parent; `--config` overrides.
45
+ - **FreeCAD discovery:** `--freecad` flag, then `FCBUILD_FREECAD` env var, then `FreeCADCmd` / `freecadcmd` on PATH, then known install locations (AppImage, Flatpak, `/Applications`, `Program Files`).
46
+ - **Exit codes:** 0 success, 1 build or verify failure, 2 bad config or usage. CI needs nothing else.
47
+ - **`inspect`** exists because writing the config is the annoying part: it lists exactly the names `verify` will check against.
48
+
49
+ ## Config format
50
+
51
+ YAML, validated against a published JSON Schema so editors (VS Code YAML extension, JetBrains) give autocomplete and inline errors for free. The config is a set of named **builds**; each build works on exactly one source file and owns its own variants and outputs. A build produces every combination of its variants and outputs.
52
+
53
+ ```yaml
54
+ # yaml-language-server: $schema=https://.../fcbuild.schema.json
55
+ version: 1
56
+
57
+ defaults:
58
+ output_dir: build/{build}/{variant}
59
+ formats:
60
+ stl:
61
+ linear_deflection: 0.05
62
+ angular_deflection: 0.3
63
+
64
+ builds:
65
+ enclosure:
66
+ source: cad/enclosure.FCStd
67
+ variants:
68
+ small:
69
+ Spreadsheet.Width: 80 # spreadsheet alias
70
+ Params.WallThickness: 2.0 # VarSet property
71
+ large:
72
+ Spreadsheet.Width: 120
73
+ large-thick:
74
+ extends: large
75
+ Params.WallThickness: 3.0
76
+ outputs:
77
+ objects: [Body, Lid]
78
+ formats: [step, stl, 3mf]
79
+ filename: "{object}-{variant}.{ext}"
80
+
81
+ enclosure-drawings: # same source, different task
82
+ source: cad/enclosure.FCStd
83
+ variants:
84
+ large:
85
+ Spreadsheet.Width: 120
86
+ outputs:
87
+ pages: [Page]
88
+ formats: [pdf]
89
+
90
+ bracket: # no variants: one build at saved values
91
+ source: cad/bracket.FCStd
92
+ outputs:
93
+ - objects: [Bracket]
94
+ formats: [step]
95
+ - objects: [Bracket]
96
+ formats: [stl]
97
+ stl: { linear_deflection: 0.01 } # finer mesh for printing
98
+ ```
99
+
100
+ **Rules**
101
+
102
+ - **One build, one source.** Several builds may share a source; each opens its own fresh copy, so they never affect each other.
103
+ - **Variants are a map of name to parameter overrides.** Omit `variants` and the build runs once as an implicit `default` variant at the model's saved values.
104
+ - **`outputs` is a mapping or a list of mappings.** A single mapping is shorthand for a one-item list; use a list when different objects need different formats or options.
105
+ - **Per-output `variants:` filter** (optional) restricts one output to some variants, for when a separate build would be overkill.
106
+ - **Parameter paths** are `Object.Property`. `Object` matches by Label first, then internal Name; ambiguity is a verify error.
107
+ - **Spreadsheet cells** are addressed by alias (`Spreadsheet.Width`), never raw cell (`B2`): aliases survive row edits.
108
+ - **Values** are YAML scalars; strings with units (`"80 mm"`, `"15 deg"`) pass through FreeCAD's unit parser.
109
+ - **Templates** in `filename` and `output_dir`: `{build}`, `{variant}`, `{object}`, `{source}`, `{ext}`, `{git_describe}`.
110
+ - **Format options** cascade: `defaults.formats`, then the build, then the output.
111
+ - **Variant inheritance:** a variant may set `extends: <other variant>` to start from that variant's values and override some of them. Parameter paths always contain a dot, so the bare `extends` key cannot clash with one. Chains are allowed; cycles and unknown names are schema errors. Scope is one build; to share parameters across builds, use YAML anchors (`&base` / `<<: *base`).
112
+
113
+ **Formats for v1:** `step`, `stl`, `3mf`, `brep`, `iges`, `obj`, `fcstd` (a recomputed copy with the variant baked in), plus GUI-stage `pdf` (TechDraw) and `png` (render).
114
+
115
+ ## Build pipeline
116
+
117
+ Each job opens a fresh copy of the source, applies the variant's parameters, recomputes, and only exports if every target shape comes out valid. An invalid variant fails its job and the build exits 1; nothing half-broken reaches `build/`.
118
+
119
+ &#91;embedded content: build pipeline · orchestrator and worker\]
120
+
121
+ The tinted band is the process boundary: everything inside runs in `FreeCADCmd`, everything outside is ordinary Python.
122
+
123
+ - **Applying parameters:** spreadsheet aliases via `sheet.set(alias, value)` followed by `sheet.recompute()`; VarSet and other properties via `setattr` with `FreeCAD.Units.Quantity` for unit strings.
124
+ - **Detecting failure:** after `doc.recompute()`, any object with `'Invalid'` or `'Error'` in its `State`, or a non-empty recompute error list, fails the job with the object's name and message.
125
+ - **Validating shapes:** each export target must have a non-null `Shape` that passes `isValid()`; an optional `expect: {solids: 1}` per output catches silent geometry loss.
126
+ - **Headless vs GUI pass:** STEP, STL, 3MF and the rest run in plain `FreeCADCmd`. TechDraw PDF and PNG renders need GUI modules, so they run as a second pass under `xvfb-run` (only when those formats are requested).
127
+ - **STL tessellation:** via `MeshPart.meshFromShape` with the configured deflections, so mesh quality is set in the config rather than in someone's preferences.
128
+
129
+ ## Verify step
130
+
131
+ `fcbuild verify` runs in three levels, each a superset of the last, and reports every problem at once rather than stopping at the first. `build` always runs the `model` level first.
132
+
133
+ | Check | Level | Needs FreeCAD | Severity |
134
+ | --- | --- | --- | --- |
135
+ | Config matches the JSON Schema; no unknown keys | `schema` | No | Error |
136
+ | Output variant filters name variants defined in the same build | `schema` | No | Error |
137
+ | No two variant x output combinations write the same path | `schema` | No | Error |
138
+ | Every source file exists and opens without load errors | `model` | Yes | Error |
139
+ | Every parameter path resolves to exactly one object + property | `model` | Yes | Error |
140
+ | Parameter value is compatible with the property's type and unit (length vs angle vs count) | `model` | Yes | Error |
141
+ | Parameter target is driven by an expression, so the override would be overwritten on recompute | `model` | Yes | Error |
142
+ | Spreadsheet alias holds a formula that the override will replace | `model` | Yes | Warning |
143
+ | Every output object exists and has a Shape (or is a TechDraw page for `pdf`) | `model` | Yes | Error |
144
+ | Saved file has touched or errored objects (saved without recompute) | `model` | Yes | Warning |
145
+ | Each variant recomputes with no object errors | `deep` | Yes | Error |
146
+ | Each exported shape is valid (`isValid()`), non-null, and has the expected solid count | `deep` | Yes | Error |
147
+
148
+ - **`schema`** is instant and runs in a pre-commit hook without FreeCAD installed.
149
+ - **`model`** opens each file once and checks names without changing anything.
150
+ - **`deep`** applies every variant and recomputes, but writes no files. It's the true dry run.
151
+ - **Suggestions on misses:** an unresolved name lists the closest matches from `inspect` ("`Spreadsheet.Widht` not found; did you mean `Spreadsheet.Width`?").
152
+ - **Output:** human-readable by default; `--format json` for CI annotations, `--format github` to emit `::error file=...` lines that show inline on PRs.
153
+
154
+ ## Distribution and updates
155
+
156
+ Ship one Python package to PyPI and build everything else from it: a pipx/uv install for local use, a Docker image with FreeCAD baked in, and a GitHub Action that wraps the image.
157
+
158
+ **Local install.** The CLI is an ordinary Python package; it never imports FreeCAD itself, it launches `FreeCADCmd` with the bundled worker script. That sidesteps the classic "FreeCAD's Python isn't my Python" problem.
159
+
160
+ ```bash
161
+ uv tool install fcbuild # or: pipx install fcbuild
162
+ uv tool upgrade fcbuild # update
163
+ fcbuild doctor # finds FreeCAD, prints versions, runs a smoke export
164
+ ```
165
+
166
+ **Standalone install script.** For testing, and for anyone who doesn't want uv or pip, `install.sh` installs a single-file build with no package manager involved:
167
+
168
+ ```bash
169
+ curl -fsSL https://raw.githubusercontent.com/<owner>/fcbuild/main/install.sh | sh
170
+ curl -fsSL .../install.sh | sh -s -- --version 0.3.0 # pin a version
171
+ ./install.sh --local # install from a checkout (dev/testing)
172
+ ./install.sh --uninstall
173
+ ```
174
+
175
+ - **What it installs:** `fcbuild.pyz`, a zipapp of the orchestrator, worker and vendored dependencies, published as a release asset with a `SHA256SUMS` file the script verifies.
176
+ - **Where:** `~/.local/share/fcbuild/<version>/fcbuild.pyz`, with `~/.local/bin/fcbuild` as a symlink to the current version. Switching versions just moves the symlink.
177
+ - **Requirements:** POSIX `sh`, `curl` or `wget`, and `python3` 3.10 or later. The script checks each and says what's missing.
178
+ - **Updating:** `fcbuild self-update` re-runs the same logic for script installs; for uv or pip installs it prints the right upgrade command instead.
179
+ - **Dependency constraint:** the zipapp can only vendor pure-Python packages, so use PyYAML (pure fallback) and `fastjsonschema` rather than `jsonschema`, whose current versions need a compiled `rpds-py`.
180
+ - **Windows:** an `install.ps1` equivalent later, if there's demand.
181
+
182
+ **Pinning per repo.** The config can declare what it needs, and `verify` fails on a mismatch, so a repo that built last year still builds the same way:
183
+
184
+ ```yaml
185
+ requires:
186
+ fcbuild: ">=0.3,<0.4"
187
+ freecad: ">=1.0,<1.2"
188
+ ```
189
+
190
+ **Docker image.** `ghcr.io/<owner>/fcbuild:<tool-version>-freecad<version>`, e.g. `0.3.0-freecad1.0`, plus a moving `latest`. Debian slim base, FreeCAD from the extracted official AppImage, `xvfb` for the GUI stage. A matrix build publishes one tag per supported FreeCAD version.
191
+
192
+ **GitHub Action.** A thin wrapper around the image:
193
+
194
+ ```yaml
195
+ - uses: <owner>/fcbuild-action@v0
196
+ with:
197
+ command: build # or verify
198
+ config: fcbuild.yaml
199
+ variant: "" # all
200
+ freecad: "1.0"
201
+ upload-artifact: true # attach build/ to the run
202
+ ```
203
+
204
+ Release workflows chain it with `softprops/action-gh-release` to attach outputs to a tag. A starter workflow ships in `fcbuild init --ci github`.
205
+
206
+ **Later, maybe:** a FreeCAD Addon Manager entry that adds a "Build" toolbar button running the same config from the GUI.
207
+
208
+ ## Architecture
209
+
210
+ Two halves with a hard process boundary: an orchestrator that runs in normal Python and never imports FreeCAD, and a worker that runs inside `FreeCADCmd` and does only FreeCAD work. They talk through JSON files.
211
+
212
+ | Module | Side | Responsibility |
213
+ | --- | --- | --- |
214
+ | `cli` | Orchestrator | Argument parsing, config discovery, exit codes |
215
+ | `config` | Orchestrator | YAML load, JSON Schema validation, defaults merge, `{template}` expansion |
216
+ | `plan` | Orchestrator | Expands builds x variants x outputs into a list of jobs; detects path collisions |
217
+ | `freecad_locator` | Orchestrator | Finds `FreeCADCmd`, reads its version |
218
+ | `runner` | Orchestrator | Writes job JSON, launches worker (headless or under `xvfb-run`), collects results, enforces timeouts |
219
+ | `cache` | Orchestrator | Hash of source bytes + params + options + tool and FreeCAD versions; skips up-to-date jobs |
220
+ | `report` | Orchestrator | Human, JSON and GitHub-annotation output; writes `build/manifest.json` |
221
+ | `worker.main` | Worker | Reads job file, dispatches inspect / verify / build, writes result file |
222
+ | `worker.params` | Worker | Resolves `Object.Property`, applies values with unit parsing, detects expression bindings |
223
+ | `worker.exporters` | Worker | One small class per format behind a common `Exporter` interface |
224
+
225
+ - **Why a process boundary:** FreeCAD's bundled Python version, its `sys.path` quirks and crashes in OCCT stay contained. A segfault fails one job cleanly instead of killing the build.
226
+ - **Process granularity:** one worker per source file. It reopens the document fresh for each variant so overrides never leak between variants.
227
+ - **Job handoff:** `FreeCADCmd` argument passing is awkward, so the job path goes through an `FCBUILD_JOB` environment variable.
228
+ - **Manifest:** `build/manifest.json` lists every output with its variant, parameters and SHA-256. It powers the cache and makes a release reproducible.
229
+ - **Style:** type hints everywhere, `dataclasses` for config and job models, no one-letter names. As explicit as Python lets us be.
230
+
231
+ ## Decisions
232
+
233
+ | Question | Decision |
234
+ | --- | --- |
235
+ | Name | `fcbuild` for now (`FCBot` is taken) |
236
+ | Minimum FreeCAD | 1.0 (VarSets, toponaming fixes) |
237
+ | Variant inheritance | Yes, via `extends:` within a build |
238
+ | Expression-bound parameters | Hard error in `verify` |
239
+ | Assemblies | Recompute and export the assembly object; nothing more in v1 |
240
+ | 3MF | FreeCAD's built-in exporter |
241
+ | PyPI name | fcbuild is unclaimed as of 2026-12-02; claim it with an early 0.0.1 release |
242
+
243
+ ## Milestones
244
+
245
+ 1. **Spike:** worker opens one FCStd, sets a spreadsheet alias, recomputes, exports STEP + STL. Proves the headless path on a real model of yours.
246
+ 2. **MVP:** config + schema, `inspect`, `verify` at `schema` and `model` levels, `build` for STEP/STL/3MF, the manifest.
247
+ 3. **CI:** Docker image, GitHub Action, `init --ci github`, a sample repo that builds on every push.
248
+ 4. **Polish:** `deep` verify, cache, GitHub annotations, GUI stage (PDF, PNG), `doctor`.
249
+ 5. **1.0:** docs site, PyPI release, versioned schema URL.
@@ -0,0 +1,107 @@
1
+ # fcbuild — Build Phases
2
+
3
+ Derived from [FreeCAD Build System — Design Doc.md](<FreeCAD Build System — Design Doc.md>). Each phase is small enough to review on its own and ends with something you can run and check. We stop for your sign-off at the end of every phase before starting the next.
4
+
5
+ Conventions that apply to every phase (from the design doc): type hints everywhere, `dataclasses` for models, no one-letter names, orchestrator never imports FreeCAD, exit codes 0/1/2.
6
+
7
+ ---
8
+
9
+ ## Phase 0 — Project skeleton
10
+
11
+ **Goal:** an installable, testable empty package.
12
+
13
+ - `pyproject.toml` (Python ≥ 3.10, `fcbuild` console script), `src/fcbuild/` layout
14
+ - `cli` with `--version` and stub subcommands (`verify`, `build`, `list`, `inspect`)
15
+ - pytest, ruff, mypy (strict) configured; a trivial passing test
16
+ - `.gitignore`, short README
17
+
18
+ **You can check:** `uv run fcbuild --version`, `uv run pytest`.
19
+
20
+ ## Phase 1 — Spike: prove the headless FreeCAD path
21
+
22
+ **Goal:** the riskiest assumption first. No config, no CLI polish.
23
+
24
+ - `freecad_locator` (flag → `FCBUILD_FREECAD` → PATH → known locations; reads version)
25
+ - Minimal `runner` that launches `FreeCADCmd` with the job path in `FCBUILD_JOB`
26
+ - Minimal `worker.main`: open one FCStd, set a spreadsheet alias, recompute, export STEP + STL, write a result JSON
27
+ - A tiny sample FCStd under `tests/fixtures/` (or you point it at a real model)
28
+
29
+ **You can check:** a script that turns a real model + one parameter into STEP and STL files.
30
+ **Exit criteria:** works on your machine with FreeCAD ≥ 1.0; a worker crash is reported, not fatal.
31
+
32
+ ## Phase 2 — Config and planning
33
+
34
+ **Goal:** the YAML file is loaded, validated, and expanded into jobs. Still no FreeCAD needed.
35
+
36
+ - `config` dataclasses; YAML load (PyYAML); defaults merge; `{template}` expansion
37
+ - JSON Schema (`fcbuild.schema.json`) validated with `fastjsonschema`
38
+ - Variant `extends` resolution (cycle / unknown-name errors), `outputs` mapping-or-list, per-output `variants:` filter, format option cascade
39
+ - `plan`: builds × variants × outputs → job list; output path collision detection
40
+ - Config discovery (`fcbuild.yaml` in cwd or parents, `--config`)
41
+ - `fcbuild list` works; `fcbuild verify --level schema` works; exit code 2 on bad config
42
+
43
+ **You can check:** `fcbuild list` on the design doc's example config prints the expected variants × outputs.
44
+
45
+ ## Phase 3 — Worker: params, validation, exporters
46
+
47
+ **Goal:** the real worker behind a clean interface, replacing the spike code.
48
+
49
+ - `worker.params`: resolve `Object.Property` (Label then Name, ambiguity error), apply spreadsheet aliases / VarSet properties, unit strings via `Quantity`, expression-binding detection
50
+ - Recompute failure detection; shape validity and `expect: {solids: n}`
51
+ - `worker.exporters`: `Exporter` interface + `step`, `stl` (MeshPart with configured deflections), `3mf`, then `brep`, `iges`, `obj`, `fcstd`
52
+ - Fresh document reopened per variant; one worker per source file
53
+ - Job/result JSON schema shared by both sides
54
+
55
+ **You can check:** build the sample model's variants end to end via the worker, with a deliberately broken variant failing loudly and writing nothing.
56
+
57
+ ## Phase 4 — MVP commands: `inspect`, `verify`, `build`, manifest
58
+
59
+ **Goal:** the tool is usable for real work locally.
60
+
61
+ - `inspect <file>`: objects, spreadsheet aliases, VarSet properties
62
+ - `verify` at `schema` and `model` levels (the full table in the design doc), "did you mean" suggestions, human output
63
+ - `build [name[:variant]]`: runs `model` verify first, runs jobs, atomic writes into `build/`
64
+ - `report` + `build/manifest.json` (output, variant, params, SHA-256)
65
+
66
+ **You can check:** the full workflow from the design doc's usage section on a real model. **This is the MVP milestone.**
67
+
68
+ ## Phase 5 — Distribution and CI
69
+
70
+ **Goal:** same command locally and in GitHub Actions.
71
+
72
+ - `install.sh` + zipapp (`fcbuild.pyz`, vendored pure-Python deps, `SHA256SUMS`), `self-update`
73
+ - Dockerfile (Debian slim, extracted AppImage, xvfb), tag scheme `<tool>-freecad<ver>`
74
+ - GitHub Action wrapper; `fcbuild init --ci github`; release workflow
75
+ - `requires:` pinning checked by `verify`
76
+ - A sample repo that builds on every push
77
+
78
+ ## Phase 6 — Polish
79
+
80
+ **Goal:** the remaining v1 features.
81
+
82
+ - `verify --level deep` (true dry run)
83
+ - `cache` keyed on source bytes + params + options + versions
84
+ - `--format json` and `--format github` annotations
85
+ - GUI stage: TechDraw `pdf` and `png` under `xvfb-run`
86
+ - `doctor` command (finds FreeCAD, prints versions, smoke export)
87
+
88
+ ## Phase 7 — 1.0
89
+
90
+ - Docs site, versioned schema URL, PyPI release (claim `fcbuild` early with a 0.0.1 — can be done any time after Phase 0)
91
+
92
+ ---
93
+
94
+ ## Mapping to the design doc milestones
95
+
96
+ | Doc milestone | Phases |
97
+ | --- | --- |
98
+ | 1. Spike | 0, 1 |
99
+ | 2. MVP | 2, 3, 4 |
100
+ | 3. CI | 5 |
101
+ | 4. Polish | 6 |
102
+ | 5. 1.0 | 7 |
103
+
104
+ ## Open points to settle as we go
105
+
106
+ - Phase 1 needs a sample model. Do you want to supply a real FCStd, or should I generate a small one with a spreadsheet alias via a FreeCAD script?
107
+ - Whether to claim the PyPI name early (after Phase 0) — your call.
fcbuild-0.0.1/PKG-INFO ADDED
@@ -0,0 +1,5 @@
1
+ Metadata-Version: 2.5
2
+ Name: fcbuild
3
+ Version: 0.0.1
4
+ Summary: Declarative build tool for FreeCAD models
5
+ Requires-Python: >=3.10
@@ -0,0 +1,24 @@
1
+ # fcbuild
2
+
3
+ A declarative build tool for FreeCAD: one YAML file says which `.FCStd` sources to open, which
4
+ parameters to set per variant, and which objects to export. See the
5
+ [design doc](<FreeCAD Build System — Design Doc.md>) and the [build phases](PHASES.md).
6
+
7
+ **Status:** early development (Phase 1 done; see PHASES.md). Not usable yet.
8
+
9
+ ## Development
10
+
11
+ ```bash
12
+ uv sync # create the venv and install dev tools
13
+ uv run pytest # tests (FreeCAD integration tests skip if FreeCADCmd is missing)
14
+ uv run ruff check . # lint
15
+ uv run mypy # strict type check
16
+ uv run fcbuild --help
17
+ ```
18
+
19
+ The orchestrator (`src/fcbuild/`) never imports FreeCAD. The worker
20
+ (`src/fcbuild/worker/`) runs inside `FreeCADCmd`. Regenerate the sample model with:
21
+
22
+ ```bash
23
+ FCBUILD_OUT=$PWD/tests/fixtures/sample.FCStd freecadcmd tests/fixtures/make_sample.py
24
+ ```
@@ -0,0 +1,34 @@
1
+ [build-system]
2
+ requires = ["hatchling"]
3
+ build-backend = "hatchling.build"
4
+
5
+ [project]
6
+ name = "fcbuild"
7
+ version = "0.0.1"
8
+ description = "Declarative build tool for FreeCAD models"
9
+ requires-python = ">=3.10"
10
+ dependencies = []
11
+
12
+ [project.scripts]
13
+ fcbuild = "fcbuild.cli:main"
14
+
15
+ [dependency-groups]
16
+ dev = ["pytest>=8", "mypy>=1.10", "ruff>=0.5"]
17
+
18
+ [tool.hatch.build.targets.wheel]
19
+ packages = ["src/fcbuild"]
20
+
21
+ [tool.mypy]
22
+ strict = true
23
+ files = ["src"]
24
+
25
+ [tool.ruff]
26
+ line-length = 100
27
+
28
+ [tool.pytest.ini_options]
29
+ testpaths = ["tests"]
30
+
31
+ [[tool.mypy.overrides]]
32
+ # FreeCAD's modules only exist inside FreeCADCmd and ship no stubs.
33
+ module = ["FreeCAD", "Import", "Mesh", "MeshPart"]
34
+ ignore_missing_imports = true
@@ -0,0 +1,37 @@
1
+ """Phase 1 spike: one model + one parameter -> STEP and STL.
2
+
3
+ uv run python scripts/spike.py tests/fixtures/sample.FCStd Spreadsheet.Width=80 Body out/
4
+ """
5
+
6
+ from __future__ import annotations
7
+
8
+ import sys
9
+ from pathlib import Path
10
+
11
+ from fcbuild.freecad_locator import locate_freecad
12
+ from fcbuild.runner import run_job
13
+
14
+
15
+ def main() -> int:
16
+ source, assignment, target, out_dir = sys.argv[1:5]
17
+ path, _, value = assignment.partition("=")
18
+ freecad = locate_freecad()
19
+ print(f"FreeCAD {freecad.version} at {freecad.executable} (found via {freecad.source})")
20
+ job = {
21
+ "source": str(Path(source).resolve()),
22
+ "params": {path: value},
23
+ "exports": [
24
+ {"object": target, "format": fmt, "path": str(Path(out_dir).resolve() / f"{target}.{fmt}")}
25
+ for fmt in ("step", "stl")
26
+ ],
27
+ }
28
+ outcome = run_job(freecad, job)
29
+ if not outcome.ok:
30
+ print(f"FAILED: {outcome.error}\n{outcome.log}")
31
+ return 1
32
+ print("wrote:", *outcome.result["written"], sep="\n ")
33
+ return 0
34
+
35
+
36
+ if __name__ == "__main__":
37
+ raise SystemExit(main())
@@ -0,0 +1,3 @@
1
+ """fcbuild: declarative build tool for FreeCAD models."""
2
+
3
+ __version__ = "0.0.1"