mwouts / jupytext

Jupyter Notebooks as Markdown Documents, Julia, Python or R scripts
https://jupytext.readthedocs.io
MIT License
6.65k stars 386 forks source link

Automatic code cell detection #1220

Closed ricopicone closed 6 months ago

ricopicone commented 8 months ago

When reading a Python script in percent format, I see no reason not to automatically detect a new code cell, without an explicit code demarcation. Consider the following example:

# %% [markdown]
# This is a Markdown cell.
# %% This is an explicit code cell
x = 3

# %% [markdown]
# Another Markdown cell
y = 4  # We could autodetect that this is a new code cell

This would be also be nicer in IDEs that support the percent format because there would be no need for the "extra" Markdown cells that are artifacts of the explicit Markdown cells:

image

Is there a reason not to do this? If this would be acceptable, I can try to make a PR.

ricopicone commented 8 months ago

I suppose the only reason not to do this is if people are writing Markdown cell contents that are uncommented. I see no reason why they would because it could not be run as Python code, which seems to defeat the purpose of writing it in a Python script to begin with. But perhaps I'm missing something?

mwouts commented 7 months ago

Hi @ricopicone , thank you for reaching out! I see your point.

Still, my expectations for the percent format is that it should be very explicit about the cell delimitations, so I would rather not change the current behavior.

There is another notebook format: py:light that is more implicit about the cell delimitations, would you like to give it a try?

ricopicone commented 6 months ago

Thanks @mwouts. No worries. Thanks again for your work on this great project.