Python environment

In OGS we make use of Python packages at different stages, e.g.:

  • Conan at configure-time to install third-party dependencies
  • ogs-container-maker when the CI prepares its environment
  • TESPy for simulating thermal engineering plants in a benchmark
  • pvpython for pre- and post-processing
  • nbconvert for testing Jupyter Notebooks

Python packages are usually installed via pip and virtualenv provides an isolated environment to install these packages to.

Poetry

We make use of poetry which is a wrapper for pip and virtualenv. We recommend to install poetry with your system package manager or:

(Invoke-WebRequest -Uri https://raw.githubusercontent.com/python-poetry/poetry/master/get-poetry.py -UseBasicParsing).Content | python -
curl -sSL https://raw.githubusercontent.com/python-poetry/poetry/master/get-poetry.py | python -
curl -sSL https://raw.githubusercontent.com/python-poetry/poetry/master/get-poetry.py | python -

When configuring with CMake poetry creates a new virtual environment in the .venv-directory inside your build directory. It will also install required Python packages into this environment. You can see the current environment definition in the file pyproject.toml inside your build-directory.

To manually add Python packages run the following inside your build-directory:

poetry add python-package-name # e.g. poetry add numpy

To activate the environment run poetry shell (this opens a new shell) or for one-off commands run poetry run command, e.g. poetry run pip list.

Poetry & Conan

You can also install Conan with Poetry (so you don’t need to install it system-wide) with the CMake-option OGS_USE_CONAN=auto:

cmake ../ogs -DOGS_USE_CONAN=auto

Poetry & Benchmarks

You can use the argument PYTHON_PACKAGES on AddTest() to specify additional Python package dependencies.

The following example would install the latest version of numpy and pandas version 0.1.2:

AddTest(
    ...
    PYTHON_PACKAGES numpy pandas=0.1.2
    ...
)

This article was written by Lars Bilke. If you are missing something or you find an error please let us know. Generated with Hugo 0.79.0. Last revision: January 20, 2022
Commit: MR comments. dc321763  | Edit this page on