Skip to content

Commit

Permalink
Issue1535 (#1536)
Browse files Browse the repository at this point in the history
* Remove 'R' formatter
* Remove remote target type
* Remove function sos remote push and sos remote pull.
* Stop interpreting paths in configuration file.
* Stop supporting named path (e.g. #home because we now assume home will be the same across hosts`)
* Stop converting paths like workdir because they are supposed to be the same across hosts.
  • Loading branch information
BoPeng authored Feb 17, 2024
1 parent 80aa3cb commit bda3d81
Show file tree
Hide file tree
Showing 31 changed files with 508 additions and 1,944 deletions.
1 change: 1 addition & 0 deletions requirements_dev.txt
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,5 @@ pytest
pytest-cov
pyzmq
sos-pbs
tabulate>=0.9.0
tqdm
7 changes: 0 additions & 7 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,6 @@ def run(self):
file_target = sos.targets:file_target
sos_tempfile = sos.targets:sos_tempfile
dynamic = sos.targets:dynamic
remote = sos.targets:remote
executable = sos.targets:executable
sos_variable = sos.targets:sos_variable
sos_step = sos.targets:sos_step
Expand All @@ -126,14 +125,8 @@ def run(self):
[sos_actions]
script = sos.actions:script
sos_run = sos.actions:sos_run
fail_if = sos.actions:fail_if
warn_if = sos.actions:warn_if
stop_if = sos.actions:stop_if
done_if = sos.actions:done_if
skip_if = sos.actions:skip_if
download = sos.actions:download
run = sos.actions:run
bash = sos.actions_bash:bash
csh = sos.actions_bash:csh
tcsh = sos.actions_bash:tcsh
Expand Down
16 changes: 0 additions & 16 deletions src/sos/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -1057,22 +1057,6 @@ def cmd_remote(args, workflow_args):
from .remote import run_command_on_hosts

run_command_on_hosts(cfg, args.hosts, args.cmd, args.verbosity)
elif args.action == "push":
if not args.files:
raise ValueError(
"Please specify files to push to remote host with option --files"
)
from .remote import push_to_hosts

push_to_hosts(cfg, args.hosts, args.files, args.verbosity)
elif args.action == "pull":
if not args.files:
raise ValueError(
"Please specify files to pull from remote host with option --files"
)
from .remote import pull_from_host

pull_from_host(cfg, args.hosts, args.files, args.verbosity)
else:
raise ValueError(
"Unacceptable remote action. Use command 'sos remote -h' to check allowable actions."
Expand Down
59 changes: 5 additions & 54 deletions src/sos/actions.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
#
# Copyright (c) Bo Peng and the University of Texas MD Anderson Cancer Center
# Distributed under the terms of the 3-clause BSD License.

import copy
import gzip
import os
Expand Down Expand Up @@ -33,18 +32,13 @@
from .parser import SoS_Script
from .syntax import SOS_ACTION_OPTIONS
from .targets import executable, file_target, path, paths, sos_targets
from .utils import (StopInputGroup, TerminateExecution,
TimeoutInterProcessLock, env, fileMD5, get_traceback,
from .utils import (TimeoutInterProcessLock, env, fileMD5, get_traceback,
load_config_files, short_repr, textMD5, transcribe)

__all__ = [
"SoS_Action",
"script",
"sos_run",
"fail_if",
"warn_if",
"stop_if",
"download",
"run",
"perl",
"report",
Expand Down Expand Up @@ -129,8 +123,7 @@ def action_wrapper(*args, **kwargs):
"shub",
"oras",
):
env.logger.warning(
f"Container type {cty} might not be supported.")
env.logger.warning(f"Container type {cty} might not be supported.")
elif engine is not None and engine != "local":
raise ValueError(f"Only docker and singularity container engines are supported: {engine} specified")
else:
Expand Down Expand Up @@ -412,8 +405,9 @@ def run(self, **kwargs):
else:
raise RuntimeError(f"Unacceptable interpreter {self.interpreter}")

debug_script_path = os.path.dirname(os.path.abspath(kwargs["stderr"])) if ("stderr" in kwargs and kwargs["stderr"] is not False and
os.path.isdir(os.path.dirname(os.path.abspath(kwargs["stderr"])))) else env.exec_dir
debug_script_path = os.path.dirname(os.path.abspath(kwargs["stderr"])) if (
"stderr" in kwargs and kwargs["stderr"] is not False and
os.path.isdir(os.path.dirname(os.path.abspath(kwargs["stderr"])))) else env.exec_dir
debug_script_file = os.path.join(
debug_script_path,
f'{env.sos_dict["step_name"]}_{env.sos_dict["_index"]}_{str(uuid.uuid4())[:8]}{self.suffix}',
Expand Down Expand Up @@ -769,49 +763,6 @@ def script(script, interpreter="", suffix="", args="", entrypoint="", **kwargs):
return SoS_ExecuteScript(script, interpreter, suffix, args, entrypoint).run(**kwargs)


@SoS_Action(acceptable_args=["expr", "msg"])
def fail_if(expr, msg=""):
"""Raise an exception with `msg` if condition `expr` is False"""
if expr:
raise TerminateExecution(msg if msg else "error triggered by action fail_if")
return 0


@SoS_Action(acceptable_args=["expr", "msg"])
def warn_if(expr, msg=""):
"""Yield an warning message `msg` if `expr` is False """
if expr:
env.logger.warning(msg)
return 0


@SoS_Action(acceptable_args=["expr", "msg", "no_output"])
def stop_if(expr, msg="", no_output=False):
"""Abort the execution of the current step or loop and yield
an warning message `msg` if `expr` is False"""
if expr:
raise StopInputGroup(msg=msg, keep_output=not no_output)
return 0


@SoS_Action(acceptable_args=["expr", "msg"])
def done_if(expr, msg=""):
"""Assuming that output has already been generated and stop
executing the rest of the substep"""
if expr:
raise StopInputGroup(msg=msg, keep_output=True)
return 0


@SoS_Action(acceptable_args=["expr", "msg", "no_output"])
def skip_if(expr, msg=""):
"""Skip the current substep and set _output to empty. Output
will be removed if already generated."""
if expr:
raise StopInputGroup(msg=msg, keep_output=False)
return 0


#
# download file with progress bar
#
Expand Down
65 changes: 65 additions & 0 deletions src/sos/functions.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
from .utils import (StopInputGroup, TerminateExecution, env)

# g_action_map = {}

# def _load_actions():
# global g_action_map # pylint: disable=global-variable-not-assigned
# for _entrypoint in pkg_resources.iter_entry_points(group="sos_actions"):
# # import actions from entry_points
# # Grab the function that is the actual plugin.
# _name = _entrypoint.name
# try:
# _plugin = _entrypoint.load()
# g_action_map[_name] = _plugin
# except Exception as e:
# from .utils import get_logger

# # look for sos version requirement
# get_logger().warning(f"Failed to load script running action {_entrypoint.name}: {e}")

# def sos_run_script(action, script, *args, **kwargs):
# '''Call script-execution actions.'''
# if not g_action_map:
# _load_actions()
# try:
# g_action_map[action](script, *args, **kwargs)
# except KeyError as e:
# raise RuntimeError(f'Undefined script running action {action}') from e


def stop_if(expr, msg="", no_output=False):
"""Abort the execution of the current step or loop and yield
an warning message `msg` if `expr` is False"""
if expr:
raise StopInputGroup(msg=msg, keep_output=not no_output)
return 0


def done_if(expr, msg=""):
"""Assuming that output has already been generated and stop
executing the rest of the substep"""
if expr:
raise StopInputGroup(msg=msg, keep_output=True)
return 0


def skip_if(expr, msg=""):
"""Skip the current substep and set _output to empty. Output
will be removed if already generated."""
if expr:
raise StopInputGroup(msg=msg, keep_output=False)
return 0


def fail_if(expr, msg=""):
"""Raise an exception with `msg` if condition `expr` is False"""
if expr:
raise TerminateExecution(msg if msg else "error triggered by action fail_if")
return 0


def warn_if(expr, msg=""):
"""Yield an warning message `msg` if `expr` is False """
if expr:
env.logger.warning(msg)
return 0
Loading

0 comments on commit bda3d81

Please sign in to comment.