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

Print output also to command line #1277

Open
HelgeGehring opened this issue Oct 25, 2024 · 2 comments
Open

Print output also to command line #1277

HelgeGehring opened this issue Oct 25, 2024 · 2 comments

Comments

@HelgeGehring
Copy link

HelgeGehring commented Oct 25, 2024

Would it be possible to also print the output of the script to the command line? I looked through the docs, but didn't find a solution yet.

I.e. when I run

jupytext script.py --to=ipynb --execute

that i also see the outputs as if I would have executed

python script.py

?

Thanks!

@mwouts
Copy link
Owner

mwouts commented Nov 1, 2024

Hey @HelgeGehring , yes that is possible but you should use the --log-output option of papermill.

For instance if I run

jupytext script.py --set-kernel - --to ipynb -o - | papermill output.ipynb --log-output

on this script:

# %%
from time import sleep


# %%
print("A")

# %%
sleep(2)

# %%
print("B")

# %%
sleep(2)

# %%
print("C")

then this is what gets displayed on the command line:

Input Notebook:  -
Output Notebook: output.ipynb
/home/marc/micromamba/envs/jupytext-dev/lib/python3.12/site-packages/papermill/iorw.py:149: UserWarning: the file is not specified with any extension : -
  warnings.warn(f"the file is not specified with any extension : {os.path.basename(path)}")
Executing notebook with kernel: python3
Executing Cell 1---------------------------------------
Ending Cell 1------------------------------------------
Executing Cell 2---------------------------------------
A

Ending Cell 2------------------------------------------
Executing Cell 3---------------------------------------
Ending Cell 3------------------------------------------
Executing Cell 4---------------------------------------
B

Ending Cell 4------------------------------------------
Executing Cell 5---------------------------------------
Ending Cell 5------------------------------------------
Executing Cell 6---------------------------------------
C

Ending Cell 6------------------------------------------

@HelgeGehring
Copy link
Author

sounds amazing, I'll give it a try, thanks a lot!!

would you have an idea how to also show the content of each cell? papermill doesn't have a "--log-input"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants