Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(runner): add skip_if_no_inputs to workflows #482

Merged
merged 1 commit into from
Nov 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
41 changes: 24 additions & 17 deletions secator/runners/command.py
Original file line number Diff line number Diff line change
Expand Up @@ -124,9 +124,12 @@ def __init__(self, inputs=[], **run_opts):
caller = run_opts.get('caller', None)
results = run_opts.pop('results', [])
context = run_opts.pop('context', {})
self.skip_if_no_inputs = run_opts.pop('skip_if_no_inputs', False)

# Prepare validators
input_validators = [self._validate_input_nonempty]
input_validators = []
if not self.skip_if_no_inputs:
input_validators.append(self._validate_input_nonempty)
if not caller:
input_validators.append(self._validate_chunked_input)
validators = {'validate_input': input_validators}
Expand Down Expand Up @@ -176,22 +179,6 @@ def __init__(self, inputs=[], **run_opts):
item_loaders.append(instance_func)
self.item_loaders = item_loaders

# Print built cmd
if not self.has_children:
if self.sync:
if self.caller and self.description:
self._print(f'\n:wrench: {self.description} ...', color='bold gold3', rich=True)
elif self.print_cmd:
self._print('')
if self.print_cmd:
cmd_str = self.cmd.replace('[', '\\[')
if self.sync and self.chunk and self.chunk_count:
cmd_str += f' [dim gray11]({self.chunk}/{self.chunk_count})[/]'
self._print(cmd_str, color='bold cyan', rich=True)

# Debug
self.debug('Command', obj={'cmd': self.cmd}, sub='init')

def toDict(self):
res = super().toDict()
res.update({
Expand Down Expand Up @@ -347,6 +334,8 @@ def yielder(self):
if self.has_children:
return

self.print_description()

# Yield targets
for input in self.inputs:
yield Target(name=input, _source=self.unique_name, _uuid=str(uuid.uuid4()))
Expand Down Expand Up @@ -379,6 +368,7 @@ def yielder(self):
shell=self.shell,
env=env,
cwd=self.cwd)
self.print_command()

# If sudo password is provided, send it to stdin
if sudo_password:
Expand Down Expand Up @@ -447,6 +437,23 @@ def process_line(self, line):
yield from self.stats()
self.last_updated_stat = time()

def print_description(self):
"""Print description"""
if self.sync and not self.has_children:
if self.caller and self.description:
self._print(f'\n[bold gold3]:wrench: {self.description} [dim cyan]({self.config.name})[/][/] ...', rich=True)
elif self.print_cmd:
self._print('')

def print_command(self):
"""Print command."""
if self.print_cmd:
cmd_str = self.cmd.replace('[', '\\[')
if self.sync and self.chunk and self.chunk_count:
cmd_str += f' [dim gray11]({self.chunk}/{self.chunk_count})[/]'
self._print(cmd_str, color='bold cyan', rich=True)
self.debug('Command', obj={'cmd': self.cmd}, sub='init')

def handle_file_not_found(self, exc):
"""Handle case where binary is not found.

Expand Down
1 change: 1 addition & 0 deletions secator/runners/workflow.py
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,7 @@ def get_tasks(self, config, inputs, workflow_opts, run_opts):
opts['context'] = self.context.copy()
opts['name'] = task_name
opts['has_parent'] = True
opts['skip_if_no_inputs'] = True

# Create task signature
task_id = str(uuid.uuid4())
Expand Down
Loading