Code Monkey home page Code Monkey logo

jupyterlab-flake8's Introduction

Jupyterlab-flake8

Jupyterlab extension to lint python notebooks and python files in the text editor. Uses flake8 python library for linting.

Note: This extension will only work if you can load the terminal in jupyterlab. The terminal does not currently work on Windows 7

Prerequisites

  • JupyterLab >= 0.33
$ conda install -c conda-forge jupyterlab
$ conda install flake8   # if using conda
$ pip install flake8     # if using pip

Installation

jupyter labextension install jupyterlab-flake8

Usage

When the extension is installed, the linter will automatically be toggled on and configured to show error messages. The linter will run when you change cells.

The linter will run on state change of the notebook or the text editor. State changes occur when the document is saved, the cell is changed, or on some carriage returns.

Options in the view menu (or command palette):

  • Enable Flake8
    • Turns on or off linting in the notebook
  • Show Error Messages
    • Shows Flake8 Error messages under the line in the notebook
  • Output Flake8 Browser Console Logs
    • Turn on browser console logs for debugging the extension

Configure

The notebook linter is configured the same way as the flake8 command line tool. See the flake8 project configuration documentation for all options.

As an example, if you want to ignore certain warnings:

  • Create .flake8 file in the same directory as the notebook
  • Specify a [flake8] block in a valid INI format
[flake8]
ignore = 
    F812,   # list comprehension redefines
    H101    # Use TODO(NAME)
exclude =
    .git,
    __pycache__,
    docs/source/conf.py,
    dist
max-complexity = 10

The flake8 linter will then use this configuration in the notebook.

TODO

Please help contribute if you have time and think this is useful. I will continue to improve as I have time:

  • show error messages on hover rather than in a new line
  • make lint frequency a configurable option

Development

It is advisable to use a seperate conda environment for development:

$ conda create -n jlflake8 anaconda

For a development install (requires npm version 4 or later), do the following in the repository directory:

$ npm install
$ npm run build
$ jupyter labextension install              # install and rebuild jupyterlab
$ jupyter labextension install --no-build   # install, but don't build (built during `jupyter lab --watch`)

To rebuild the package and the JupyterLab app:

$ npm run build
$ jupyter lab build

To run jupyter lab and thet typescript in watch mode:

$ jupyter lab --watch       # in the first terminal window
$ npm run watch             # in a new terminal window

Every time you add a dependency you much re-run npm run watch, then jupyter lab --watch

Acknowledgment

jupyterlab-flake8's People

Contributors

mlshapiro avatar

Watchers

James Cloos avatar

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.