Skip to main content

Invokes Python dev tools at once.

Project description

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
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.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

invokelint-0.20.0.tar.gz (29.3 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

invokelint-0.20.0-py3-none-any.whl (17.1 kB view details)

Uploaded Python 3

File details

Details for the file invokelint-0.20.0.tar.gz.

File metadata

  • Download URL: invokelint-0.20.0.tar.gz
  • Upload date:
  • Size: 29.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for invokelint-0.20.0.tar.gz
Algorithm Hash digest
SHA256 a26e1c186e28283b0bb697f2f7e99bdd2139512b3db1b326431126a39c856d8b
MD5 25eb8c0d8cc4e206b9c2a7a1af3612ba
BLAKE2b-256 348834b8fdc85ad5b3cd1cc7aa046e50f59f63abbc590437e3460709066b8363

See more details on using hashes here.

File details

Details for the file invokelint-0.20.0-py3-none-any.whl.

File metadata

  • Download URL: invokelint-0.20.0-py3-none-any.whl
  • Upload date:
  • Size: 17.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for invokelint-0.20.0-py3-none-any.whl
Algorithm Hash digest
SHA256 661087c997bf9eb82b636a3f33c229606e6e8665c7bb7f59300f19cb2b6a1fb5
MD5 63afcc0a70f717e9341b6531430adb2b
BLAKE2b-256 4412e252d923240f1bc3ef8d6ce1d525a85ae13f1f443d91bc6746e0f5ec6d3a

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page