Skip to content

feat(backend): respect MULTIACE_CONFIG_DIR and resolve post-processor via _CFG_DIR - #153

Merged
decay71 merged 1 commit into
decay71:mainfrom
Simon-CR:feat/backend-config-dir-env
Oct 2, 2026
Merged

decay71 merged 1 commit into
decay71:mainfrom
Simon-CR:feat/backend-config-dir-env

Conversation

@Simon-CR

@Simon-CR Simon-CR commented Sep 30, 2026 •

Copy link
Copy Markdown
Collaborator

1. Executive Summary & Problem Statement

Following the environment variable unification landed in #148, ace.py in Klipper honors MULTIACE_CONFIG_DIR and MULTIACE_PRINTER_DATA. However, the web backend (multiace/web/backend/main.py) still resolved _CFG_DIR exclusively by searching default user paths (printer_data/config). On hosts using custom configuration roots (such as containerized deployments, custom multi-instance setups, or PAXX-managed environments), the backend would read and write filament snapshots, slot overrides, and spool databases under the stock fallback path rather than the configuration directory used by Klipper.

Additionally, two locations in main.py (_load_post_processor and preflight_pysrc) contained hardcoded references to printer_data/config/tools/post_process_virtual_toolheads.py via _user_paths(), bypassing custom configuration directories.

This PR completes the host path alignment requested in #142 by making MULTIACE_CONFIG_DIR the first preference for _CFG_DIR and ensuring the post-processor script lookups follow _CFG_DIR.


2. Implementation Details

multiace/web/backend/main.py

  • Environment Documentation: Updated module docstring to document MULTIACE_CONFIG_DIR.
  • _resolve_cfg_dir(): Added a dedicated resolver that queries os.environ.get("MULTIACE_CONFIG_DIR") as its first preference. If set, it returns os.path.abspath(env_dir). If unset or empty, it falls back to the existing _first_existing(_user_paths("printer_data/config")).
  • Derivative Path Alignment:
    • _CFG_EXT_DIR: dynamically derives as os.path.join(_CFG_DIR, "extended").
    • MULTIACE_CFG_PATH: continues to serve as the explicit file override (MULTIACE_CFG_PATH), falling back to _CFG_EXT_DIR/ace.cfg and _CFG_DIR/ace.cfg.
    • SNAPSHOT_DIR: defaults to os.path.join(_CFG_EXT_DIR, "multiace", "filament_snapshots").
    • OVERRIDE_FILE: defaults to os.path.join(_CFG_EXT_DIR, "multiace", "slot_overrides.json").
    • SPOOL_DB_PATH: defaults to os.path.join(_CFG_DIR, "persistent", "multiace_spools.json").
  • Post-Processor Script Resolution:
    • In _load_post_processor(): Replaced hardcoded _user_paths("printer_data/config/tools/...") with Path(_CFG_DIR) / "tools" / "post_process_virtual_toolheads.py", maintaining repo-level tools/ as the fallback.
    • In preflight_pysrc(): Replaced hardcoded _user_paths("printer_data/config/tools/...") with Path(_CFG_DIR) / "tools" / "post_process_virtual_toolheads.py", ensuring consistent module delivery to the browser preflight worker.

tests/backend_config_dir_selfcheck.py

  • Self-contained test script in tests/ verifying:
    1. MULTIACE_CONFIG_DIR environment override takes precedence and correctly roots all derivative paths.
    2. Fallback candidate resolution when MULTIACE_CONFIG_DIR is unset.
    3. MULTIACE_CFG_PATH explicit override priority over _CFG_DIR.
    4. Dynamic post-processor script discovery under <custom_config_dir>/tools/.

3. Verification Matrix & Test Evidence

Test Vector Condition / Setup Observed Result Status
MULTIACE_CONFIG_DIR Override MULTIACE_CONFIG_DIR=/tmp/custom_printer_config set _CFG_DIR resolves to absolute custom path; extended dir, snapshots, slot overrides, and spool db derive correctly PASS
Unset Fallback Resolution MULTIACE_CONFIG_DIR not set _CFG_DIR resolves to first existing user config candidate PASS
Specific File Override MULTIACE_CFG_PATH=/path/to/my_ace.cfg set MULTIACE_CFG_PATH preserved verbatim regardless of _CFG_DIR PASS
Post-Processor Lookup Custom script placed at <_CFG_DIR>/tools/post_process_virtual_toolheads.py Discovered by candidate list ahead of repo fallback PASS
Repo Fallback Lookup Custom tools directory missing Successfully falls back to repo root multiace/tools/post_process_virtual_toolheads.py PASS
Test Suite Execution python3 tests/backend_config_dir_selfcheck.py All test sections pass (0 failures) PASS

4. Backward Compatibility & Impact Assessment

  • Zero Breaking Changes: Stock Snapmaker U1 and standard generic Klipper installations (where MULTIACE_CONFIG_DIR is not set) execute the exact same fallback resolution chain as before.
  • Cross-Component Consistency: Aligns the web backend with ace.py in Klipper and external service wrappers, guaranteeing all multiACE components operate on the identical configuration root.

Fixes #142

@Simon-CR
Simon-CR requested a review from decay71 as a code owner September 30, 2026 19:47
@Simon-CR
Simon-CR force-pushed the feat/backend-config-dir-env branch 3 times, most recently from 198407b to 7fcd71e Compare September 30, 2026 20:07

@decay71 decay71 left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks Simon, looks good. One small thing: tests/test_backend_config_dir.py and tests/backend_config_dir_selfcheck.py are identical, could you keep just one? Then I'll merge.

Dirk

@Simon-CR

Simon-CR commented Oct 1, 2026

Copy link
Copy Markdown
Collaborator Author

Removed the duplicate test file as requested. Thanks Dirk!

@Tareku99

Tareku99 commented Oct 1, 2026

Copy link
Copy Markdown
Collaborator

Would probably be safer to pull in main (since 151 was merged in) and see what is left on this PR to resolve conflicts!

@decay71

decay71 commented Oct 1, 2026

Copy link
Copy Markdown
Owner

Thanks Simon. #151 is merged now and already adds MULTIACE_CONFIG_DIR to the backend, so #153 conflicts in main.py. Please merge main in (or rebase, it gets squashed anyway) and keep the resolver from #151; what's left from your PR is the post-processor part.

One test needs adjusting: with #151, a MULTIACE_CONFIG_DIR pointing to a missing directory is still used rather than falling back, so that case should expect the env value.

@Simon-CR
Simon-CR force-pushed the feat/backend-config-dir-env branch from dd8d959 to 111f0e1 Compare October 1, 2026 10:09
@Simon-CR

Simon-CR commented Oct 1, 2026

Copy link
Copy Markdown
Collaborator Author

Rebased onto main to incorporate #151's config dir resolver, kept our post-processor script resolution, and updated tests to match. Ready for review! Thanks Dirk.

@decay71
decay71 merged commit 5156ecc into decay71:main Oct 2, 2026
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Environment variables for host paths: one naming convention

3 participants