Skip to content

Build model extensions with the environment's cmake and ninja - #3518

Open
codekongdev wants to merge 1 commit into
AMICI-dev:mainfrom
codekongdev:fix/3505-env-scripts-on-path
Open

codekongdev wants to merge 1 commit into
AMICI-dev:mainfrom
codekongdev:fix/3505-env-scripts-on-path

Conversation

@codekongdev

Copy link
Copy Markdown

What does this pull request do, and why?

cmake and ninja are installed into the Python environment together with amici (as requirements of cmake-build-extension), but cmake_build_extension.BuildExtension.run looks them up only on PATH (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 with Required command 'ninja' not found (or 'cmake'), or uses some other cmake from PATH.

Changes:

  • build_model_extension now prepends the scripts directory of the running interpreter (sysconfig.get_path("scripts"), the directory _get_env_swig() already uses for SWIG) to PATH for the setup.py subprocess, if it is not on PATH already. This is what activating the environment would do.
  • If the directory is already on PATH (activated environment, or a deliberately chosen order, e.g. a module-loaded cmake in front), PATH is 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.
  • A test in python/tests/test_misc.py and a changelog fragment.

Testing (Ubuntu, Python 3.14.4, amici installed from this branch with pip install -e python/sdist --no-build-isolation; no system cmake/ninja/swig):

  • Reproducer from Model build fails with "Required command 'ninja' not found" when the environment is not activated, although cmake and ninja are installed in it #3505, run as env -i HOME=$HOME PATH=/usr/bin:/bin /path/to/venv/bin/python repro.py: on main it fails with Required command 'cmake' not found; with this change the model builds. With another cmake but no ninja first on PATH: Required command 'ninja' not found on main; builds with this change. With the environment's bin on PATH: builds, as before.
  • pytest python/tests/test_misc.py with the environment on PATH: 20 passed, 1 failed. test_cmake_compilation needs the C++ CMake build in build/, which I did not do; it fails the same way on main.
  • The same without the environment on PATH (PATH=/usr/bin:/bin): on main the shared model fixture fails to build (2 errors). With this change, 19 passed. The two failures are test_cmake_compilation (as above) and test_model_rebuild_reruns_swig_on_swig_change, which looks up swig with shutil.which("swig") in the test itself.
  • The new test fails on 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

  • I have run the relevant tests locally
  • I have added a changelog entry in changelog.d/ (or it is not needed)

🤖 Generated with Claude Code

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>
@codekongdev
codekongdev requested a review from a team as a code owner November 5, 2026 04:59

This branch has not been deployed

No deployments
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.

Model build fails with "Required command 'ninja' not found" when the environment is not activated, although cmake and ninja are installed in it

1 participant