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

active-py mode strips leading # from comments #1131

Closed
kerrickstaley opened this issue Sep 28, 2023 · 1 comment · Fixed by #1159
Closed

active-py mode strips leading # from comments #1131

kerrickstaley opened this issue Sep 28, 2023 · 1 comment · Fixed by #1159

Comments

@kerrickstaley
Copy link

Summary

When I load a file that has a cell tagged with active-py and then save it, Jupytext strips the leading # on comments in the cell, making the cell no longer run correctly in the .py file.

To reproduce

  1. Save this as foo.py:
# ---
# jupyter:
#   jupytext:
#     text_representation:
#       extension: .py
#       format_name: percent
#       format_version: '1.3'
#       jupytext_version: 1.15.2
#   kernelspec:
#     display_name: Python 3 (ipykernel)
#     language: python
#     name: python3
# ---

# %%
print('hello')

# %% tags=["active-py"]
# Print goodbye
print('goodbye')
  1. Run jupyter notebook in the directory where you saved foo.py and open foo.py.
  2. Hit Ctrl+S or Cmd+S to save the file.

Expected behavior

The file foo.py is unchanged.

Actual behavior

The line

# Print goodbye

in foo.py changes to

Print goodbye

which makes the file no longer runnable (not valid Python code).

System info

macOS 13.3.1
Python 3.11.5
jupytext 1.15.2

Also repros on:
Rocky Linux 8.8
Python 3.8.17
jupytext 1.5.2

@mwouts
Copy link
Owner

mwouts commented Nov 12, 2023

I see! Thank you @kerrickstaley for reporting this. I will have a look.

mwouts added a commit that referenced this issue Nov 12, 2023
mwouts added a commit that referenced this issue Nov 23, 2023
mwouts added a commit that referenced this issue Nov 27, 2023
mwouts added a commit that referenced this issue Nov 27, 2023
mwouts added a commit that referenced this issue Nov 27, 2023
* Add a test to reproduce #1131
* Do not uncomment raw ipynb cells
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

Successfully merging a pull request may close this issue.

2 participants