Skip to content

Commit

Permalink
allow process version to be printed to terminal (#3379)
Browse files Browse the repository at this point in the history
* allow process version to be printed to terminal

* add version monkeypatch to test_run_mode
  • Loading branch information
clmould authored and chris-ashe committed Nov 8, 2024
1 parent 48eb81a commit 9baa160
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 0 deletions.
3 changes: 3 additions & 0 deletions process/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
from importlib.metadata import version

__version__ = version("process")
9 changes: 9 additions & 0 deletions process/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@
from process.impurity_radiation import initialise_imprad
from process.caller import write_output_files

import process

from pathlib import Path
import os
Expand Down Expand Up @@ -191,6 +192,11 @@ def parse_args(self, args):
action="store_true",
help="Produce a filled json from --mfile arg in working dir",
)
parser.add_argument(
"--version",
action="store_true",
help="Print the version of PROCESS to the terminal",
)

# If args is not None, then parse the supplied arguments. This is likely
# to come from the test suite when testing command-line arguments; the
Expand All @@ -202,6 +208,9 @@ def parse_args(self, args):

def run_mode(self):
"""Determine how to run Process."""
if self.args.version:
print(process.__version__)
return
# Store run object: useful for testing
if self.args.varyiterparams:
self.run = VaryRun(self.args.varyiterparamsconfig, self.args.solver)
Expand Down
1 change: 1 addition & 0 deletions tests/unit/test_main.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ def test_run_mode(process_obj, monkeypatch):
# Mock the args attributes for --varyiterparams and --varyiterparamsconfig
monkeypatch.setattr(process_obj, "args", argparse.Namespace(), raising=False)
monkeypatch.setattr(process_obj.args, "varyiterparams", True, raising=False)
monkeypatch.setattr(process_obj.args, "version", False, raising=False)
monkeypatch.setattr(
process_obj.args, "varyiterparamsconfig", "file.conf", raising=False
)
Expand Down

0 comments on commit 9baa160

Please sign in to comment.