doctor

package
v0.19.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 24, 2026 License: Apache-2.0 Imports: 15 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrNoAutoFix = errors.New("no auto-fix available for this check")

ErrNoAutoFix is returned by Fix() for detect-only checks.

Functions

This section is empty.

Types

type Check

type Check interface {
	Name() string
	Group() Group
	Description() string
	Check(ctx *CheckContext) ([]Finding, error)
	Fix(ctx *CheckContext, findings []Finding) error
}

Check is the interface every doctor rule implements.

func AllChecks

func AllChecks() []Check

AllChecks returns all registered doctor checks in execution order. To add a new check: implement the Check interface and add it here.

type CheckContext

type CheckContext struct {
	ProjectDir     string
	ConfigFilename string                 // Config filename (e.g. "cog.yaml")
	Config         *config.Config         // Parsed cog.yaml (nil if parsing failed)
	ConfigFile     []byte                 // Raw cog.yaml bytes (available even if parsing failed)
	LoadResult     *config.LoadResult     // Non-nil if config loaded successfully
	LoadErr        error                  // Non-nil if config loading failed
	PythonFiles    map[string]*ParsedFile // Pre-parsed Python files keyed by relative path
	PythonPath     string                 // Path to python binary (empty if not found)
	// contains filtered or unexported fields
}

CheckContext provides checks with access to project state. Built once by the runner and passed to every check.

The ctx field deliberately stores a context.Context, which deviates from the usual Go guidance of passing contexts as the first argument to every function. It's kept unexported to discourage external callers from constructing a CheckContext directly — all production construction goes through buildCheckContext, which always populates ctx. Tests in this package set ctx explicitly via struct literals.

func (*CheckContext) Close

func (cc *CheckContext) Close()

Close releases resources held by the CheckContext — primarily the C-allocated tree-sitter parse trees cached in PythonFiles. Tree-sitter also releases memory via runtime finalizers, but calling Close() on each tree releases the backing buffer promptly, which matters if the doctor runner is reused from a long-lived process.

type CheckResult

type CheckResult struct {
	Check    Check
	Findings []Finding
	Fixed    bool  // True if --fix was passed and Fix() succeeded
	Err      error // Non-nil if the check itself errored
}

CheckResult holds the outcome of running a single check.

type ConfigDeprecatedFieldsCheck

type ConfigDeprecatedFieldsCheck struct{}

ConfigDeprecatedFieldsCheck detects deprecated fields in cog.yaml.

func (*ConfigDeprecatedFieldsCheck) Check

func (*ConfigDeprecatedFieldsCheck) Description

func (c *ConfigDeprecatedFieldsCheck) Description() string

func (*ConfigDeprecatedFieldsCheck) Fix

func (*ConfigDeprecatedFieldsCheck) Group

func (*ConfigDeprecatedFieldsCheck) Name

type ConfigParseCheck

type ConfigParseCheck struct{}

ConfigParseCheck verifies that cog.yaml exists and can be parsed as valid YAML.

func (*ConfigParseCheck) Check

func (c *ConfigParseCheck) Check(ctx *CheckContext) ([]Finding, error)

func (*ConfigParseCheck) Description

func (c *ConfigParseCheck) Description() string

func (*ConfigParseCheck) Fix

func (c *ConfigParseCheck) Fix(_ *CheckContext, _ []Finding) error

func (*ConfigParseCheck) Group

func (c *ConfigParseCheck) Group() Group

func (*ConfigParseCheck) Name

func (c *ConfigParseCheck) Name() string

type ConfigPredictRefCheck

type ConfigPredictRefCheck struct{}

ConfigPredictRefCheck verifies that the predict field in cog.yaml points to a file and class that actually exist.

func (*ConfigPredictRefCheck) Check

func (c *ConfigPredictRefCheck) Check(ctx *CheckContext) ([]Finding, error)

func (*ConfigPredictRefCheck) Description

func (c *ConfigPredictRefCheck) Description() string

func (*ConfigPredictRefCheck) Fix

func (*ConfigPredictRefCheck) Group

func (c *ConfigPredictRefCheck) Group() Group

func (*ConfigPredictRefCheck) Name

func (c *ConfigPredictRefCheck) Name() string

type ConfigSchemaCheck

type ConfigSchemaCheck struct{}

ConfigSchemaCheck validates cog.yaml against the configuration schema. Parse errors are handled by ConfigParseCheck; this check catches schema and validation errors (wrong types, invalid values, etc.).

func (*ConfigSchemaCheck) Check

func (c *ConfigSchemaCheck) Check(ctx *CheckContext) ([]Finding, error)

func (*ConfigSchemaCheck) Description

func (c *ConfigSchemaCheck) Description() string

func (*ConfigSchemaCheck) Fix

func (c *ConfigSchemaCheck) Fix(_ *CheckContext, _ []Finding) error

func (*ConfigSchemaCheck) Group

func (c *ConfigSchemaCheck) Group() Group

func (*ConfigSchemaCheck) Name

func (c *ConfigSchemaCheck) Name() string

type DeprecatedImportsCheck

type DeprecatedImportsCheck struct{}

DeprecatedImportsCheck detects imports that were removed or moved in recent cog versions.

func (*DeprecatedImportsCheck) Check

func (c *DeprecatedImportsCheck) Check(ctx *CheckContext) ([]Finding, error)

