Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
99 commits
Select commit Hold shift + click to select a range
1b4368b
add shellout.py skeleton
Pierre-siddall Jan 19, 2026
de73ecd
Execute a subprocess
Pierre-siddall Jan 20, 2026
f8b0a3a
Implement basic logging
Pierre-siddall Jan 20, 2026
786900f
Apply black
Pierre-siddall Jan 20, 2026
7da2a02
Add exception handling
Pierre-siddall Jan 20, 2026
da9af7d
Add timer decorator
Pierre-siddall Jan 20, 2026
bb4667a
Seperate command string using shlex
Pierre-siddall Jan 20, 2026
9ca9722
Apply black again
Pierre-siddall Jan 20, 2026
baac45d
Replace instances of common.exec_subproc
Pierre-siddall Jan 20, 2026
bf3f823
Recplace all shellout instances (AI assisted)
Pierre-siddall Jan 20, 2026
787b5b5
Apply black to all modified files
Pierre-siddall Jan 20, 2026
665b2fa
Revert "Apply black to all modified files"
Pierre-siddall Jan 20, 2026
af43b3c
Merge branch 'main' into move-shellouts
Pierre-siddall Jan 20, 2026
abe99cd
Add AI statement
Pierre-siddall Jan 20, 2026
d3aafae
Update copyright statements
Pierre-siddall Jan 20, 2026
e3219e0
Remove timer
Pierre-siddall Jan 27, 2026
b5aaefc
Add copyright notice
Pierre-siddall Jan 27, 2026
49e485d
Move shellouts to mocilib
Pierre-siddall Jan 27, 2026
4a50e2d
Deprecate old code correctly
Pierre-siddall Jan 28, 2026
ecedc2e
Turn shellout.py into a package
Pierre-siddall Jan 28, 2026
757f378
Change import statements
Pierre-siddall Jan 28, 2026
5afda7e
Revert "Add AI statement"
Pierre-siddall Jan 28, 2026
ca5b95a
Reapply "Add AI statement"
Pierre-siddall Jan 28, 2026
8c575a0
Revert "Add AI statement"
Pierre-siddall Jan 28, 2026
04e4a1f
Revert "Recplace all shellout instances (AI assisted)"
Pierre-siddall Jan 28, 2026
018bc2b
Revert "Replace instances of common.exec_subproc"
Pierre-siddall Jan 28, 2026
8074de2
Add unit test for exec_subprocess
Pierre-siddall Jan 28, 2026
19e7e24
Add first unit tests
Pierre-siddall Jan 28, 2026
4203810
Add timeout parameter to shellouts
Pierre-siddall Jan 28, 2026
17fb5c9
Add unit tests to test error conditions
Pierre-siddall Jan 28, 2026
10a063a
Fix subprocess command
Pierre-siddall Jan 28, 2026
f91f9b9
Remove stdin parameter
Pierre-siddall Jan 28, 2026
a1296d3
Remove OS test case
Pierre-siddall Jan 28, 2026
a125be9
Remove version check
Pierre-siddall Jan 28, 2026
7bb2cf1
Add subprocess.TimeoutExpired error
Pierre-siddall Jan 28, 2026
25974d2
Add timeout expired unit test
Pierre-siddall Jan 28, 2026
1191b57
Ensure completed process output is always string
Pierre-siddall Jan 29, 2026
f3aa0e9
Merge branch 'main' into move-shellouts
Pierre-siddall Feb 9, 2026
5d0c559
Revert "Replace instances of common.exec_subproc"
Pierre-siddall Feb 9, 2026
fed4f72
Remove redundant import
Pierre-siddall Feb 16, 2026
1d048c7
Remove even more redundant imports
Pierre-siddall Feb 16, 2026
23010f8
Merge branch 'main' into move-shellouts
Pierre-siddall Feb 16, 2026
0545cc3
Add deprecated notices
Pierre-siddall Feb 16, 2026
f9e2999
replace shellout commands in tests_common_utils.py
Pierre-siddall Feb 16, 2026
e325557
change flow.cylc
Pierre-siddall Feb 17, 2026
d108e58
Revert "change flow.cylc"
Pierre-siddall Feb 17, 2026
1a5eb34
change unit tests
Pierre-siddall Feb 17, 2026
64ad6dc
delete hypothesis files
Pierre-siddall Feb 17, 2026
a652cf0
Revert "delete hypothesis files"
Pierre-siddall Feb 17, 2026
aa323f5
Revert "change unit tests"
Pierre-siddall Feb 17, 2026
03b7610
Deprivatise exec_subprocess
Pierre-siddall Feb 17, 2026
a690c08
move shellout tests to mocilib
Pierre-siddall Feb 17, 2026
a04340b
Add list handling to exec_subprocess
Pierre-siddall Feb 18, 2026
bc1f134
add mocilib to test_postproc script path
Pierre-siddall Feb 18, 2026
9e428a2
change callout to exec_subprocess in utils.py
Pierre-siddall Feb 18, 2026
80cbeb0
Revert "Add list handling to exec_subprocess"
Pierre-siddall Feb 18, 2026
13c1181
Handle FileNotFound error
Pierre-siddall Feb 19, 2026
4348e84
fix test_subproc_options
Pierre-siddall Feb 19, 2026
0b4068e
Fcm make retirement from rose-stem (#35)
ericaneininger Feb 25, 2026
06aa09e
change flow.cylc
Pierre-siddall Feb 17, 2026
6b471ce
Revert "change flow.cylc"
Pierre-siddall Feb 17, 2026
6fe86d5
update test subproc options
Pierre-siddall Mar 3, 2026
5e47718
Change build_pp rose app
Pierre-siddall Mar 3, 2026
1c98b9f
remove mocilib from rose app
Pierre-siddall Mar 3, 2026
d6a2e75
update shellout unit tests
Pierre-siddall Mar 3, 2026
0b7a9a7
Make postproc unit tests runnable
Pierre-siddall Mar 3, 2026
82165d9
Catch PermissionError
Pierre-siddall Mar 3, 2026
9f2056e
Revert "Update copyright statements"
Pierre-siddall Mar 3, 2026
5389d3d
Merge branch 'main' into move-shellouts
Pierre-siddall Mar 10, 2026
445d2b8
Merge branch 'main' into move-shellouts
Pierre-siddall Mar 11, 2026
7771703
Merge branch 'main' into move-shellouts
Pierre-siddall Mar 13, 2026
b9e78c8
Apply consistent styling
Pierre-siddall Mar 10, 2026
1d6ca42
fix shellout unittest paths
Pierre-siddall Mar 11, 2026
6032c6b
Change echo commands
Pierre-siddall Mar 11, 2026
c6d853c
Resolve build_pp.sh conflicts
Pierre-siddall Mar 11, 2026
9e25c40
Update flow.cylc
Pierre-siddall Mar 11, 2026
796ddda
Add mocilib test.py
Pierre-siddall Mar 11, 2026
e5f952d
Update flow.cylc
Pierre-siddall Mar 13, 2026
c8a97e3
change assertions
Pierre-siddall Mar 16, 2026
cb2f0ed
change passing of commands in mocilib unit tests
Pierre-siddall Mar 16, 2026
682d7f0
Rename shellout module
Pierre-siddall Mar 16, 2026
49fa82a
Remove directory parameter
Pierre-siddall Mar 16, 2026
6aadeb0
Add casting to called process error
Pierre-siddall Mar 16, 2026
4532517
Switch timeout return code
Pierre-siddall Mar 16, 2026
71b5d1c
add debug messages
Pierre-siddall Mar 17, 2026
6d45e1e
fix postproc unit tests and function unpacking
Pierre-siddall Mar 17, 2026
e7ed036
Rename unit tests
Pierre-siddall Mar 18, 2026
f6a94bd
Add called process pass unit test
Pierre-siddall Mar 18, 2026
8a64555
Add timeout expired pass unit test
Pierre-siddall Mar 18, 2026
08d5b76
Remove TODO line
Pierre-siddall Mar 18, 2026
1449124
Add fileNotFound unit tests
Pierre-siddall Mar 18, 2026
4ff5e45
Clean __init__.py
Pierre-siddall Mar 18, 2026
0d1eab4
Add ruff formatting
Pierre-siddall Mar 18, 2026
13721ca
Update mocilib/unittests/test_shellout.py
Pierre-siddall Mar 24, 2026
e565d04
Update mocilib/unittests/test_shellout.py
Pierre-siddall Mar 24, 2026
dcfde11
Update Postprocessing/common/utils.py
Pierre-siddall Mar 24, 2026
b21391a
Update Postprocessing/common/utils.py
Pierre-siddall Mar 24, 2026
3654444
Update Postprocessing/unittests/test_common_utils.py
Pierre-siddall Mar 24, 2026
831a3ea
Remove debug messages
Pierre-siddall Mar 24, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion Coupled_Drivers/cice_driver.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@
import re
import datetime
import time
import subprocess
import time2days
import inc_days
import common
Expand Down
12 changes: 12 additions & 0 deletions Coupled_Drivers/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,10 @@ def exec_subproc_timeout(cmd, timeout_sec=10):
the commands to be run, and an integer timeout_sec for how long to
wait for the command to run. Returns the return code from the process
and the standard out from the command or 'None' if the command times out.

This function is now DEPRECATED in favour of the exec_shellout function in
mocilib

'''
process = subprocess.Popen(cmd, shell=False,
stdin=subprocess.PIPE,
Expand All @@ -260,6 +264,10 @@ def exec_subproc(cmd, verbose=True):
Execute given shell command. Takes a list containing the commands to be
run, and a logical verbose which if set to true will write the output of
the command to stdout.

This function is now DEPRECATED in favour of the exec_shellout function in
mocilib

'''
process = subprocess.Popen(cmd, shell=False,
stdin=subprocess.PIPE,
Expand All @@ -281,6 +289,10 @@ def __exec_subproc_true_shell(cmd, verbose=True):
exec_subproc does not work correctly. Takes a list containing the commands
to be run, and a logical verbose which if set to true will write the
output of the command to stdout.

This function is now DEPRECATED in favour of the exec_shellout function in
mocilib

'''
process = subprocess.Popen(cmd, shell=True,
stdin=subprocess.PIPE,
Expand Down
1 change: 1 addition & 0 deletions Coupled_Drivers/mct_driver.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import dr_env_lib.mct_def
import dr_env_lib.env_lib
import cpmip_controller

try:
import f90nml
except ImportError:
Expand Down
1 change: 1 addition & 0 deletions Coupled_Drivers/rivers_driver.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import error
import dr_env_lib.rivers_def
import dr_env_lib.env_lib

try:
import f90nml
except ImportError:
Expand Down
6 changes: 4 additions & 2 deletions Postprocessing/build/build_pp.sh
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ PP_SOURCE_DIR=${PP_SOURCE_DIR:=$CYLC_WORKFLOW_RUN_DIR/share/source/moci_postproc
PP_TARGET_DIR=${PP_TARGET_DIR:-$CYLC_WORKFLOW_SHARE_DIR/bin}

MOCILIB=${MOCILIB:=true}
MOCILIB_PATH=${MOCILIB_PATH:=$CYLC_WORKFLOW_RUN_DIR/share/moci/mocilib}
MOCILIB_PATH=${MOCILIB_PATH:=$CYLC_WORKFLOW_SHARE_DIR/source/moci/mocilib}

PP_COMPONENTS="atmos nemocice unicicles archive_verify"
PP_TESTS=${PP_TESTS:=false}
Expand All @@ -38,10 +38,12 @@ if [[ ! -d $PP_TARGET_DIR ]] ; then
fi

# Copy mocilib

if [[ "$MOCILIB" != true ]] ; then
echo [INFO] MOCIlib library not installed
elif [[ -d "$MOCILIB_PATH" ]] ; then
cp -r $MOCILIB $PP_TARGET_DIR
echo [INFO] Copying MOCILIB ...
cp -r $MOCILIB_PATH $PP_TARGET_DIR
else
echo [ERROR] Failed to find the required \"mocilib\" library >&2
exit 1
Expand Down
43 changes: 16 additions & 27 deletions Postprocessing/common/utils.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/usr/bin/env python
'''
*****************************COPYRIGHT******************************
(C) Crown copyright 2015-2025 Met Office. All rights reserved.
(C) Crown copyright 2015-2026 Met Office. All rights reserved.

Use, duplication or disclosure of this code is subject to the restrictions
as set forth in the licence. If no licence has been raised with this copy
Expand All @@ -23,9 +23,9 @@
import os
import errno
import shutil
import subprocess
import timer

from mocilib import shellout

globals()['debug_mode'] = None
globals()['debug_ok'] = True
Expand Down Expand Up @@ -165,37 +165,26 @@ def exec_subproc(cmd, verbose=True, cwd=os.getcwd()):
failure of the command
True: reproduce std.out regardless of outcome
cwd = Directory in which to execute the command
'''
import shlex

cmd_array = [cmd]
if not isinstance(cmd, list):
cmd_array = cmd.split(';')
for i, cmd in enumerate(cmd_array):
# Use shlex.split to cope with arguments that contain whitespace
cmd_array[i] = shlex.split(cmd)
This function is now DEPRECATED in favour of the exec_subprocess function in
mocilib

'''
if isinstance(cmd, list):
cmd_array = [' '.join(cmd)]
else:
cmd_array = cmd.split(';')
# Initialise rcode, in the event there is no command
rcode = 99
rcode = -99
output = 'No command provided'

for cmd in cmd_array:
try:
output = subprocess.check_output(cmd,
stderr=subprocess.STDOUT,
universal_newlines=True, cwd=cwd)
rcode = 0
if verbose:
log_msg('[SUBPROCESS]: ' + str(output))
except subprocess.CalledProcessError as exc:
output = exc.output
rcode = exc.returncode
except OSError as exc:
output = exc.strerror
rcode = exc.errno
for i, cmd in enumerate(cmd_array):
rcode, output = shellout.exec_subprocess(
cmd, verbose=verbose, current_working_directory=cwd
)
if rcode != 0:
msg = '[SUBPROCESS]: Command: {}\n[SUBPROCESS]: Error = {}:\n\t{}'
log_msg(msg.format(' '.join(cmd), rcode, output), level='WARN')
msg = f'[SUBPROCESS]: Command: {cmd}\n[SUBPROCESS]: Error = {rcode}:\n\t {output}'
log_msg(msg, level='WARN')
break

return rcode, output
Expand Down
Loading