Skip to content

test.py does not honor $OPENMODELICALIBRARY #39

Open

Description

@bilderbuchi

I am currently running OMLT in a Docker container with a custom image based on openmodelica/openmodelica:v1.21.0-ompython, with the intention to test a local package.

To "install" my package as per the README, based on https://openmodelica.org/doc/OpenModelicaUsersGuide/latest/faq.html?highlight=openmodelicalibrary#openmodelica-general and https://openmodelica.org/doc/OpenModelicaUsersGuide/latest/packagemanager.html#overview-of-basic-modelica-package-management-concepts, I append the location of my package to the environment variable OPENMODELICALIBRARY. (At first, it was not clear to me how to "install" a package that is not available in the package manager)

When loading a model from the package using omc, this works as expected (except for an unrelated error fixed in OM master OpenModelica/OpenModelica#10564)

$ echo $OPENMODELICALIBRARY
/home/openmodelicausers/repo
$ omc --instClass=MyPackage.Examples.MyExample
...

Expected behaviour

For test.py to pick up and use the value of $OPENMODELICALIBRARY

Observed behaviour

However, test.py does not seem to honor the content of that environment variable:

$ cat ../repo/CI_OMLT.json
[
    {
        "library": "MyPackage",
        "libraryVersion": ""
    }
]
$ python3 test.py ../repo/CI_OMLT.json
...
Failed to load library MyPackage {"default"}: Error: Failed to load package MyPackage (default) using MODELICAPATH /home/openmodelicausers/.openmodelica/libraries/.

It is clear that the MODELICAPATH is incomplete/wrong, considering the value of the env var OPENMODELICALIBRARY.

(As an aside, in the config file libraryVersion MUST be "", otherwise loading the package fails even though it has a matching version annotation in its package.mo.)

I suspect the reason is a hard-coded default for the --libraries argument at https://github.com/OpenModelica/OpenModelicaLibraryTesting/blob/9aa10d5f1091bb6d6eafb7f5e3cf6c9cfb164acd/test.py#L95C24-L95C33

Workaround

To work around this, one needs to manually pass the env var to test.py with --libraries $OPENMODELICALIBRARY. In some circumstances it was even necessary to manually find and prepend the "default" location: --libraries ~/.openmodelica/libraries/:$OPENMODELICALIBRARY, otherwise MSL etc. would not be loaded.

Possible solution

I think the default value for the libraries argument should be the value of $OPENMODELICALIBRARY. Only if that is empty/undefined, maybe the current hard-coded /home/openmodelicausers/.openmodelica/libraries/ might be appropriate, but I don't know enough about the inner workings of omc to assess if that would do that internally, anyway.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions