Skip to content

Python wrapper for OGS commandline tools

Christoph Lehmann requested to merge chleh/ogs:python-wrapper into master

This MR adds a very simple Python wrapper for OGS commandline tools.

The usage is as follows:

$ pip install ogs

$ python
>>> from ogs import cli
>>> return_code = cli.createQuadraticMesh("--version")

.../lib/python3.10/site-packages/ogs/_internal/../bin/createQuadraticMesh  version: 6.4.3-70-gd27595c4ed

>>> outfile = "/tmp/line.vtu"
>>> return_code = cli.generateStructuredMesh(e="line", lx=1, nx=10, o=outfile)
[2022-09-29 08:05:02.718] [ogs] [info] Mesh created: 11 nodes, 10 elements.

>>> help(cli.createQuadraticMesh)
Help on function run_cmd in module ogs._internal.wrap_cli_tools:

run_cmd(*args, **kwargs)
    This function wraps the commandline tool createQuadraticMesh for easy use from Python.
    
    The entries of args are passed as is to the commandline tool.
    The entries of kwargs are transformed: one-letter keys get a single
    dash as a prefix, multi-letter keys are prefixed with two dashes.
    
    Thereby, commandline tools can be used like proper Python functions, e.g.:
    
    >>> cli = CLI()
    >>> cli.createQuadraticMesh("--help") # prints a help text
    ...
    >>> cli.createQuadraticMesh(help=None) # special, does the same
    ...
    
    A more useful example. The following will create a line mesh:
    
    >>> outfile = "line.vtu"
    >>> cli.generateStructuredMesh(e="line", lx=1, nx=10, o=outfile)

Future Work

  • Improved help texts
  • Autocompletion of available tools
  • Options to capture tool output/write log files
  • Documentation on the OGS website

Checklist

  1. Feature description was added to the changelog
  2. Tests covering your feature were added?
  3. Any new feature or behavior change was documented?
Edited by Christoph Lehmann

Merge request reports

Loading