Skip to content
This repository has been archived by the owner on Jan 14, 2024. It is now read-only.

Commit

Permalink
Add --no-ui switch and make RKD_DEPTH >=1 to turn on --no-ui (RKD_DEP…
Browse files Browse the repository at this point in the history
…TH >= 1 means RKD-in-RKD - a call to rkd in already executing rkd task)
  • Loading branch information
blackandred committed May 12, 2020
1 parent e96b215 commit 2963ad9
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 6 deletions.
2 changes: 1 addition & 1 deletion .rkd/makefile.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ tasks:
:examples:bash-test:
description: Execute an example command in bash - show only python related tasks
steps: |
echo "RKD_DEPTH: ${RKD_DEPTH} # >= 2 means we are running rkd-in-rkd"
echo "RKD_DEPTH: ${RKD_DEPTH} # >= 1 means we are running rkd-in-rkd"
echo "RKD_PATH: ${RKD_PATH}"
rkd --silent :tasks | grep ":py"
Expand Down
7 changes: 6 additions & 1 deletion src/rkd/executor.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,11 @@ def execute(self, declaration: TaskDeclaration, parent: Union[GroupDeclaration,
try:
io = IO()
io.set_log_level(parsed_args['log_level'] if parsed_args['log_level'] else self.io.get_log_level())
io.silent = parsed_args['silent'] if parsed_args['silent'] else self.io.silent # fallback to system-wide

if parsed_args['silent']:
io.silent = parsed_args['silent']
else:
io.inherit_silent(self.io) # fallback to system-wide

with io.capture_descriptors(target_file=parsed_args['log_to_file']):
task = declaration.get_task_to_execute()
Expand Down Expand Up @@ -68,6 +72,7 @@ def execute(self, declaration: TaskDeclaration, parent: Union[GroupDeclaration,
if not is_exception: # do not do double summary
self._observer.task_failed(declaration, parent)

# break the whole pipeline only if not --keep-going
if not parsed_args['keep_going']:
raise InterruptExecution()

Expand Down
23 changes: 20 additions & 3 deletions src/rkd/inputoutput.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,12 @@ def capture_descriptors(self, target_file: str = None, stream=None, enable_stand

this.IS_CAPTURING_DESCRIPTORS = False

def inherit_silent(self, io: 'SystemIO'):
self.silent = io.is_silent(consider_ui=False)

def is_silent(self) -> bool:
return self.silent

#
# Log level - mutable setting
#
Expand Down Expand Up @@ -134,13 +140,13 @@ def errln(self, text):
def opt_out(self, text):
""" Optional output - fancy output skipped in --silent mode """

if not self.silent:
if not self.is_silent():
self.out(text)

def opt_outln(self, text):
""" Optional output - fancy output skipped in --silent mode + newline """

if not self.silent:
if not self.is_silent():
self.outln(text)

#
Expand Down Expand Up @@ -168,7 +174,7 @@ def critical(self, text):
self.log(text)

def log(self, text):
if not self.silent:
if not self.is_silent():
self.outln(text)

def print_group(self, text):
Expand Down Expand Up @@ -204,9 +210,20 @@ def info_msg(self, text):
class SystemIO(IO):
""" Used for logging outside of tasks """

_ui = True

def capture_descriptors(self, target_file: str = None, stream=None, enable_standard_out: bool = True):
pass

def set_display_ui(self, ui: bool):
self._ui = ui

def is_silent(self, consider_ui: bool = True) -> bool:
if consider_ui and not self._ui:
return True

return self.silent


class NullSystemIO(SystemIO):
def _stdout(self, text):
Expand Down
13 changes: 12 additions & 1 deletion src/rkd/standardlib/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@

import pkg_resources
import os
from typing import Dict
from argparse import ArgumentParser
from typing import Callable
from ..contract import TaskInterface, ExecutionContext, TaskDeclarationInterface
Expand All @@ -20,8 +21,15 @@ def get_name(self) -> str:
def get_group_name(self) -> str:
return ''

def get_declared_envs(self) -> Dict[str, str]:
return {
'RKD_DEPTH': '0'
}

def configure_argparse(self, parser: ArgumentParser):
pass
parser.add_argument('--no-ui', '-n', action='store_true',
help='Do not display RKD interface (similar to --silent, ' +
'but does not inherit --silent into next tasks)')

def execute(self, context: ExecutionContext) -> bool:
"""
Expand All @@ -40,6 +48,9 @@ def execute(self, context: ExecutionContext) -> bool:
if context.args['log_level']:
self._ctx.io.set_log_level(context.args['log_level'])

if int(context.getenv('RKD_DEPTH')) >= 1 or context.args['no_ui']:
self._ctx.io.set_display_ui(False)

return True

def is_silent_in_observer(self) -> bool:
Expand Down

0 comments on commit 2963ad9

Please sign in to comment.