Skip to content
GitLab
Projects Groups Topics Snippets
  • /
  • Help
    • Help
    • Support
    • Community forum
    • Submit feedback
  • Register
  • Sign in
  • O ogs
  • Project information
    • Project information
    • Activity
    • Labels
    • Members
  • Repository
    • Repository
    • Files
    • Commits
    • Branches
    • Tags
    • Contributor statistics
    • Graph
    • Compare revisions
    • Locked files
  • Issues 111
    • Issues 111
    • List
    • Boards
    • Service Desk
    • Milestones
    • Iterations
  • Merge requests 42
    • Merge requests 42
  • CI/CD
    • CI/CD
    • Pipelines
    • Jobs
    • Schedules
    • Test cases
  • Deployments
    • Deployments
    • Environments
    • Releases
  • Packages and registries
    • Packages and registries
    • Package Registry
    • Container Registry
    • Infrastructure Registry
  • Wiki
    • Wiki
  • Activity
  • Graph
  • Create a new issue
  • Jobs
  • Commits
  • Issue Boards
Collapse sidebar
  • ogsogs
  • ogs
  • Merge requests
  • !4285

Python wrapper for OGS commandline tools

  • Review changes

  • Download
  • Email patches
  • Plain diff
Merged Christoph Lehmann requested to merge chleh/ogs:python-wrapper into master Sep 20, 2022
  • Overview 8
  • Commits 1
  • Pipelines 9
  • Changes 3

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 Sep 29, 2022 by Christoph Lehmann
Assignee
Assign to
Reviewers
Request review from
Time tracking
Source branch: python-wrapper