-
-
Notifications
You must be signed in to change notification settings - Fork 1
Command Line Options
MoleditPy's CLI is defined with argparse in main.py (prog="moleditpy"). This page documents every flag, the positional argument, and the environment variables that change runtime behavior.
usage: moleditpy [-h] [--version] [--safe] [--install-plugin PATH] [file]
nargs="?", default=None— "File to open on startup"
If given, MoleditPy opens this file immediately after launch, exactly as if you had used the relevant File ▸ Open/Import action. There is no restriction on extension in the parser itself — what happens depends on what the file actually is; unsupported/corrupt files fail the same way they would from the GUI's open dialog.
moleditpy molecule.mol
moleditpy project.pmeprjStandard argparse help text; prints usage and exits.
action="version" — prints MoleditPy {VERSION} (or MoleditPy (Linux) {VERSION} when running from the moleditpy-linux distribution — detected by checking whether "moleditpy_linux" appears in __file__) and exits immediately, before Qt is even imported. VERSION comes from moleditpy/src/moleditpy/utils/constants.py.
moleditpy --version
# MoleditPy <version>
action="store_true", default=False— "Start in safe mode: skip loading all plugins"
Passed through to MainWindow(initial_file=..., safe_mode=True). In ui/main_window_init.py, safe mode sets self.host.plugin_manager = None entirely (the PluginManager is never constructed) and logs "Safe mode: plugins disabled.". Consequences:
- No plugin
.pyfiles under~/.moleditpy/plugins/are discovered, loaded, orinitialize()d — including plugins that provide file openers, 3D styles, or menu actions. - Opening
Plugin ▸ Plugin Manager...shows an informational dialog — "Plugins are disabled (safe mode)." — instead of the plugin table, since there is noPluginManagerinstance to browse. - Use this to recover from a crash caused by a broken/incompatible plugin, or to rule plugins in/out when debugging a problem.
moleditpy --safe
metavar="PATH"— "Install a plugin from a .py file, .zip, or folder (Headless)"
Installs a plugin without launching the GUI at all — this is a separate headless code path in main(), executed and exited before QApplication is created:
- Resolves
PATHto an absolute path; if it doesn't exist, printsError: Plugin path not found: {path}and exits with status1. - Computes the plugin's SHA-256 (
PluginManager.compute_sha256) — for a.pyfile or.zip, the hash of the file itself; for a folder, a hash derived from its contents. - If the path is a folder containing an
__init__.py, metadata is read from that__init__.py(PLUGIN_NAME,PLUGIN_AUTHOR,PLUGIN_VERSION,PLUGIN_DESCRIPTIONconstants, seeget_plugin_info_safe); for a bare.pyfile the same constants are read directly; for a.zipno metadata preview is available before install. - Prints a confirmation summary (name, author, version, description, path, SHA-256) and prompts interactively:
Only a literal
Do you want to proceed with installation? (y/N):yproceeds; anything else (including Enter) printsInstallation aborted.and exits0. - On
y, callsPluginManager.install_plugin(path), which copies the file/zip/folder into~/.moleditpy/plugins/(see Using Plugins for what "install" means in more detail). PrintsSuccess: {msg}and exits0, orError: {msg}and exits1.
Because this path calls input(), it is meant for interactive terminal use (e.g. scripted first-time setup), not for a fully unattended pipeline — there is no --yes/--force flag to skip the confirmation.
moleditpy --install-plugin ~/Downloads/my_plugin.py
moleditpy --install-plugin ~/Downloads/some_plugin.zip
moleditpy --install-plugin ~/Downloads/some_plugin_folder/The parser calls parser.parse_known_args(), not parse_args(), specifically so that Qt's own command-line flags (e.g. -platform offscreen, -style, -geometry) pass straight through to QApplication untouched — anything argparse doesn't recognize is forwarded as remaining and appended to sys.argv when constructing QApplication([sys.argv[0]] + remaining). This means you can combine MoleditPy's own flags with Qt's:
moleditpy --safe -platform offscreenThese are read directly via os.environ, not via argparse — set them in the shell before launching.
Checked in two places:
-
main.py: setup_logging()— if set (any truthy string), the GUI error-dialog handler (_ErrorDialogHandler, which pops aQMessageBoxfor every ERROR/CRITICAL log record) is not installed. This exists because a blocking modal dialog would hang an automated/headless run waiting for a click that will never come. -
ui/io_logic.py: _report_load_error()— if set, load-error dialogs (QMessageBox.warning) are skipped; only the status-bar message is shown. Without it, a failed file load in a headless environment would otherwise try to pop a modal warning box.
This is how MoleditPy's own test suite runs (see the main-app CLAUDE.md): MOLEDITPY_HEADLESS=1 QT_QPA_PLATFORM=offscreen python tests/run_all_tests.py .... It is not read by main.py's CLI parsing at all — it changes behavior after launch, not startup flags.
Not read by MoleditPy's own code — this is a Qt/PyQt6 environment variable consumed by the Qt platform-abstraction layer itself, before any Python moleditpy code runs. Setting it to offscreen makes Qt render without an actual display/X server/compositor, which is what lets MoleditPy start at all on a headless CI runner or an SSH session with no DISPLAY. Without a real display and without this variable, Qt fails to initialize with a platform-plugin error (see Troubleshooting Common Issues).
MOLEDITPY_HEADLESS=1 QT_QPA_PLATFORM=offscreen moleditpy --safemain.py reads ~/.moleditpy/settings.json before Qt/logging is configured (_read_startup_log_settings()), specifically for two keys that are otherwise set from Settings ▸ Settings... ▸ Other:
| Key | Effect at startup |
|---|---|
log_to_file (bool, default False) |
If true, a RotatingFileHandler is attached writing to ~/.moleditpy/moleditpy.log (1 MiB per file, 3 backups kept). |
log_level_debug (bool, default False) |
If true, the root logger level is DEBUG instead of INFO. |
These aren't CLI flags — you can't set them with --log-to-file — but they behave like startup configuration since they're read from disk before the window opens, and any parse failure (missing file, malformed JSON) silently falls back to (False, False).
-
Troubleshooting Common Issues — what to do when
QT_QPA_PLATFORM/OpenGL/plugin-loading goes wrong -
Using Plugins — the full plugin install/uninstall/safe-mode picture beyond
--install-plugin