Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Codefold preprocessor improvements #1054

Merged
merged 9 commits into from
Aug 31, 2017

Conversation

gabyx
Copy link
Contributor

@gabyx gabyx commented Aug 20, 2017

This improvements make the preprocessor much more stable:
There were several bugs, such that outer levels did not get collapsed when exporting.
Now the coldfolding during export is closer to the experience in the notebook (if not totally the same)
Input:
Notebook
Output:
HTML

@gabyx
Copy link
Contributor Author

gabyx commented Aug 21, 2017

The state of the art coldfolding produces wrong results:
Input
bildschirmfoto 2017-08-21 um 23 39 10
Output:
bildschirmfoto 2017-08-21 um 23 39 15

@juhasch
Copy link
Member

juhasch commented Aug 22, 2017

Thanks. I will take a look at it.

Copy link
Member

@jcb91 jcb91 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Mainly a reasonable plan, but the tests are currently failing on zero-length lines (see comments). Could you also address the linting errors - see https://travis-ci.org/ipython-contrib/jupyter_contrib_nbextensions/jobs/266962119#L762-L773

if indent <= fold_indent:
lstrip = l.lstrip(r' \t') # strip tabs and spaces
indent = len(l) - len(lstrip)
isSkipLine = lstrip[0] == "#" or lstrip in ["\n"] # is it a comment or an empty line
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the lstrip[0] in this line is causing tests to fail. It should be something more like

# skip comments and empty lines, except at the end of the fold
# in which case they'll be replaced when the fold finishes
is_skip_line = lstrip.startswith('#') or lstrip == '\n'

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sure :-), will take a look at the mistakes =)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

by the way, how do you reproduce the linter errors locally?
I am using atom, but flake8 is giving me not the same errors? Do you have a solution for this or you just look at travis?

@@ -32,26 +32,52 @@ def fold_cell(self, cell, folded):
"""
Remove folded lines and add a '<->' at the parent line
"""
# self.log.debug("CodeFoldingPreprocessor:: folding at: %s" % folded)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think debug logs can (should) stay in, since the default log level is info...

lines = cell.splitlines(True)

if folded[0] == 0 and (lines[0][0] == '#' or lines[0][0] == '%'):
# fold whole cell when first line is a comment or magic
# self.log.debug("fold whole cell")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ditto above, we can keep this at debug level

@jcb91
Copy link
Member

jcb91 commented Aug 23, 2017

So the output on Travis comes from flake8, run by tox. I just run flake8 locally in a terminal, and that's enough, but I guess it's possible that the atom version isn't looking for config in the same places as my standalone setup? Not sure at the moment sorry...

@gabyx
Copy link
Contributor Author

gabyx commented Aug 23, 2017

Ah now I got the errors with atom, was on the wrong branch shit :-)

Ehm -> Can line ending be '\r\n' like on Windows? in python notebooks?
Hm... so we should probably make that robust for this too

@gabyx
Copy link
Contributor Author

gabyx commented Aug 23, 2017

Hm, it seems its alway '\n' which is good

@jcb91
Copy link
Member

jcb91 commented Aug 23, 2017

Can line ending be '\r\n' like on Windows? in python notebooks?

I think notebook cells are stored as an array of lines, which makes them ending-agnostic, although the file itself can presumably have carriage returns... always best to assume the most difficult 😉

@gabyx
Copy link
Contributor Author

gabyx commented Aug 23, 2017

I checked on a notebook from windows and it seems its always '\n'. Having a json file which is not lineendings-agnostic would be a design mistake =), so notebook went the right path here I think :)
Lineendings ar a pain in the a** why bother then in the first place ;-)

@gabyx
Copy link
Contributor Author

gabyx commented Aug 30, 2017

Could we merge these changes =)? Thanks :-)

@jcb91
Copy link
Member

jcb91 commented Aug 30, 2017

Staring at https://travis-ci.org/ipython-contrib/jupyter_contrib_nbextensions/jobs/267700939#L762, there are still a bunch of linting errors?

@jcb91
Copy link
Member

jcb91 commented Aug 30, 2017

*starting

@gabyx
Copy link
Contributor Author

gabyx commented Aug 31, 2017 via email

@jcb91
Copy link
Member

jcb91 commented Aug 31, 2017

Ok, seems good to me, thanks @gabyx!

@jcb91 jcb91 merged commit 646fa6e into ipython-contrib:master Aug 31, 2017
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants