Development Setup
This guide sets up History Workbench for local development. It installs Python dependencies, connects the checkout to FreeCAD, and configures the FreeCAD runtime scripts used by tests and API exploration.
Prerequisites
Section titled “Prerequisites”Clone The Repository
Section titled “Clone The Repository”git clone https://github.com/eblanshey/HistoryWorkbench.gitcd HistoryWorkbenchIf you already have a checkout, run the setup commands from the repository root.
Install Python Dependencies
Section titled “Install Python Dependencies”From the repository directory, install Python 3.11 using uv:
uv python install 3.11Then sync dependencies:
uv syncThis creates or updates the local .venv and installs development tools declared in pyproject.toml, including ruff, mypy, pytest, radon, freecad-stubs, and taskfile-help.
Nix / NixOS
Section titled “Nix / NixOS”On Nix or NixOS, run nix-shell in the repository root to enter an environment with all required dependencies (including Qt libraries like libGL) and tools (uv, python311, go-task):
nix-shellInside the Nix shell, run uv sync to set up the Python virtual environment, then follow the “Link Into FreeCAD’s Mod Directory” section to connect the workbench to FreeCAD.
Using direnv for Convenience on NixOS
Section titled “Using direnv for Convenience on NixOS”To automatically enter the Nix shell when opening the project directory, use direnv:
-
In your
configuration.nix:programs.direnv.enable = true;programs.direnv.nix-direnv.enable = true; -
Allow direnv in the repository root:
Terminal window direnv allow
The .envrc file checks if Nix is installed before loading the shell. If Nix is not available, direnv does nothing (no error).
For VSCode users, install the “direnv” extension by Martin Koehler (search for “direnv” in the extensions panel) to have VSCode automatically load the Nix environment.
Link Into FreeCAD’s Mod Directory
Section titled “Link Into FreeCAD’s Mod Directory”Create a symlink from FreeCAD’s Mod directory to this checkout. FreeCAD will load the workbench from the live source tree, so code changes are picked up after restarting FreeCAD.
To find the correct Mod directory from FreeCAD:
- Open Tools > Addon Manager.
- Click the preferences icon at the bottom of the Addon Manager.
- Click Open Addons Folder.
- Use the opened folder as the target directory for the
HistoryWorkbenchsymlink.
Linux example:
ln -s /path/to/HistoryWorkbench ~/.local/share/FreeCAD/v1-1/Mod/HistoryWorkbenchUse the absolute path to your local checkout in place of /path/to/HistoryWorkbench.
Start FreeCAD
Section titled “Start FreeCAD”Restart FreeCAD after creating the symlink. The workbench should appear as History in the workbench selector.
During development, restart FreeCAD after changing Python files. Resource files, command registration, and workbench initialization are loaded by FreeCAD process startup and activation.
Run Local Checks
Section titled “Run Local Checks”Run all checks:
task checkRun tests (includes unit and integration):
task testConfigure Git Hooks
Section titled “Configure Git Hooks”Enable repository-managed hooks so translation artifacts are verified before each commit:
git config core.hooksPath scripts/githookschmod +x scripts/githooks/pre-commitThe pre-commit hook runs task translations:verify-clean.
Linux FreeCAD AppImage Runtime
Section titled “Linux FreeCAD AppImage Runtime”The scripts ./run_with_freecad.sh and ./run_integration_tests.sh need an extracted FreeCAD AppImage and the FREECAD_ROOT environment variable.
Download the FreeCAD AppImage, then extract it:
chmod +x FreeCAD*.AppImage./FreeCAD*.AppImage --appimage-extractThis creates a squashfs-root directory. Move it wherever you keep local tools, then export FREECAD_ROOT:
export FREECAD_ROOT=$HOME/Programs/freecad_extracted/squashfs-rootTo keep the setting across shells, add that export to your shell profile, such as ~/.bashrc, ~/.zshrc, or your shell-specific environment file.
Verify the runtime:
./run_with_freecad.sh python -c "import FreeCAD; print(FreeCAD.Version())"Integration tests rely on the FreeCAD python environment. pytest isn’t installed there, so run:
./run_with_freecad.sh pip install pytestNow run integration tests directly:
./run_integration_tests.shRun a focused integration test path:
./run_integration_tests.sh tests/integration/workbench -vFreeCAD API Exploration
Section titled “FreeCAD API Exploration”Use run_with_freecad.sh to inspect FreeCAD’s App APIs from the extracted runtime:
./run_with_freecad.sh python -c "import FreeCAD; print(dir(FreeCAD))"FreeCADGui is not generally available through this script. GUI API debugging usually needs instrumentation inside the workbench and a manual FreeCAD run.
FreeCAD type stubs are installed in the local uv environment under .venv/lib/python3.11/site-packages/. Check those stubs before assuming FreeCAD API signatures.
Troubleshooting
Section titled “Troubleshooting”| Problem | Fix |
|---|---|
| FreeCAD does not show the workbench | Check that the symlink exists under FreeCAD’s active Mod directory and points to the repository root. Restart FreeCAD. |
FREECAD_ROOT environment variable is not set | Export FREECAD_ROOT to the extracted AppImage squashfs-root path. |
FreeCAD Python not found | Check that $FREECAD_ROOT/usr/bin/python exists. Re-extract the AppImage if needed. |
| Many integration tests are skipped | Run task test or ./run_integration_tests.sh, not plain pytest. |
| Import errors for local tools | Run uv sync from the repository root. |
| FreeCAD loads stale behavior | Restart FreeCAD. Python modules are cached for the lifetime of the FreeCAD process. |