Skip to content

Comments

Common CLI behavior#1198

Draft
woutdenolf wants to merge 1 commit intomasterfrom
1196-harmonize-cli-with-argparse
Draft

Common CLI behavior#1198
woutdenolf wants to merge 1 commit intomasterfrom
1196-harmonize-cli-with-argparse

Conversation

@woutdenolf
Copy link
Collaborator

@woutdenolf woutdenolf commented Feb 21, 2026

Two new modules for common behavior across all PyMca applications:

  • PyMca5.PyMcaGui.PyMcaAppInit: common behavior for multiprocessing, Qt, HDF5, matplotlib, logging.
    Common calls at these stages of the application start-up:
    • before importing application dependencies
    • after importing application dependencies and before instantiating the application
    • after instantiating and before starting the application
  • PyMca5.PyMcaMisc.CliUtils: common CLI behavior in terms of logging, common arguments.
    Uses argparse instead of getopt which provides proper --help for users.

The docstring of the two modules show the usage pattern.

Currently we have 28 CLI's of which 20 are Qt apps. There are many more files with a __main__, many of which using sys.argv directly, but I only handled the once that already had a CLI by using getopt or argparse.

In addition I added unit tests for the CLI: python -m PyMca5.tests.CliTest

Main CLI as an example
pymca --help

usage: pymca [-h] [--debug DEBUG] [--log-level {DEBUG,INFO,WARNING,ERROR,CRITICAL}] [--version] [--qt {5,6}]
             [--binding {pyqt5,pyqt6,pyside2,pyside6}]
             [--backend {matplotlib,mpl,gl,opengl,glut,osmesa,mesa,silx,silx-mpl,silxmpl,silx-gl,silxgl}]
             [--spec SPEC] [--shm SHM] [--fresh] [--nativefiledialogs NATIVEFILEDIALOGS] [--profiling] [--test]
             [files ...]

Main PyMca GUI

positional arguments:
  files                 Optional list of data files to open (default: None)

options:
  -h, --help            show this help message and exit
  --debug DEBUG         Enable debug mode (default: 0)
  --log-level {DEBUG,INFO,WARNING,ERROR,CRITICAL}
                        Logging level (default: WARNING)
  --version             Show version and exit (default: False)
  --qt {5,6}            Force Qt version (default: None)
  --binding {pyqt5,pyqt6,pyside2,pyside6}
                        Qt binding (default: None)
  --backend {matplotlib,mpl,gl,opengl,glut,osmesa,mesa,silx,silx-mpl,silxmpl,silx-gl,silxgl}
                        The plot backend to use: Matplotlib, OpenGL 2.1 (requires appropriate OpenGL drivers),
                        or Off-screen Mesa OpenGL software pipeline (requires OSMesa library). (default: mpl)
  --spec SPEC           Spec file (default: None)
  --shm SHM             Shared memory spec (default: None)
  --fresh, -f           Clear configuration (default: False)
  --nativefiledialogs NATIVEFILEDIALOGS
                        Use native file dialogs (default: 0)
  --profiling           Run main loop under profiler (default: False)
  --test                Run unit tests (default: False)

@woutdenolf woutdenolf linked an issue Feb 21, 2026 that may be closed by this pull request
@woutdenolf woutdenolf marked this pull request as draft February 21, 2026 22:41
@woutdenolf woutdenolf force-pushed the 1196-harmonize-cli-with-argparse branch 11 times, most recently from 24da256 to 53cb97f Compare February 22, 2026 12:54
@woutdenolf woutdenolf force-pushed the 1196-harmonize-cli-with-argparse branch from 53cb97f to e9baeba Compare February 22, 2026 16:09
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.

Harmonize CLI with argparse

1 participant