Skip to content

fix: import add-in modules relatively to avoid cross-add-in collisions - #13

Merged
Botrops1 merged 1 commit into
Botrops1:mainfrom
craigulliott:main
Oct 1, 2026
Merged

Botrops1 merged 1 commit into
Botrops1:mainfrom
craigulliott:main

Conversation

@craigulliott

Copy link
Copy Markdown
Contributor

I found this because my own add-in, Fusion Keypad (it drives a Logitech MX Keypad from Fusion), was doing exactly the same thing. It added its folder to sys.path and imported its code as lib. With both add-ins running, mine picked up ConstraintLens's lib.lifecycle instead of its own. ConstraintLens's start() then ran against my add-in's folder, and the palette icons ended up copied in there. It confused me for a while!

Fusion runs every add-in in the same Python interpreter, so whichever add-in imports lib first wins, and the other gets its code. Autodesk's own add-in template avoids this with relative imports (from .lib import …). I've switched mine to that, and this PR makes the same small change here, so ConstraintLens can't be caught by, or catch, another add-in that uses the same pattern.

Nothing under lib/ needed to change, since it already imports relatively. I've also added a small test that loads the entry point while another add-in's lib is already imported. It fails with the old import and passes with the new one, and all the headless tests and lint pass.

Thanks for ConstraintLens, it's been really useful. Happy to adjust anything.

Fusion runs every add-in in a single Python interpreter. The entry point added the add-in folder to sys.path and imported its code as the top-level package `lib`. Any other add-in with a `lib` package could therefore shadow ConstraintLens's modules, or have its own shadowed, depending on load order. When that happens one add-in runs the other's code: ConstraintLens's lifecycle.start() was observed running against another add-in's folder.

Import from the add-in's own package instead (`from .lib import lifecycle`), matching Autodesk's add-in template, and leave sys.path untouched. Nothing under lib/ changes; it already imports relatively.

The headless tests now import `ConstraintLens.lib` the way Fusion loads it, and test_entry.py checks the entry point resolves its own `lib` when another add-in's is already imported.
@Botrops1
Botrops1 merged commit 64df593 into Botrops1:main Oct 1, 2026
3 checks passed
@Botrops1

Botrops1 commented Oct 1, 2026 •

Copy link
Copy Markdown
Owner

Thanks, Craig. This was a great catch and a really clean PR, and the regression test made it easy to review. I tested it in Fusion before merging, and it ships in v1.6.6. Good luck with Fusion Keypad!

Botrops1 added a commit that referenced this pull request Oct 1, 2026
Bump the manifest to 1.6.6 and add its release-notes section, crediting
@craigulliott for the fix merged in #13. CLAUDE.md: v1.6.5 is released,
the outstanding steps now cover tagging and publishing v1.6.6, the
headless test count is 35, and a v1.6.6 entry records why the entry
point must never go back to a sys.path insert plus an absolute lib
import.


Claude-Session: https://claude.ai/code/session_01FxxsWx1gqvDYC3S6YChoEw

Co-authored-by: Claude <noreply@anthropic.com>
Botrops1 added a commit that referenced this pull request Nov 27, 2026
## Summary

The `v1.6.6` tag points at `64df593` (the PR #13 merge), one commit
before the version bump in `ed13909`. The release ZIP is built from the
tag, so it shipped a manifest reading `1.6.5` (issue #15). The tag is
protected by a repository ruleset and cannot be moved, so this releases
a new version with identical code.

- `ConstraintLens/ConstraintLens.manifest`: `1.6.6` → `1.6.7`
- `RELEASE_NOTES.md`: new v1.6.7 section (packaging fix, credits
@DiegoV71 for the report and #16)
- `CLAUDE.md`: status and release steps updated; records that published
tags cannot be moved

No code under `ConstraintLens/lib/` or `palette/` changes.

## Test plan

- [x] `python3 -m unittest discover` in `tests/headless` — 35 tests pass
- [ ] After merge: tag the merge commit as `v1.6.7`, run `python
scripts/package_release.py v1.6.7` (refuses if the tag's manifest is not
1.6.7), publish the release with that ZIP

Related to #15.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-authored-by: Claude <noreply@anthropic.com>
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.

2 participants