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 --listprints 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--configtakes the settings from a file of your own when it is not. - Offers profiles, which are named sets of checks. The
triageprofile only reads files, so it works on a repository that has not been installed. Thecoreprofile 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
--verboseto 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, andpycmdcheck --list-rulesprints 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 --listA 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 pycmdcheckWith uv, add it as a development dependency.
uv add --dev pycmdcheckExtras such as pycmdcheck[linting] install a tool that a check runs. Getting Started lists them.
Next Steps
- Getting Started for installation and a first run
- Command-Line Reference for every option and the exit codes
- Configuration for the settings in
pyproject.toml - Rule Codes for the codes and skip reasons a program can read
- Checking Untrusted Code for reviewing a repository you did not write
- With an AI Assistant for the skill that has an assistant check and fix a package
- Custom Checks for writing your own checks
- API Reference for the Python API