-
Notifications
You must be signed in to change notification settings - Fork 394
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Python representation is pep8 when notebook cells are #154
- Loading branch information
Showing
21 changed files
with
157 additions
and
71 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
"""Determine how many blank lines should be inserted between two cells""" | ||
|
||
|
||
def cell_starts_with_function_or_class(lines): | ||
"""Is the first non-commented line of the cell either a function or a class?""" | ||
for line in lines: | ||
if line.startswith('#'): | ||
continue | ||
if line.startswith('def ') or line.startswith('class '): | ||
return True | ||
return False | ||
|
||
return False | ||
|
||
|
||
def cell_ends_with_function_or_class(lines): | ||
"""Does the last line of the cell belong to an indented code?""" | ||
if not lines: | ||
return False | ||
if not lines[-1].startswith(' '): | ||
return False | ||
if not lines[-1].strip(): | ||
return False | ||
|
||
# find the first line, starting from the bottom, that is not indented | ||
for line in lines[::-1]: | ||
if line.startswith('#') or line.startswith(' '): | ||
continue | ||
if line.startswith('def ') or line.startswith('class '): | ||
return True | ||
return False | ||
|
||
return False | ||
|
||
|
||
def pep8_lines_to_end_of_cell_marker(lines, ext): | ||
"""In case the cell has an end-of-cell marker, how many blank lines should be added to it?""" | ||
return 2 if ext == '.py' and cell_ends_with_function_or_class(lines) else 0 | ||
|
||
|
||
def pep8_lines_between_cells(prev_lines, next_lines, ext): | ||
"""How many blank lines should be added between the two python paragraphs to make them pep8?""" | ||
if not next_lines: | ||
return 1 | ||
if not prev_lines: | ||
return 0 | ||
if ext != '.py': | ||
return 1 | ||
if cell_ends_with_function_or_class(prev_lines): | ||
return 2 | ||
if cell_starts_with_function_or_class(next_lines): | ||
return 2 | ||
return 1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -67,4 +67,4 @@ | |
}, | ||
"nbformat": 4, | ||
"nbformat_minor": 2 | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.