Is there a python style checker that works on notebooks in google colab?
Asked Answered
N

2

8

Style checkers are a great tool when it comes to organizing your notebooks. I am working in google colab recently and noticed that I couldn't find anything online on a style checker in google colab.

In terms of Python style guide checkers, I found that using Spyder as an IDE one could use Pylint and in terms of Jupiter notebooks I found a post of a question where one suggested using pycodestyle as

!pip install pycodestyle pycodestyle_magic
%load_ext pycodestyle_magic

but this did not work and gave a long error message

   17 import copy
     18 import pycodestyle as pycodestyle_module
---> 19 from flake8.api import legacy as flake8_module
     20 from contextlib import redirect_stdout
     21 

ModuleNotFoundError: No module named 'flake8'

##Summary## So to summarize how can one import and use a style checker in google colab . Please may you also provide an example of the lines that you may have used in your notebook that worked?

Nimbus answered 2/6, 2020 at 14:45 Comment(0)
A
1

This DOES work in colab, but you have to manually install flake8 too:

!pip install pycodestyle pycodestyle_magic
!pip install flake8
%load_ext pycodestyle_magic

Then add %%pycodestyle at the top of any cell you want linted:

screenshot of pycodestyle linting working correctly in colab

Acceleration answered 8/11, 2020 at 21:35 Comment(2)
How could I run the linter for the entire notebook? This fix works for me, but I don't like to insert a magic in each cell.Treadmill
How I can config max-line-length for flake8?Beacon
L
-1

You can install flake8 for notebooks

!pip install flake8-nb
!flake8_nb example_notebook.ipynb

flake8-nb

Lashawn answered 9/1, 2021 at 10:37 Comment(1)
Where could one find the .ipynb in Google Colab? I think the OP referred specifically to Colab.Treadmill

© 2022 - 2024 — McMap. All rights reserved.