githubEdit

Back-end Code Quality Tools

  • Status: Active

  • Last Modified: 2023-07-07

  • Related Issue: #101arrow-up-right

  • Deciders: Aaron, Daphne, Sammy, Gina, Lucas, Billy

  • Tags: ADR

Context and Problem Statement

Back-end code quality tools should facilitate and efficiently enforce linting, auto-formatting, type-checking and security concerns. They should be easily configurable to suit our specific use-cases, uniformly applying conventions while alleviating the need for individual intervention.

Decision Drivers

  • Ease of use and configurability: Code quality tools should be configurable to meet the specific needs of our project and enforce standards uniformly. Running the tool should be simple, and feedback should be easily implementable and understandable.

  • Speed: Code quality tools should be able to run in an timely manner, ideally in a pre-commit hook.

  • Documentation and resources: Code quality tools should have robust and helpful documentation, specifically around usage and configuration.

  • Lean: Selection of code quality tools should cover all use-cases with little overlap for ease of use and to minimize mental surface area required to understand the system. As in, each tool should have a specific, meaningful purpose.

  • Enforces security: Tooling should assist us in identifying security concerns and vulnerabilities.

  • Well-maintained: We have a preference towards libraries that are widely adopted and have active maintainers.

Options Considered

  1. Use a curated collection of Python libraries from Flask template repository (described below)

  2. Use a different or modified set of Python libraries

Dependency Management

Poetryarrow-up-right: Python packaging and dependency management.

Code Linting

Ruffarrow-up-right: An extremely fast Python linter, written in Rust. Preferred for its speed and growing community adoption.

Auto-formatting

Blackarrow-up-right: Format Python code. Compatible with Ruffarrow-up-right out of the box, however, Ruff may replace the need for Black at some point. See this issuearrow-up-right.

Type Checking

Mypyarrow-up-right: Validate and enforce static type checking in Python.

Security

Safetyarrow-up-right: Safety first! Safety scans dependencies for vulnerabilities and security concerns.

License Checking

pip-licensesarrow-up-right: CLI tool for checking the software license of installed Python packages with pip.

Interface

Makearrow-up-right: Run scripts, linters and formatters.

Decision Outcome

Option #2 is preferred. We would like to use Ruff for linting and add some additional libraries for security and license checks.

We will be using the Flask template repository for initial project set up, which already relies on Flake8 and several additional extensions (bugbear, alfred, bandit) that would be redundant with Ruff. Some extra work will need to be done to migrate away from Flake8 and to Ruff without any regression. Recommend using flake8-to-ruffarrow-up-right to convert existing configuration.

There are some additional packages that we desire to use that are not included in the Flask template: safety & pip-licenses.

As we iterate on the tools that work for us, we would like to investigate a possible switch to Pyright in the future as well.

Other Options

Adopting Toxarrow-up-right as a testing / linting manager with some of the libraries.

Dependency Management: Pipenvarrow-up-right

Code Linting: Flake8arrow-up-right: Much slower than Ruff. Requires additional extentions like bugbeararrow-up-right that are built into Ruff. Pylintarrow-up-right

Auto-formatting: autopep8arrow-up-right

Type Checking: Pyrightarrow-up-right: Comparison of MyPy and Pyrightarrow-up-right. Language service through Pylance. Pyrearrow-up-right

Security: Banditarrow-up-right: Security checking tool used to identify common concerns in Python code. Redundant because Ruff implements flake8-bandit. dependency-checkarrow-up-right

License Checking: licensecheckarrow-up-right

Interface: Bash, Poetry

Last updated

Was this helpful?