Skip to content

Commit

Permalink
Do not display the output of a command in pipe mode
Browse files Browse the repository at this point in the history
  • Loading branch information
mwouts committed Mar 17, 2020
1 parent 75449a5 commit 2a96dfa
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 5 deletions.
5 changes: 4 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,10 @@
------------------

**Added**
- Script of script (SoS) notebooks are now supported. Thanks to Thomas Pernet-coudrier for contributing the sample notebook (#453).
- Script of script (SoS) notebooks are now supported. Thanks to Thomas Pernet-coudrier for contributing the sample notebook (#453).

**Fixed**
- When using `jupytext --pipe cmd`, the output of `cmd` should not appear in the terminal (#432)


1.4.0 (2020-03-09)
Expand Down
8 changes: 4 additions & 4 deletions jupytext/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -621,15 +621,15 @@ def load_paired_notebook(notebook, fmt, nb_file, log):
return notebook, latest_inputs, latest_outputs


def exec_command(command, input=None):
def exec_command(command, input=None, capture=False):
"""Execute the desired command, and pipe the given input into it"""
if not isinstance(command, list):
command = command.split(' ')
sys.stdout.write("[jupytext] Executing {}\n".format(' '.join(command)))
process = subprocess.Popen(command,
**(dict(stdout=subprocess.PIPE, stdin=subprocess.PIPE) if input is not None else {}))
out, err = process.communicate(input=input)
if out:
if out and not capture:
sys.stdout.write(out.decode('utf-8'))
if err:
sys.stderr.write(err.decode('utf-8'))
Expand Down Expand Up @@ -673,7 +673,7 @@ def pipe_notebook(notebook, command, fmt='py:percent', update=True, prefix=None)
tmp.write(text)
tmp.close()

exec_command([cmd if cmd != '{}' else tmp.name for cmd in command])
exec_command([cmd if cmd != '{}' else tmp.name for cmd in command], capture=update)

if not update:
return notebook
Expand All @@ -682,7 +682,7 @@ def pipe_notebook(notebook, command, fmt='py:percent', update=True, prefix=None)
finally:
os.remove(tmp.name)
else:
cmd_output = exec_command(command, text.encode('utf-8'))
cmd_output = exec_command(command, text.encode('utf-8'), capture=update)

if not update:
return notebook
Expand Down

0 comments on commit 2a96dfa

Please sign in to comment.