Skip to content

Commit

Permalink
Add Provided Targets section to help message of workflows #976
Browse files Browse the repository at this point in the history
  • Loading branch information
Bo Peng committed May 31, 2018
1 parent 6cf99be commit 52e7315
Showing 1 changed file with 24 additions and 3 deletions.
27 changes: 24 additions & 3 deletions src/sos/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
SOS_MAGIC, SOS_SECTION_HEADER, SOS_SECTION_NAME,
SOS_SECTION_OPTION, SOS_STRU, SOS_SUBWORKFLOW)
from .targets import file_target, path, paths, sos_targets, textMD5
from .utils import Error, env, locate_script, text_repr, format_par
from .utils import Error, env, locate_script, text_repr, format_par, short_repr

__all__ = ['SoS_Script']

Expand Down Expand Up @@ -560,6 +560,18 @@ def finalize(self) -> None:
# if otuput has options and rely on anything, it cannot be treated as
# auto output
pass
if 'provides' in self.options:
# let us check if provides is a "plain output"
try:
plain_output = eval(self.options['provides'])
if isinstance(plain_output, str) or \
(isinstance(plain_output, (list, tuple, set)) and
all(isinstance(x, str) for x in plain_output)):
self.options['autoprovides'] = self.options['provides']
except:
# if otuput has options and rely on anything, it cannot be treated as
# auto output
pass

def show(self):
'''Output for command sos show'''
Expand Down Expand Up @@ -1422,10 +1434,11 @@ def print_help(self, script_name: str):

if len(script_name) > 20:
print(f'usage: sos run {script_name}')
print(' [workflow_name] [options] [workflow_options]')
print(' [workflow_name | -t targets] [options] [workflow_options]')
else:
print(f'usage: sos run {script_name} [workflow_name] [options] [workflow_options]')
print(f'usage: sos run {script_name} [workflow_name | -t targets] [options] [workflow_options]')
print(' workflow_name: Single or combined workflows defined in this script')
print(' targets: One or more targets to generate')
print(' options: Single-hyphen sos parameters (see "sos run -h" for details)')
print(' workflow_options: Double-hyphen workflow-specific parameters')
description = [x.lstrip('# ').strip() for x in self.description]
Expand All @@ -1449,6 +1462,14 @@ def print_help(self, script_name: str):
width=textWidth,
initial_indent=' '*24,
subsequent_indent=' ' * 24)))
# targets
targets = []
for section in self.sections:
if 'autoprovides' in section.options:
targets.append(section.options['autoprovides'])
if targets:
print('\nProvided Targets')
print('\n'.join(' ' + x for x in list(dict.fromkeys(targets))))
print('\nSections')
for section in self.sections:
section.show()

0 comments on commit 52e7315

Please sign in to comment.