Code Monkey home page Code Monkey logo

pycodestyle_magic's Introduction

PyPI version

pycodestyle_magic

Magic function for pycodestyle and flake8 module in Jupyter-Lab or Notebook

installation

Make sure you've the Python package pycodestyle, flake8 and this pycodestyle_magic.

pip install flake8 pycodestyle_magic

configuration

Flake8 and pycodestyle will discover and manage user configuration files (stored in a user's home directory or in the XDG directory inside their home directory) or project configuration files (stored in the current directory). See their respective docs for specific details on configuration file naming, syntax, and location.

Additionally, Flake8 cell magic ignores four codes by default:

  • W292 - no newline at end of file; not relevant in an iPython cell
  • W391 - blank line at end of file; not relevant in an iPython cell
  • F401 - module imported but unused; a module may be imported in one cell and used in another
  • F821 - undefined name name; a variable may be defined in one cell and used in another

usage

Enable the magic function by using the pycodestyle_magic module in a cell

%load_ext pycodestyle_magic

to check a cell once:

use the function as first line in your cell to check compliance with pycodestyle or flake8 as such:

%%pycodestyle

or for flake8

%%flake8

to auto check each cell (version >= 0.3):

If you want this compliance checking turned on by default for each cell then run this magic line function in an empty cell:

%pycodestyle_on

or for flake8

%flake8_on

You only need to call this once (observe the single %).

To turn off the auto-checking for each cell use:

%pycodestyle_off or %flake8_off

config options for %flake8_on (version >= 0.5)

  1. The option --ignore or -i will add the the named error(s) to the ignore list

Example to ignore the errors E225 and E265:

%flake8_on --ignore E225,E265

Remember to avoid spaces between declaring multiple errors.

  1. With the option --max_line_length or -m the max-line-length can be customised.

Example to set the line length to 119 characters instead of the default 79:

%flake8_on --max_line_length 119

The options can be combined as well.

See notebooks in notebook directory for example use cases, as such:

Pycodestyle (notebook)

alt text

Flake8 (notebook)

alt text

Examples notebooks were slightly adapted from https://github.com/SiggyF/notebooks/blob/master/styleguide.ipynb

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.