func (*DeprecatedImportsCheck) Description

func (c *DeprecatedImportsCheck) Description() string

func (*DeprecatedImportsCheck) Fix

func (c *DeprecatedImportsCheck) Fix(ctx *CheckContext, findings []Finding) error

func (*DeprecatedImportsCheck) Group

func (c *DeprecatedImportsCheck) Group() Group

func (*DeprecatedImportsCheck) Name

func (c *DeprecatedImportsCheck) Name() string

type DockerCheck

type DockerCheck struct{}

DockerCheck verifies that Docker is installed and the daemon is reachable.

func (*DockerCheck) Check

func (c *DockerCheck) Check(ctx *CheckContext) ([]Finding, error)

func (*DockerCheck) Description

func (c *DockerCheck) Description() string

func (*DockerCheck) Fix

func (c *DockerCheck) Fix(_ *CheckContext, _ []Finding) error

func (*DockerCheck) Group

func (c *DockerCheck) Group() Group

func (*DockerCheck) Name

func (c *DockerCheck) Name() string

type Finding

type Finding struct {
	Severity    Severity
	Message     string // What's wrong
	Remediation string // How to fix it
	File        string // Optional: file path where the issue was found
	Line        int    // Optional: line number (1-indexed, 0 means unknown)
}

Finding represents a single problem detected by a check.

type Group

type Group string

Group categorizes checks for display purposes.

const (
	GroupConfig      Group = "Config"
	GroupPython      Group = "Python"
	GroupEnvironment Group = "Environment"
)

type MissingTypeAnnotationsCheck

type MissingTypeAnnotationsCheck struct{}

MissingTypeAnnotationsCheck detects predict/train methods that are missing return type annotations.

func (*MissingTypeAnnotationsCheck) Check

func (*MissingTypeAnnotationsCheck) Description

func (c *MissingTypeAnnotationsCheck) Description() string

func (*MissingTypeAnnotationsCheck) Fix

func (*MissingTypeAnnotationsCheck) Group

func (*MissingTypeAnnotationsCheck) Name

type ParsedFile

type ParsedFile struct {
	Path    string                // Relative path from project root
	Source  []byte                // Raw file contents
	Tree    *sitter.Tree          // Tree-sitter parse tree
	Imports *schema.ImportContext // Collected imports
}

ParsedFile holds tree-sitter parse results for a Python file.

type PydanticBaseModelCheck

type PydanticBaseModelCheck struct{}

PydanticBaseModelCheck detects output classes that inherit from pydantic.BaseModel with arbitrary_types_allowed=True instead of using cog.BaseModel.

func (*PydanticBaseModelCheck) Check

func (c *PydanticBaseModelCheck) Check(ctx *CheckContext) ([]Finding, error)

func (*PydanticBaseModelCheck) Description

func (c *PydanticBaseModelCheck) Description() string

func (*PydanticBaseModelCheck) Fix

func (c *PydanticBaseModelCheck) Fix(ctx *CheckContext, findings []Finding) error

func (*PydanticBaseModelCheck) Group

func (c *PydanticBaseModelCheck) Group() Group

func (*PydanticBaseModelCheck) Name

func (c *PydanticBaseModelCheck) Name() string

type PythonVersionCheck

type PythonVersionCheck struct{}

PythonVersionCheck verifies that Python is available and that the local version is consistent with the version configured in cog.yaml.

func (*PythonVersionCheck) Check

func (c *PythonVersionCheck) Check(ctx *CheckContext) ([]Finding, error)

func (*PythonVersionCheck) Description

func (c *PythonVersionCheck) Description() string

func (*PythonVersionCheck) Fix

func (c *PythonVersionCheck) Fix(_ *CheckContext, _ []Finding) error

func (*PythonVersionCheck) Group

func (c *PythonVersionCheck) Group() Group

func (*PythonVersionCheck) Name

func (c *PythonVersionCheck) Name() string

type Result

type Result struct {
	Results []CheckResult
}

Result holds the outcome of a full doctor run.

func Run

func Run(ctx context.Context, opts RunOptions, checks []Check) (*Result, error)

Run executes all checks and optionally applies fixes.

func (*Result) HasErrors

func (r *Result) HasErrors() bool

HasErrors returns true if any check produced error-severity findings or if any check itself errored.

func (*Result) HasFixableErrors

func (r *Result) HasFixableErrors() bool

HasFixableErrors returns true if any check produced unfixed error-severity findings AND the check supports auto-fix. This helps the CLI decide whether suggesting --fix would actually be useful.

type RunOptions

type RunOptions struct {
	Fix            bool
	ProjectDir     string
	ConfigFilename string // Config filename (defaults to "cog.yaml" if empty)
}

RunOptions configures a doctor run.

type Severity

type Severity int

Severity of a finding.

Values are ordered from most severe (Error = 0) to least severe (Info = 2), so a smaller integer means "worse". Callers that aggregate findings by severity compare with < rather than > to find the worst.

const (
	SeverityError   Severity = iota // Must fix -- will cause build/predict failures
	SeverityWarning                 // Should fix -- deprecated patterns, future breakage
	SeverityInfo                    // Informational -- suggestions, best practices
)

func (Severity) String

func (s Severity) String() string

String returns the human-readable name of the severity level.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL