Skip to content

dev_environment.py: detect Blender's bundled Python from disk - #9228

Open
theoryshaw wants to merge 1 commit into
IfcOpenShell:v0.9.0from
theoryshaw:dev-environment-detect-python
Open

theoryshaw wants to merge 1 commit into
IfcOpenShell:v0.9.0from
theoryshaw:dev-environment-detect-python

Conversation

@theoryshaw

Copy link
Copy Markdown
Member

Closes #9227.

dev_environment.py derived the site-packages path from a hardcoded Blender→Python mapping:

BLENDER_VERSION_INT = tuple(map(int, BLENDER_VERSION.split(".")))
PYTHON_VERSION = "3.13" if BLENDER_VERSION_INT >= (5, 1) else "3.11"

That boundary has needed a manual edit on each Blender release that bumps the interpreter — 7e1843b for 5.1, then d30c250 after 5.2 fell through to 3.11 and the script aborted — and it will break again the moment Blender ships 3.14. Each time, the symptom is a new contributor unable to set up a dev environment, with an assertion that doesn't point at the cause.

The information is already on disk, so this reads it instead of predicting it: glob extensions/.local/lib/python*/site-packages and take the highest version. The old mapping stays as a fallback so the existing assert still reports a sensible path when nothing matches.

Sorting is on the parsed version parts rather than the raw string — plain sorted() puts python3.9 above python3.13. Folder names that don't parse sort below the ones that do instead of raising, so an unexpected variant (e.g. a free-threaded python3.13t build) can't take the script down.

Also prints PACKAGE_PATH in the "Script settings" block. It was the one path the script asserts on but never showed.

Testing

Loaded the module with input stubbed and checked the resolved path against a real install:

Blender Resolved Exists
5.2 ...\5.2\extensions\.local\lib\python3.13\site-packages yes
4.5 ...\4.5\extensions\.local\lib\python3.11\site-packages yes

Sort key checked against a tree containing python3.9, python3.13 and python3.13t: string sort picks python3.9, the version-part key picks python3.13. black --line-length 120 reports no changes.

Windows 10, Blender 5.2 and 4.5, Bonsai installed via offline installation (extensions/user_default/bonsai). Not exercised on macOS or Linux, though the changed code is platform-independent — only BLENDER_PATH, set above it, differs per platform.

🤖 Generated with Claude Code

The site-packages path was derived from a hardcoded Blender -> Python
mapping, which has needed a manual edit on each Blender release that
bumps the bundled interpreter (5.1 -> 3.13, then 5.2 falling through to
3.11) and would break again on 3.14.

Glob extensions/.local/lib/python*/site-packages instead and take the
highest version, sorting on the parsed version parts so python3.9 does
not outrank python3.13. The old mapping stays as a fallback so the
existing assert can still report a sensible path when nothing matches.

Also print PACKAGE_PATH in the settings block - it was the one path the
script asserts on but never showed, so the failure had no context.

Closes IfcOpenShell#9227

Co-Authored-By: Claude Opus 5 <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.

dev_environment.py: detect Blender's bundled Python from disk instead of a hardcoded version boundary

1 participant