Onlive Soft > Make-A-Flake

Blog

Getting Started¶

To get started writing a Flake8 plugin you first need:

  • An idea for a plugin

  • An available package name on PyPI

  • One or more versions of Python installed

  • A text editor or IDE of some kind

  • An idea of what kind of plugin you want to build:

    • Formatter

    • Check

Once you’ve gathered these things, you can get started.

All plugins for Flake8 must be registered via entry points. In this section we cover:

  • How to register your plugin so Flake8 can find it

  • How to make Flake8 provide your check plugin with information (via command-line flags, function/class parameters, etc.)

  • How to make a formatter plugin

  • How to write your check plugin so that it works with Flake8 2.x and 3.x

Video

What are Nix flakes?

Flakes are self-contained units that have inputs (dependencies) and outputs (packages, deployment instructions, Nix functions for use in other flakes). You can think about them as Rust crates or Go modules but language-independent. Flakes have great reproducibility because they are only allowed to depend on their inputs and they pin the exact versions of said inputs in a lockfile.

If you’re already familiar with Nix, flakes are to Nix expressions what derivations are to build instructions.

Optional: nix-direnv .envrc

In order to hook into nix-direnv:

Then git add .envrc.

Before we do a full proper build, we need to populate the Cargo.lock! (Skip this if you have one!)

If you did not opt to use nix-direnv, now you need to call nix develop . to enter the full development shell.

At this point you can try out cargo build and other relevant commands. They should work and use the libraries and tools provided by Nix.

Go ahead and test a build:

Get trouble? Try running nix build --print-build-logs --keep-failed to be able to see logs and check the workdir.

Here’s it working:

So how does this do on other crates? I test these files to several other popular Rust packages, here’s what I needed to change for each:

ripgrep

I had to set mainProgram within the meta of default.nix:

bottom

I also had to set mainProgram to btm. I also had to set doCheck = true in default.nix, as the tests depended on floating environment variables the build didn’t have.

Tags