kynan / nbstripout

strip output from Jupyter and IPython notebooks
Other
1.19k stars 94 forks source link

Doesn't strip out pycharm metadata #163

Closed SiddhantSadangi closed 2 years ago

SiddhantSadangi commented 2 years ago

PyCharm adds the below metadata to markdown cells whenever a notebook is opened in its renderer:

   "metadata": {
    "pycharm": {
     "name": "#%% md\n"
    }
   },

This is not stripped by nbstripout even when using the nbstripout --extra-keys "metadata.pycharm" or git config --system filter.nbstripout.extrakeys 'metadata.pycharm' options

kynan commented 2 years ago

I'm not a PyCharm user so I don't know how PyCharm interacts with Git. Are you using Git in PyCharm or on the command line?

SiddhantSadangi commented 2 years ago

PyCharm, but don't think that would make any difference as commands are sent to the command line anyway

kynan commented 2 years ago

It would make a difference if PyCharm appends this metadata after its interaction with Git, in which case there's nothing nbstripout could do. I'll try to reproduce this.

kynan commented 2 years ago

Turns out only PyCharm Professional supports notebooks in edit mode, so I can't reproduce this.

SiddhantSadangi commented 2 years ago

PyCharm appends this metadata as soon as a notebook is opened in edit mode. To reproduce, can you open a notebook as text and manually append this to it? Or I can attach a notebook with this appended

kynan commented 2 years ago

If you could attach a test case that would be really helpful.

SiddhantSadangi commented 2 years ago

Attaching three versions of the same notebook. The first is the original - clean with no metadata and output, second is after running in pycharm (you can see the pycharm metadata attributes added on openings the notebook in a text editor); third is after stripping out the output using nbstripout --extra-keys "metadata.pycharm" 3_output_stripped.ipynb.. the output has been stripped, but the pycharm tags haven't

notebooks.zip

kentavv commented 2 years ago

To remove the PyCharm tag, use the nbstripout argument --extra-keys="cell.metadata.pycharm". (Tested on @SiddhantSadangi 's notebooks.zip.)

SiddhantSadangi commented 2 years ago

@kentavv - thank you. Confirming that this works