Skip to content

Select one of several installed OpenModelica versions - #490

Open
adrpo wants to merge 2 commits into
OpenModelica:masterfrom
adrpo:omhome-version
Open

adrpo wants to merge 2 commits into
OpenModelica:masterfrom
adrpo:omhome-version

Conversation

@adrpo

@adrpo adrpo commented Nov 17, 2026

Copy link
Copy Markdown
Member

Client part of OpenModelica/OpenModelica#5809 (several OpenModelica versions installed side by side on Windows).

With OpenModelica/OpenModelicaSetup#96 the Windows installer keeps OPENMODELICAHOME for the version selected as the default one and sets OPENMODELICAHOME_<version> for each installed version, with every character of the version that is not a letter or a digit replaced by an underscore, e.g. OPENMODELICAHOME_1_27_0 or OPENMODELICAHOME_1_28_0_dev_1962_g6e348e217c.

What changes

OMCSessionLocal and ModelicaSystemOMC get a version argument:

omc = OMPython.OMCSessionLocal(version="1.27.0")  # exactly this version
omc = OMPython.OMCSessionLocal(version="1.27")    # the newest installed 1.27.x
mod = OMPython.ModelicaSystemOMC(version="1.27.0")

OpenModelica is looked for in this order:

  1. the omhome argument
  2. the version argument
  3. OPENMODELICAHOME
  4. the newest OPENMODELICAHOME_<version>
  5. omc on the PATH
  • A version that is not installed raises OMSessionException with the list of the installed ones.
  • "Newest" compares the numbers of the version: for the same major.minor.patch a pre-release build (1.28.0-dev-…) is older than the release, which is older than a build after it (1.27.0-5-g…).
  • "1.2" does not match 1.27.0: the given version has to be followed by the end of the name or by _.
  • omc_home_versions() lists the installations found in the environment, newest first.

Compatibility

Without OPENMODELICAHOME_<version> variables (Linux, macOS, the current Windows installer) nothing changes: OPENMODELICAHOME is used as it is, then omc on the PATH. With them, an OPENMODELICAHOME that has no omc executable (left behind by an uninstalled version) is skipped.

Testing

  • tests/test_omc_home.py: 15 tests of the lookup with a fake environment and directories with an empty bin/omc; no omc is started.
  • Sessions started on Linux with OPENMODELICAHOME_1_99_0=/usr and version="1.99" (OMCSessionLocal and ModelicaSystemOMC), with no version, and with a version that is not installed.
  • tests/test_OMSessionCmd.py and tests/test_ZMQ.py pass; flake8 and codespell are clean, mypy and pylint report nothing new.
  • Not tested on Windows with real side by side installations; the installer change is still a draft.

🤖 Generated with Claude Code

The Windows installer is changed to allow several OpenModelica versions
side by side (OpenModelica/OpenModelica#5809,
OpenModelica/OpenModelicaSetup#96). OPENMODELICAHOME then points to the
default one and each version sets OPENMODELICAHOME_<version>, with the
characters of the version that are not letters or digits replaced by
underscores (OPENMODELICAHOME_1_27_0).

OMCSessionLocal and ModelicaSystemOMC get a version argument and look for
OpenModelica in this order:

1. the omhome argument
2. the version argument: OPENMODELICAHOME_<version>, or the newest
   installed version that starts with it ("1.27" for the newest 1.27.x)
3. OPENMODELICAHOME
4. the newest OPENMODELICAHOME_<version>
5. omc on the PATH

Without OPENMODELICAHOME_<version> variables nothing changes. With them,
an OPENMODELICAHOME without an omc executable (left behind by an
uninstalled version) is skipped. A version that is not installed raises
OMSessionException with the list of the installed ones.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
shutil.which only finds a file with an executable extension on Windows,
so the test that puts an empty omc on the PATH failed there.

Co-Authored-By: Claude Fable 5.2 <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.

1 participant