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

Commit

Permalink
#57: Add support for inline subprocess compat mode
Browse files Browse the repository at this point in the history
  • Loading branch information
blackandred committed Nov 11, 2020
1 parent 30d7f78 commit 2682078
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 5 deletions.
2 changes: 1 addition & 1 deletion src/rkd/api/contract.py
Original file line number Diff line number Diff line change
Expand Up @@ -408,7 +408,7 @@ def py(self, code: str = '', become: str = None, capture: bool = False, script_p
)

def sh(self, cmd: str, capture: bool = False, verbose: bool = False, strict: bool = True,
env: dict = None) -> Union[str, None]:
env: dict = None, use_subprocess: bool = False) -> Union[str, None]:
"""Executes a shell script in bash. Throws exception on error.
To capture output set capture=True
Expand Down
4 changes: 2 additions & 2 deletions src/rkd/process.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ def __init__(self):
self.has_exited = False


def check_call(command: str, script_to_show: Optional[str] = ''):
def check_call(command: str, script_to_show: Optional[str] = '', use_subprocess: bool = False):
"""
Another implementation of subprocess.check_call(), in comparison - this method writes output directly to
sys.stdout and sys.stderr, which makes output capturing possible
Expand All @@ -69,7 +69,7 @@ def check_call(command: str, script_to_show: Optional[str] = ''):
:return:
"""

if os.getenv('RKD_COMPAT_SUBPROCESS') == 'true':
if os.getenv('RKD_COMPAT_SUBPROCESS') == 'true' or use_subprocess:
subprocess.check_call(command, shell=True)
return

Expand Down
5 changes: 3 additions & 2 deletions src/rkd/taskutil.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ def get_rkd_binary():
return sys.executable

def sh(self, cmd: str, capture: bool = False, verbose: bool = False, strict: bool = True,
env: dict = None) -> Union[str, None]:
env: dict = None, use_subprocess: bool = False) -> Union[str, None]:
""" Executes a shell script in bash. Throws exception on error.
To capture output set capture=True
"""
Expand Down Expand Up @@ -98,7 +98,8 @@ def sh(self, cmd: str, capture: bool = False, verbose: bool = False, strict: boo
bash_temp_file.flush()

check_call('bash ' + bash_temp_file.name,
script_to_show=original_cmd if not is_debug else bash_script)
script_to_show=original_cmd if not is_debug else bash_script,
use_subprocess=use_subprocess)

return

Expand Down

0 comments on commit 2682078

Please sign in to comment.