Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
IPython cell magic to check for PEP8 using https://pypi.python.org/pypi/pep8
# IPython magic to check for PEP8 compliance.
# Author: Juan Luis Cano <juanlu001@gmail.com>
"""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')
@Juanlu001

This comment has been minimized.

Copy link
Owner Author

Juanlu001 commented Feb 18, 2014

To test it:

%load_ext pep8magic

And then:

%%pep8

print("This code passes!")
@wonbyte

This comment has been minimized.

Copy link

wonbyte commented Mar 29, 2015

Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.