pycmdcheck

Python package quality checker inspired by R CMD check

Overview

pycmdcheck checks a Python package the way R CMD check checks an R package. One command looks at the metadata, layout, license, documentation, tests, code style and types of a project and reports where it falls short.

What It Does

  • Runs 20 built-in checks. pycmdcheck --list prints them.
  • Reads its settings from pyproject.toml, where each check can be turned off or configured. To check repositories you do not own, a profile on the command line is usually enough, and --config takes the settings from a file of your own when it is not.
  • Offers profiles, which are named sets of checks. The triage profile only reads files, so it works on a repository that has not been installed. The core profile runs the tests, the build and the code-quality tools next to the checks of the metadata, the layout and the license.
  • Starts external tools for linting, type checking and formatting. Each of these checks runs the tool the project has configured, which is ruff, flake8 or pylint for linting, mypy or pyright for type checking, and ruff or black for formatting. A project that has configured none is skipped for that check and is not held to a tool it never chose.
  • Accepts custom checks that other packages register through entry points.
  • Prints a table for the terminal, JSON for another program, or Markdown for a comment on a pull request.
  • Makes a suggestion for each finding of a built-in check, in one sentence that says what to do about it. Add --verbose to a run to print the suggestions.
  • Gives every finding a rule code, such as license.missing, and every skipped check a reason. Both are stable names that a program can compare, and pycmdcheck --list-rules prints the codes and a suggestion for each.

Quick Example

Command Line

# The checks that only read files
pycmdcheck --profile triage

# Every enabled check
pycmdcheck

# Two checks only (-c is short for --check)
pycmdcheck --check metadata,license

# List the installed checks
pycmdcheck --list

A run with no profile executes code from the project. It runs the tests, builds the package, starts the linter and the type checker the project has configured, and requests the project URLs over the network. To check a repository you did not write, use --profile triage and read Checking Untrusted Code first.

Python API

from pycmdcheck import check

report = check(".", profile="triage")

if report.passed:
    print("No check returned an error")
for result in report.results:
    print(f"{result.status}: {result.name} - {result.message}")

Installation

pycmdcheck needs Python 3.11 or later.

pip install pycmdcheck

With uv, add it as a development dependency.

uv add --dev pycmdcheck

Extras such as pycmdcheck[linting] install a tool that a check runs. Getting Started lists them.

Next Steps