Developer tools#

This guide explains the different types of tools that can help you develop and test your code.

This guide covers:#

General tools#

All of these are optional.
Many are very helpful, but they do take a little time to learn. The more time you spend coding, the greater the return-on-investment for using them. It’s a personal decision on whether the time saved by using these outweighs the time required to understand the tools.

Linting tools#

These check your code.

  • flake8 - checks various code style conventions, unused variables, line spacings, etc…

  • mypy

    • Static type checker: enforces proper usage of types.

    • Super useful once you get the hang of it, but definitely an intermediate-advanced tool.

    • Along with high test coverage, probably the best time-saver and project robustness tool.

Formatting tools#

These auto-modify your code.

  • black
    Forces code to follow specific style, indentations, etc…

  • autoflake
    Auto-fixes some flake8 failures.

  • isort
    Auto-sorts and formats your imports.

  • setup-cfg-fmt
    Sorts and enforces conventions in setup.cfg.

Pre-commit tools#

  • pre-commit, runs all your checks each time you run git commit, preventing bad code from ever getting checked in.

     $ pip install pre-commit
     # install the pre-commit "hook"  
     $ pre-commit install  
     # then configure in .pre-commit-config.yaml  
     # (optionally) Run hooks on demand  
     $ pre-commit run --all-files  
  • pre-commit-ci

    • Runs all your pre-commit hooks on CI (Continuous Integration).

    • Useful even if contributors don’t install and run your pre-commit hooks locally before they open a PR.

Napari plugin-specific tools#

  • Static plugin checks

    • This is a pre-commit hook. It is intended to be added to your .pre-commit-config.yaml file.

    • It statically (without importing) checks various best practices about your plugin:

    repo: https://github.com/tlambert03/napari-plugin-action  
    rev: v0.2.0  
    hooks: id: napari-plugin-checks  
  • Plugin check GitHub action (work in progress)

    • It is intended to be added to your GitHub workflow.

    • It (currently) checks that your plugin is installable, and performs a few sanity checks about Qt backends and dock widgets.

     uses: tlambert03/napari-plugin-action@main  
     with: package_name:  <your-package-name>  

The next topic in this series is the Survey/Q&A.

Other topics in this series:#