Skip to content

A Nova extension to lint your Python source code with Flake8, and format it with Black

License

Notifications You must be signed in to change notification settings

flother/Blake.novaextension

Repository files navigation

Blake: a Nova extension for linting your Python source code with Flake8, and formatting your code with Black.

Blake runs Flake8 when you save a Python file, and reports any warnings and errors in Nova's issues sidebar. You can also choose to format your code with Black every time you save, or just using the EditorFormat Source Code with Black menu item whenever you wish (shortcut: ⌘⇧B).

Prerequisites

Before using Blake you need to install Flake8 and Black. The recommended method is to use Homebrew and Pipx.

  1. Install Homebrew
  2. Install Pipx
  3. Install Flake8: pipx install flake8
  4. Install Black: pipx install black

If everything goes to plan, the flake8 and black CLIs will be available globally.

If you do use Pipx to install Flake8 you can later install your favourite Flake8 plugins by injecting them into the virtual environment. For example, to install the flake8-docstrings plugin: pipx inject flake8 flake8-docstrings. The extra warnings and violations provided by the plugin will be immediately and automatically available to both Blake and the flake8 CLI.

Installation

You can install Blake from Nova's online extension library, or you can install it from within Nova itself (select Extension Library... from the Extensions menu and search for "blake").

If you want to install a version for development, clone the GitHub repo, open the code in Nova, and select Activate Project as Extension from the Extensions menu. Any changes you make to the code will be reflected in the extension for the duration of your Nova session.

Preferences

By default Flake8 will be run using /usr/bin/env flake8, and Black using /usr/bin/env black. However you can configure this either for one particular project or for all Python projects within Nova.

  • To configure an individual project: select Project Settings... from the Project menu, and look for the Blake environment
  • To configure all Python projects: select Extension Library... from the Extensions menu, look for Blake under Installed Extensions in the sidebar, and click Settings

An individual project's settings will override the global preferences. Blake's preferences also allow you to:

  • Format your source files every time you save (off by default)
  • Set preferred maximum line length (default unset, meaning Black decides)
  • Use Black's preview style (off by default)

For further configuration, you can configure Flake8 and set your Black preferences using the standard config files.