python

package
v0.31.1 Latest Latest
Warning

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

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

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func IsTestFile

func IsTestFile(filePath string) bool

IsTestFile reports whether the given Python path is a test file.

func ResolvePythonAbsoluteImportPath

func ResolvePythonAbsoluteImportPath(absSourcePath, importPath string, suppliedFiles map[string]bool) []string

ResolvePythonAbsoluteImportPath resolves an absolute Python package import (e.g. "dexter.tools.finance.api") to matching project files.

A bare absolute import names a module reachable from a sys.path root, not from just anywhere in the tree a file with a matching tail happens to live. Suffix matching alone can't tell "the real top-level urllib3" apart from "requests/packages/urllib3", a same-named vendored copy several levels deep -- both end in "/urllib3/__init__.py". The directory that would need to be on sys.path for a candidate to be valid (suppliedPath with the matched suffix removed) is checked for its own __init__.py: a real sys.path entry is a directory of packages, never a package itself, so a candidate whose would-be root has one is rejected.

func ResolvePythonImportPath

func ResolvePythonImportPath(sourceFile, importPath string, suppliedFiles map[string]bool) []string

ResolvePythonImportPath resolves a Python import path to possible file paths.

A candidate matching sourceFile itself is never returned. This matters most for the bare-dots case (`from . import x` falling back to `.` when `x` isn't a real submodule, or a query scoped to fewer files than the whole project -- a single-file or single-commit `clarity show` -- simply doesn't have x's file in suppliedFiles even though it exists): resolving "." always means the enclosing package's own __init__.py, which is sourceFile itself whenever sourceFile IS that __init__.py. A file cannot depend on itself.

func ResolvePythonProjectImports

func ResolvePythonProjectImports(
	absPath string,
	filePath string,
	ext string,
	suppliedFiles map[string]bool,
	contentReader vcs.ContentReader,
) ([]string, error)

Types

type ExternalImport

type ExternalImport struct {
	// contains filtered or unexported fields
}

ExternalImport represents an external module import.

func (ExternalImport) FallbackPath added in v0.31.0

func (e ExternalImport) FallbackPath() string

func (ExternalImport) IsTypeOnly

func (e ExternalImport) IsTypeOnly() bool

func (ExternalImport) Path

func (e ExternalImport) Path() string

type InternalImport

type InternalImport struct {
	// contains filtered or unexported fields
}

InternalImport represents a relative module import.

func (InternalImport) FallbackPath added in v0.31.0

func (i InternalImport) FallbackPath() string

func (InternalImport) IsTypeOnly

func (i InternalImport) IsTypeOnly() bool

func (InternalImport) Path

func (i InternalImport) Path() string

type Provider added in v0.27.0

type Provider struct{}

func (Provider) Extensions added in v0.27.0

func (Provider) Extensions() []string

func (Provider) IsTestFile added in v0.27.0

func (Provider) IsTestFile(filePath string, _ vcs.ContentReader) bool

func (Provider) Maturity added in v0.27.0

func (Provider) Maturity() moduleapi.MaturityLevel

func (Provider) Name added in v0.27.0

func (Provider) Name() string

func (Provider) NewResolver added in v0.27.0

func (Provider) NewResolver(ctx *moduleapi.Context, contentReader vcs.ContentReader) moduleapi.Resolver

type PythonImport

type PythonImport interface {
	Path() string
	FallbackPath() string
	IsTypeOnly() bool
}

PythonImport represents an import in a Python file.

FallbackPath is the path to try when Path does not resolve to a real file. It is only non-empty for `from X import name` statements: name might be a submodule of X (Path: "X.name") or an attribute defined inside X's own file/package (FallbackPath: "X") -- only a file-existence check can tell them apart, and the parser doesn't have that information, so both candidates are threaded through to the resolver.

func ParsePythonImports

func ParsePythonImports(sourceCode []byte) ([]PythonImport, error)

ParsePythonImports parses Python source code and extracts imports.

func PythonImports

func PythonImports(filePath string) ([]PythonImport, error)

PythonImports parses a Python file and returns its imports.

Jump to

Keyboard shortcuts

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