checks.base.BaseCheck

checks.base.BaseCheck()

Abstract base class for implementing checks.

This is the recommended way to implement custom checks. Subclasses must override the name, description attributes and implement the run method.

Attributes

name : str

Unique identifier for the check. Override in subclass.

description : str

Human-readable description. Override in subclass.

Examples

Create a custom check:

>>> from pycmdcheck.checks.base import BaseCheck
>>> from pycmdcheck.results import CheckResult, CheckStatus
>>>
>>> class CopyrightCheck(BaseCheck):
...     name = "copyright"
...     description = "Check for copyright headers"
...
...     def run(self, package_path, config):
...         # Check logic here
...         return CheckResult(
...             name=self.name,
...             status=CheckStatus.OK,
...             message="All files have copyright headers",
...         )

Register via entry points in pyproject.toml:

[project.entry-points."pycmdcheck.checks"]
copyright = "my_package.checks:CopyrightCheck"

Methods

Name Description
run Execute the check and return result.

run

checks.base.BaseCheck.run(package_path, config)

Execute the check and return result.

Subclasses must implement this method to perform the actual check.

Parameters

package_path : Path

Path to the package directory to check. This is always an absolute, resolved path.

config : dict[str, Any]

Configuration dictionary for this check. Contains any options specified in pyproject.toml under [tool.pycmdcheck.checks.]. Common keys include “enabled” (bool) and check-specific options.

Returns

: CheckResult

A CheckResult with:

: CheckResult
  • name: Should match self.name
: CheckResult
  • status: One of CheckStatus values (OK, WARNING, ERROR, etc.)
: CheckResult
  • message: Brief description of the result
: CheckResult
  • details: Optional list of specific issues found

Examples

>>> def run(self, package_path, config):
...     issues = self._find_issues(package_path)
...     if issues:
...         return CheckResult(
...             name=self.name,
...             status=CheckStatus.WARNING,
...             message=f"Found {len(issues)} issues",
...             details=issues,
...         )
...     return CheckResult(
...         name=self.name,
...         status=CheckStatus.OK,
...         message="No issues found",
...     )