Skip to main content

Invoke Lint

Test CodeQL Code Coverage Maintainability Dependabot Python versions Twitter URL

Invokes Python dev tools at once.

Attention

  • The development status of this package is Beta now. It may not be able to keep backward compatibility. Be careful to use, especially for CI.
  • Currently, each commands require to run in project home directory.

Advantage

  1. Covers major development tools and they are optional to install
  2. Quick response for developer, slow but detail for CI
  3. Available to place commands into your selected namespace

1. Covers major development tools and they are optional to install

You can choose which dev tool you'll install, this package doesn't force to install each of dev tools. It helps you to avoid conflicts or breaking your project's dependencies.

Supporting tools:

Linters:

Formatters:

  • docformatter
  • Ruff
  • autoflake (If you want to use it instead of Ruff, style-legacy extra)
  • isort (If you want to use it instead of Ruff, style-legacy extra)
  • Black (If you want to use it instead of Ruff, style-legacy extra)

For test and coverage:

Package build:

2. Quick response for developer, slow but detailed for CI

The commands for each kind of tasks are designed as unified into 2 main commands:

  • For developer: Runs only quick responsive dev tools at once
  • For CI (or final check): Runs slow but detailed responsive tools at once

3. Available to place commands into your selected namespace

This doesn't pollute your comfortable namespaces of command line tools. Thanks to Invoke, you can place commands into your selected namespace. (See: Quickstart)

Representative commands

(Note that the namespaces of following commands can be changed as you like. See: Quickstart)

inv style

Formats code by following tools at once:

  1. docformatter
  2. Ruff format
  3. Ruff check --fix

Optionally, you can use autoflake, isort, and Black instead of Ruff format by inv style --no-ruff:

  1. docformatter
  2. autoflake
  3. isort
  4. Black
  5. Ruff check --fix
  • inv style --check can only check.
  • inv style --ruff can skip ruff check --fix.

inv lint

Runs following fast linters at once:

  1. Ruff
  2. Bandit
  3. dodgy
  4. Flake8

The format task (described later) also run before running above linters. You can skip them by --skip-format option. Use --xenon to enable Xenon (requires xenon extra), and --pydocstyle to enable pydocstyle (requires style-legacy extra).

inv lint.deep

Runs following slow but detailed linters at once:

  1. mypy
  2. Pylint
  3. Semgrep

inv lint.radon

Reports radon both code complexity and maintainability index. (Requires xenon extra)

inv test

Runs fast tests (which is not marked @pytest.mark.slow) by pytest.

See:

inv test.all

Runs all tests including those marked @pytest.mark.slow by pytest.

inv test.cov

Runs all tests and report those coverage by pytest and Coverage.py.

It also can dump the coverage as XML or HTML format.

inv dist

Builds source and wheel packages into dist/ directory by build.
(Currently, not support in Windows)

See:

Quickstart

1. Install

We should use uv or one of the dependency management tools to resolve dependencies of many dev tools.

invokelint publishes its supported tools as pip extras, so you can pull them in directly. For example, in case when we use uv, pyproject.toml is like below:

[dependency-groups]
dev = [
    "invokelint[basic]",
]

Available extras:

Extra Invoke task Tools
basic core tasks invokelint[lint,lint-deep,style,test,dist]
lint inv lint ruff, bandit, cohesion, dodgy, flake8 + plugins
lint-deep inv lint.deep mypy, pylint
semgrep inv lint.semgrep, inv lint.deep (runs semgrep only when installed) semgrep (not installed on Python 3.15 since semgrep-core crashes there)
style inv style docformatter, ruff
style-legacy inv style --no-ruff, inv lint --pydocstyle autoflake, isort, black, pydocstyle
test inv test / inv test.cov pytest, coverage
dist inv dist build
xenon inv lint --xenon, inv lint.radon xenon, radon, flake8-polyfill

then:

uv sync
source .venv/bin/activate

2. Implement

Create tasks.py in project directory:

"""Tasks for maintaining the project.

Execute 'invoke --list' for guidance on using Invoke
"""
from invoke import Collection

from invokelint import dist, lint, path, style, test

ns = Collection()
ns.add_collection(dist)
ns.add_collection(lint)
ns.add_collection(path)
ns.add_collection(style)
ns.add_collection(test)

Commands may be explicitly place with a different name than they were originally given via a name kwarg (or the 2nd regular arg):

ns.add_collection(lint, 'namespace-you-wish')

See: Constructing namespaces — Invoke documentation

3. Check installation

inv --list

4. Setup target package

