Last active
April 27, 2017 11:00
-
-
Save astrojuanlu/9082229 to your computer and use it in GitHub Desktop.
IPython cell magic to check for PEP8 using https://pypi.python.org/pypi/pep8
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
# IPython magic to check for PEP8 compliance. | |
# Author: Juan Luis Cano <[email protected]> | |
"""IPython magic to check for PEP8 compliance. | |
To use it, type | |
```%load_ext pep8magic``` | |
and then | |
```%%pep8 | |
if 6*9==42:print("Something fundamentally wrong..." ) | |
``` | |
to see PEP8 failures. | |
""" | |
import pep8 as _pep8 | |
def pep8(line, cell): | |
lines = cell.splitlines(True) | |
lines[-1] += '\n' | |
fchecker = _pep8.Checker(lines=lines, | |
show_source=True) | |
report = fchecker.check_all() | |
if report == 0: | |
print("This code is PEP8-compliant!") | |
def load_ipython_extension(ipython): | |
ipython.register_magic_function(pep8, magic_kind='cell') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
To test it:
And then: