Repository navigation
Build model extensions with the environment's cmake and ninja - #3518
Open
codekongdev wants to merge 1 commit into
Open
codekongdev wants to merge 1 commit into
codekongdev wants to merge 1 commit into
Conversation
If the scripts directory of the running interpreter's environment is not on PATH, e.g., because the environment was not activated, prepend it to PATH for the model build. Otherwise, cmake-build-extension fails with "Required command 'ninja' not found" (or 'cmake'), or uses another cmake from PATH. If the directory is already on PATH, the existing order is kept. Fixes AMICI-dev#3505. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What does this pull request do, and why?
cmakeandninjaare installed into the Python environment together with amici (as requirements ofcmake-build-extension), butcmake_build_extension.BuildExtension.runlooks them up only onPATH(shutil.which). If the interpreter of a virtual environment is run without activating the environment (IDE, scheduler job,/path/to/venv/bin/python script.py), every model build fails withRequired command 'ninja' not found(or'cmake'), or uses some othercmakefromPATH.Changes:
build_model_extensionnow prepends the scripts directory of the running interpreter (sysconfig.get_path("scripts"), the directory_get_env_swig()already uses for SWIG) toPATHfor thesetup.pysubprocess, if it is not onPATHalready. This is what activating the environment would do.PATH(activated environment, or a deliberately chosen order, e.g. a module-loadedcmakein front),PATHis left unchanged. I chose this over always prepending because for a system interpreter the scripts directory is e.g./usr/local/bin, and always moving it to the front could change which tools are used for setups that work today.python/tests/test_misc.pyand a changelog fragment.Testing (Ubuntu, Python 3.14.4, amici installed from this branch with
pip install -e python/sdist --no-build-isolation; no systemcmake/ninja/swig):env -i HOME=$HOME PATH=/usr/bin:/bin /path/to/venv/bin/python repro.py: onmainit fails withRequired command 'cmake' not found; with this change the model builds. With anothercmakebut noninjafirst onPATH:Required command 'ninja' not foundonmain; builds with this change. With the environment'sbinonPATH: builds, as before.pytest python/tests/test_misc.pywith the environment onPATH: 20 passed, 1 failed.test_cmake_compilationneeds the C++ CMake build inbuild/, which I did not do; it fails the same way onmain.PATH(PATH=/usr/bin:/bin): onmainthe shared model fixture fails to build (2 errors). With this change, 19 passed. The two failures aretest_cmake_compilation(as above) andtest_model_rebuild_reruns_swig_on_swig_change, which looks upswigwithshutil.which("swig")in the test itself.main([False]case) and passes with this change.Related issues
Closes #3505
Use of AI tools
Claude Code (Claude Opus 5.5) drafted the code change, the test, the changelog entry, and this description, and ran the tests listed above.
Checklist
changelog.d/(or it is not needed)🤖 Generated with Claude Code