This package reuses setuptools settings for package discovery for linting, formatting, and measuring coverage. You can check which package are discovered by setuptools and your project's settings, by following command:

$ inv path
Setuptools detected packages: ['invokelint', 'invokelint.path']
Root packages: ['invokelint']
Setuptools detected Python modules: ['setup', 'tasks']
Existing test packages: ['tests']
Python file or directories to lint: ['invokelint', 'setup.py', 'tasks.py', 'tests']
Python file or directories to lint excluding test packages: ['invokelint', 'setup.py', 'tasks.py']

If result is not your expected, follow official documentation of setuptools to configure pyproject.toml (recommended), setup.cfg, or setup.py.

See: Package Discovery and Namespace Packages - setuptools latest documentation

5. Set up CI/CD workflows

This package provides reusable GitHub Actions workflows. Create the following files in .github/workflows/:

.github/workflows/test.yml — runs tests and linters on push/PR to main:

name: Test
on:
  push:
    branches:
      - main
  pull_request:
    branches:
      - main
permissions:
  contents: read
jobs:
  call-workflow-test:
    uses: yukihiko-shinoda/reusable-workflow-invoke-lint-test/.github/workflows/workflow.yml@v1
    with:
      support-python-versions: "[ '3.14', '3.13', '3.12', '3.11', '3.10' ]"
  call-workflow-lint:
    uses: yukihiko-shinoda/reusable-workflow-invoke-lint-lint/.github/workflows/workflow.yml@v1

.github/workflows/qlty.yml — uploads coverage to Qlty on push to main:

on:
  push:
    branches:
      - main
# For OIDC token exchange with Qlty:
# - Configuring OpenID Connect in cloud providers - GitHub Docs
#   https://docs.github.com/en/actions/how-tos/secure-your-work/security-harden-deployments/oidc-in-cloud-providers#adding-permissions-settings
permissions:
  contents: read
  id-token: write
jobs:
  analyze:
    uses: yukihiko-shinoda/reusable-workflow-invoke-lint-qlty/.github/workflows/workflow.yml@v1
    permissions:
      contents: read
      id-token: write

.github/workflows/deploy.yml — publishes to PyPI on version tag push (v*.*.*):

on:
  push:
    tags:
      - 'v[0-9]+.[0-9]+.[0-9]+'
permissions:
  contents: read
jobs:
  call-workflow:
    uses: yukihiko-shinoda/reusable-workflow-invoke-lint-deploy/.github/workflows/workflow.yml@v1
    secrets:
      pypi_password: ${{ secrets.pypi_password }}

Check the respective repositories for the latest commit hashes if you want to use them for lock:

How do I...

Suppress B101: assert_used in Bandit and assert (S101) in Ruff only in test files?

Set below configuration in pyproject.toml:

[tool.bandit.assert_used]
skips = ["tests/*"]

[tool.ruff.lint.per-file-ignores]
"tests/*" = ["S101"]

Note that invoke-lint executes Bandit with option --configfile=pyproject.toml, so upper configuration will be applied.

See: Configuration — Bandit documentation

Credits

This package was created with Cookiecutter and the yukihiko-shinoda/cookiecutter-pypackage project template.

Metadata

Release files for invokelint 0.23.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for invokelint 0.23.0
File Size Uploaded Provenance Actions
invokelint-0.23.0.tar.gz 30.5 kB Without provenance Details for invokelint-0.23.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for invokelint 0.23.0
File Interpreter ABI Platform Actions
invokelint-0.23.0-py3-none-any.whl Python 3 none any Details for invokelint-0.23.0-py3-none-any.whl

Total release size: 48.2 kB

Release files / invokelint-0.23.0.tar.gz

Download URL invokelint-0.23.0.tar.gz
Size 30.5 kB
Tags Source
SHA-256 checksum
How to use checksums
ef04299aac45b88624503e91d685101f68a3ca69678b3cdcd140ec94e747944a
BLAKE2b-256 checksum
How to use checksums
84c44ff0d6f7169d6a1be95eea719331c09fdcaa69bf25560b733bc10307d9b8
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.16

Release files / invokelint-0.23.0-py3-none-any.whl

Download URL invokelint-0.23.0-py3-none-any.whl
Size 17.7 kB
Tags Python 3
SHA-256 checksum
How to use checksums
1d30219cd7f07a9fa8f0a9029812538ca559853df84b8bd7c5a01fa9644820a9
BLAKE2b-256 checksum
How to use checksums
5579c827df1f6c58f087a20dc9414c50f1453615210fcf5293f7e546e8e47429
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.16

Security for invokelint 0.23.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

0.23.0 This release

2 release files No provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page