Skip to content
Snippets Groups Projects
Commit c164cee5 authored by Paul McCarthy's avatar Paul McCarthy :mountain_bicyclist:
Browse files

Merge branch 'wrapper_to_cmd' into 'main'

Fix infinite regression error when pickling wrapper functions

See merge request fsl/fslpy!449
parents c622941e 6e89eab3
No related branches found
No related tags found
No related merge requests found
...@@ -20,6 +20,7 @@ import pytest ...@@ -20,6 +20,7 @@ import pytest
import fsl.utils.tempdir as tempdir import fsl.utils.tempdir as tempdir
from fsl.utils.platform import platform as fslplatform from fsl.utils.platform import platform as fslplatform
import fsl.utils.run as run import fsl.utils.run as run
import fsl.wrappers as wrappers
from . import make_random_image, mockFSLDIR, CaptureStdout, touch from . import make_random_image, mockFSLDIR, CaptureStdout, touch
...@@ -479,7 +480,7 @@ def test_hold(): ...@@ -479,7 +480,7 @@ def test_hold():
threading.Thread(target=create_holdfile).start() threading.Thread(target=create_holdfile).start()
run.hold([1, 2, 3], holdfile, timeout=1) run.hold([1, 2, 3], holdfile, timeout=1)
cmds = list(run.dryrun.commands) cmds = list(run.DRY_RUN_COMMANDS)
# dryrun gathers all executed commands # dryrun gathers all executed commands
# in a list of (cmd, submit) tuples, # in a list of (cmd, submit) tuples,
...@@ -534,6 +535,11 @@ def test_func_to_cmd(): ...@@ -534,6 +535,11 @@ def test_func_to_cmd():
else: else:
assert op.exists(fn), f"Failing job got removed even with clean = {clean}" assert op.exists(fn), f"Failing job got removed even with clean = {clean}"
def test_wrapper_to_cmd():
fn = run.func_to_cmd(wrappers.bet)
assert op.exists(fn)
assert op.basename(fn).startswith("bet_")
def test_job_output(): def test_job_output():
with tempdir.tempdir() as td: with tempdir.tempdir() as td:
......
...@@ -53,6 +53,12 @@ DRY_RUN = False ...@@ -53,6 +53,12 @@ DRY_RUN = False
execute them. execute them.
""" """
DRY_RUN_COMMANDS = None
"""Contains the commands that got logged during a dry run.
Commands will be logged if :data:`DRY_RUN` is true, which can be set using :func:`dryrun`.
"""
FSL_PREFIX = None FSL_PREFIX = None
"""Global override for the FSL executable location used by :func:`runfsl`. """ """Global override for the FSL executable location used by :func:`runfsl`. """
...@@ -73,14 +79,14 @@ def dryrun(*_): ...@@ -73,14 +79,14 @@ def dryrun(*_):
After this function returns, each command that was executed while the After this function returns, each command that was executed while the
dryrun is active, along with any submission parameters, will be accessible dryrun is active, along with any submission parameters, will be accessible
within a list which is stored as an attribute of this function called within a list which is stored as :data:`DRY_RUN_COMMANDS`.
``commands``.
""" """
global DRY_RUN # pylint: disable=global-statement global DRY_RUN, DRY_RUN_COMMANDS # pylint: disable=global-statement
oldval = DRY_RUN oldval = DRY_RUN
DRY_RUN = True DRY_RUN = True
dryrun.commands = [] DRY_RUN_COMMANDS = []
try: try:
yield yield
...@@ -106,7 +112,6 @@ def prepareArgs(args): ...@@ -106,7 +112,6 @@ def prepareArgs(args):
return list(args) return list(args)
real_stdout = sys.stdout
def _forwardStream(in_, *outs): def _forwardStream(in_, *outs):
"""Creates and starts a daemon thread which forwards the given input stream """Creates and starts a daemon thread which forwards the given input stream
to one or more output streams. Used by the :func:`run` function to redirect to one or more output streams. Used by the :func:`run` function to redirect
...@@ -269,7 +274,8 @@ def _dryrun(submit, returnStdout, returnStderr, returnExitcode, *args): ...@@ -269,7 +274,8 @@ def _dryrun(submit, returnStdout, returnStderr, returnExitcode, *args):
# Save command/submit parameters - # Save command/submit parameters -
# see the dryrun ctx manager # see the dryrun ctx manager
getattr(dryrun, 'commands', []).append((args, submit)) if DRY_RUN_COMMANDS is not None:
DRY_RUN_COMMANDS.append((args, submit))
if submit: if submit:
return ('0',) return ('0',)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment