Skip to content

Commit

Permalink
Deprecate section option skip #1132
Browse files Browse the repository at this point in the history
  • Loading branch information
Bo Peng committed Dec 29, 2018
1 parent 06463de commit 0cd7827
Show file tree
Hide file tree
Showing 6 changed files with 7 additions and 83 deletions.
4 changes: 2 additions & 2 deletions src/sos/syntax.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

from typing import Callable
SOS_TARGETS_OPTIONS = ['group_by', 'paired_with', 'pattern', 'group_with', 'for_each']
SOS_INPUT_OPTIONS = ['filetype', 'concurrent']
SOS_INPUT_OPTIONS = ['concurrent']
SOS_OUTPUT_OPTIONS = []
SOS_DEPENDS_OPTIONS = []
SOS_RUNTIME_OPTIONS = ['workdir', 'concurrent', 'active', 'walltime', 'nodes',
Expand All @@ -18,7 +18,7 @@
'allow_error', 'tracked', 'stdout', 'stderr', 'default_env', 'env']

SOS_DIRECTIVES = ['input', 'output', 'depends', 'task', 'parameter']
SOS_SECTION_OPTIONS = ['skip', 'provides', 'shared', 'workdir']
SOS_SECTION_OPTIONS = ['provides', 'shared', 'workdir']

SOS_KEYWORDS = SOS_INPUT_OPTIONS + SOS_OUTPUT_OPTIONS + SOS_DEPENDS_OPTIONS + SOS_RUNTIME_OPTIONS \
+ SOS_ACTION_OPTIONS + SOS_DIRECTIVES + SOS_SECTION_OPTIONS
Expand Down
27 changes: 0 additions & 27 deletions src/sos/workflow_executor.py
Original file line number Diff line number Diff line change
Expand Up @@ -318,29 +318,6 @@ def init_dict(self) -> None:
if not key.startswith('__'):
env.sos_dict.set(key, value)

def skip(self, section: SoS_Step) -> bool:
if section.global_def:
try:
SoS_exec(section.global_def)
except subprocess.CalledProcessError as e:
raise RuntimeError(e.stderr)
except RuntimeError as e:
if env.verbosity > 2:
sys.stderr.write(get_traceback())
raise RuntimeError(
f'Failed to execute statements\n"{section.global_def}"\n{e}')
#
if 'skip' in section.options:
val_skip = section.options['skip']
if val_skip is None or val_skip is True:
env.logger.info(
f'``{section.step_name(True)}`` is ``ignored`` due to skip option.')
return True
elif val_skip is not False:
raise RuntimeError(
f'The value of section option skip can only be None, True or False, {val_skip} provided')
return False

def match(self, target: BaseTarget, step: SoS_Step) -> Union[Dict[str, str], bool]:
# for sos_step, we need to match step name
if isinstance(target, sos_step):
Expand Down Expand Up @@ -442,8 +419,6 @@ def resolve_dangling_targets(self, dag: SoS_DAG, targets: Optional[sos_targets]=
default_input: sos_targets = sos_targets()
#
for idx, section in enumerate(sections):
if self.skip(section):
continue
res = analyze_section(section, default_input)

environ_vars = res['environ_vars']
Expand Down Expand Up @@ -634,8 +609,6 @@ def initialize_dag(self, targets: Optional[List[str]] = [], nested: bool = False
default_input: sos_targets = sos_targets([])
targets = sos_targets(targets)
for idx, section in enumerate(self.workflow.sections):
if self.skip(section):
continue
#
res = analyze_section(section, default_input)

Expand Down
24 changes: 0 additions & 24 deletions test/test_execute.py
Original file line number Diff line number Diff line change
Expand Up @@ -960,30 +960,6 @@ def testLocalNamespace(self):
self.assertEqual(env.sos_dict['shared'], 'c.txt')
self.assertEqual(env.sos_dict['d'], 2)

#
# def testCollectionOfErrors(self):
# '''Test collection of errors when running in dryrun mode.'''
# script = SoS_Script('''
# [0]
#depends: executable('a1')
# [1: skip='blah']
#depends: executable('a2')
#
# [2]
#input: None
#depends: executable('a3')
# [3]
#depends: executable('a4')
#
# ''')
# wf = script.workflow()
# # we should see a single error with 2 messages.
# # because 2 being on a separate branch will be executed but
# # the later steps will not be executed
# try:
# Base_Executor(wf).run(mode='dryrun')
# except Exception as e:
# self.assertEqual(len(e.errors), 3)

def testDynamicOutput(self):
'''Testing dynamic output'''
Expand Down
4 changes: 2 additions & 2 deletions test/test_nested.py
Original file line number Diff line number Diff line change
Expand Up @@ -347,7 +347,7 @@ def testIncludedNestedWorkFlow(self):
if 'executed' not in locals():
executed = []
[b_1: skip=False, shared='executed']
[b_1: shared='executed']
executed.append(step_name)
input: 'a.txt', 'b.txt', group_by='single'
sos_run('A', shared='executed')
Expand All @@ -371,7 +371,7 @@ def testIncludedNestedWorkFlow(self):
if 'executed' not in locals():
executed = []
[b_1: skip=False, shared='executed']
[b_1: shared='executed']
executed.append('g.' + step_name)
input: 'a.txt', 'b.txt', group_by='single'
sos_run('k.A', shared='executed')
Expand Down
29 changes: 2 additions & 27 deletions test/test_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@
var3 = 'a'
[section_3, *_4 : shared='var4', skip ]
[section_3, *_4 : shared='var4']
output:
var2,
var3
Expand Down Expand Up @@ -119,11 +119,6 @@ def testWorkflows(self):
self.assertEqual(sorted(script.workflows), [
'', 'human', 'mouse'])
script = SoS_Script('''[0]\n[*_1]\n[human_1]\n[mouse_2]\n[s*_2]''')
self.assertEqual(sorted(script.workflows), [
'', 'human', 'mouse'])
# skip option is not effective at parsing time
script = SoS_Script(
'''[0]\n[*_1]\n[human_1]\n[mouse_2:skip]\n[s*_2]''')
self.assertEqual(sorted(script.workflows), [
'', 'human', 'mouse'])
# unnamed
Expand All @@ -147,32 +142,14 @@ def testTypeHint(self):
# action
SoS_Script('''a : expand='${ }' ''')

def testSkipStep(self):
'''Test the skip option to skip certain steps'''
script = SoS_Script('''
parameter: skip = 0
[0: shared={'a':'var'}, skip=skip==0]
var = 0
[1: shared={'b': 'var'}, skip=skip==1]
var = 1
''')
wf = script.workflow()
Base_Executor(wf, args=['--skip', '0']).run()
self.assertEqual(env.sos_dict['b'], 1)
#
Base_Executor(wf, args=['--skip', '1']).run()
self.assertEqual(env.sos_dict['a'], 0)

def testSections(self):
'''Test section definitions'''
# bad names
for badname in ['56_1', '_a', 'a_', '1x', '*', '?']:
self.assertRaises(ParsingError, SoS_Script, '[{}]'.format(badname))
# bad options
for badoption in ['ss', 'skip a', 'skip:_', 'skip, skip']:
for badoption in ['ss']:
self.assertRaises(ParsingError, SoS_Script,
'[0:{}]'.format(badoption))
# allowed names
Expand All @@ -193,8 +170,6 @@ def testSections(self):
SoS_Script('''[a_1]\n[a_3]\n[b*_1]''')
#
# global section
self.assertRaises(ParsingError, SoS_Script,
'''[global: skip]''')
self.assertRaises(ParsingError, SoS_Script,
'''[global, step_10]''')

Expand Down
2 changes: 1 addition & 1 deletion test/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ def testAccessedVars(self):
self.assertEqual(accessed_vars('''a = "C" + f"{D}"'''), {'a', 'D'})
self.assertEqual(accessed_vars(
'''a = 1 + f"{D + 20:f}" '''), {'a', 'D'})
self.assertEqual(accessed_vars('''k, "a.txt", "b.txt", skip=True, par=f(something) '''), {
self.assertEqual(accessed_vars('''k, "a.txt", "b.txt", par=f(something) '''), {
'k', 'f', 'something', '__NULLFUNC__'})
# this is a complicated case because the actual variable depends on the
# result of an expression... However, in the NO-evaluation case, this is
Expand Down

0 comments on commit 0cd7827

Please sign in to comment.