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

--clear-output flag is broken #822

Closed
spencermathews opened this issue May 29, 2018 · 5 comments · Fixed by #1312
Closed

--clear-output flag is broken #822

spencermathews opened this issue May 29, 2018 · 5 comments · Fixed by #1312
Labels
Milestone

Comments

@spencermathews
Copy link

spencermathews commented May 29, 2018

I appreciate the --clear-output convenience flag introduced in #619. However, unless I'm missing something it simply does not work.

These commands should both remove output, but the second does not:

jupyter nbconvert --ClearOutputPreprocessor.enabled=True --inplace example.ipynb
jupyter nbconvert --clear-output example.ipynb

The first form includes the following output (using the --debug option):

[NbConvertApp] Applying preprocessor: TagRemovePreprocessor
[NbConvertApp] Applying preprocessor: ClearOutputPreprocessor
[NbConvertApp] Applying preprocessor: coalesce_streams

However, the ClearOutputProcessor line is missing when using --clear-output.

See this StackOverflow answer for another user who observed the same issue.

Using Anaconda Python 3.6.5 + Jupyter 4.4.0

@t-makaro
Copy link
Contributor

I can confirm that --clear-output is broken, but I can't for the life of me figure out why....

@rawlins
Copy link

rawlins commented Nov 27, 2018

I have tracked down (at some level) the why, but this is bound up in deep traitlets behavior that I cannot figure out at all, so I'm not sure what the fix is. In traitlets.config.Application.flatten_flags, which is called on flags, various processing happens. One of the things that this function apparently does, is replace all class names of classes that have a single subclass with the name of that subclass. Since ClearOutputProcessor has only one subclass, namely TagRemoveProcessor, ever since that subclass was added, the clear-output flag gets changed from:

{'NbConvertApp': {'use_output_suffix': False, 'export_format': 'notebook'}, 'ExecutePreprocessor': {'enabled': False}, 'FilesWriter': {'build_directory': ''}, 'ClearOutputPreprocessor': {'enabled': True}}

into

{'NbConvertApp': {'use_output_suffix': False, 'export_format': 'notebook'}, 'ExecutePreprocessor': {'enabled': False}, 'FilesWriter': {'build_directory': ''}, 'TagRemovePreprocessor': {'enabled': True}}

This is the crucial traitlets code:

            newflag = {}
            for cls, subdict in flagdict.items():
                children = mro_tree[cls]
                # exactly one descendent, promote flag section
                if len(children) == 1:
                    cls = children[0]

                if cls in newflag:
                    newflag[cls].update(subdict)
                else:
                    newflag[cls] = subdict

I have no clue what this traitlets code is even trying to do, though it really doesn't work as expected for this case. The best workaround I can think of for this specific case would be to not make TagRemovePreprocessor inherit from ClearOutputPreprocessor since it looks like that's mainly done for conceptual reasons; they really only share remove_metadata_fields; or to make them both inherit from an abstract class.

This does seem to be acknowledged as a problem in traitlets in ipython/traitlets@c577973 ("The whole flatten_flags method seems like a very awkward workaround to make one priority ordering more important than another. It only 'flattens' one level of inheritance, and it ignores that parent classes may be instantiated.").

rawlins added a commit to rawlins/lambda-notebook that referenced this issue Nov 27, 2018
The `--clear-output` flag has been broken for a while, replace it with a
the still-working direct configuration (see
jupyter/nbconvert#822).

Also, update all notebooks with cleared versions.
IAlibay pushed a commit to bigginlab/OxCompBio that referenced this issue Nov 21, 2019
* cleanup 00

* 01 cleanup

* 02 cleanup

* 03 cleanup

* 04 cleanup

* 05 cleanup

* 06 cleanup

* cleanup

* cleanup script for notebooks

* working cleanup script

jupyter/nbconvert#822

* clean all output

* f-string suggestion
@TitouanT
Copy link

TitouanT commented Feb 7, 2020

Any updates on this ? It is still broken on version 5.6.1 of nbconvert

@MSeal
Copy link
Contributor

MSeal commented Feb 16, 2020

I will add it to the 6.0 release milestone to double check it's fixed. One of the larger dependency changes needed got done last week so 6.0 can move forward again.

@lindhe
Copy link

lindhe commented Jan 4, 2021

I think I'm running nbconvert 6.0.7, yet it seems to not work for me...

Any chance that jupyter notebook can run with another version than what jupyter nbconvert --version shows me? How do I check that?

$ jupyter nbconvert --version       
nbconvert        : 6.0.7

EDIT: I tried again, and magically it worked. Let's assume I made a typo or something the first time. Or perhaps it only works if jupyter notebook is stopped first?

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

Successfully merging a pull request may close this issue.

6 participants