toolchain

package
v3.165.0 Latest Latest
Warning

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

Go to latest
Published: Apr 25, 2025 License: Apache-2.0 Imports: 19 Imported by: 3

Documentation

Index

Constants

View Source
const (
	// TypeCheckerNone is the default typeChecker
	TypeCheckerNone typeChecker = iota
	// TypeCheckerMypy is the mypy typeChecker
	TypeCheckerMypy
	// TypeCheckerPyright is the pyright typeChecker
	TypeCheckerPyright
)
View Source
const (
	Pip toolchain = iota
	Poetry
	Uv
)

Variables

This section is empty.

Functions

func ActivateVirtualEnv

func ActivateVirtualEnv(environ []string, virtualEnvDir string) []string

ActivateVirtualEnv takes an array of environment variables (same format as os.Environ()) and path to a virtual environment directory, and returns a new "activated" array with the virtual environment's "bin" dir ("Scripts" on Windows) prepended to the `PATH` environment variable, the `VIRTUAL_ENV` variable set to the path, and the `PYTHONHOME` variable removed.

func Command

func Command(ctx context.Context, arg ...string) (*exec.Cmd, error)

Command returns an *exec.Cmd for running `python`. Uses `ComandPath` internally to find the correct executable.

func CommandPath

func CommandPath() (string, string, error)

CommandPath finds the correct path and command for Python. If the `PULUMI_PYTHON_CMD` variable is set it will be looked for on `PATH`, otherwise, `python3` and `python` will be looked for.

func InstallDependencies

func InstallDependencies(ctx context.Context, cwd, venvDir string, useLanguageVersionTools, showOutput bool,
	infoWriter, errorWriter io.Writer,
) error

InstallDependencies will create a new virtual environment and install dependencies in the root directory.

func IsBuildablePackage added in v3.165.0

func IsBuildablePackage(dir string) (bool, error)

IsBuildablePackage checks if a directory is a buildable Python package. A directory is considered a buildable package if it contains a pyproject.toml file with a build-system section.

func IsVirtualEnv

func IsVirtualEnv(dir string) bool

IsVirtualEnv returns true if the specified directory contains a python binary.

func Name

func Name(tc toolchain) string

func NewVirtualEnvError

func NewVirtualEnvError(dir, fullPath string) error

NewVirtualEnvError creates an error about the virtual environment with more info on how to resolve the issue.

func VirtualEnvCommand

func VirtualEnvCommand(virtualEnvDir, name string, arg ...string) *exec.Cmd

VirtualEnvCommand returns an *exec.Cmd for running a command from the specified virtual environment directory.

Types

type BuildSystem added in v3.165.0

type BuildSystem struct {
	Requires     []string `toml:"requires,omitempty" json:"requires,omitempty"`
	BuildBackend string   `toml:"build-backend,omitempty" json:"build-backend,omitempty"`
}

type Info

type Info struct {
	Executable string
	Version    string
}

type Project added in v3.165.0

type Project struct {
	Name string `toml:"name" json:"name"`
}

type Pyproject added in v3.165.0

type Pyproject struct {
	Project     *Project       `toml:"project" json:"project"`
	BuildSystem *BuildSystem   `toml:"build-system,omitempty" json:"build-system,omitempty"`
	Tool        map[string]any `toml:"tool,omitempty" json:"tool,omitempty"`
}

func LoadPyproject added in v3.165.0

func LoadPyproject(dir string) (Pyproject, error)

type PythonOptions

type PythonOptions struct {
	// The root directory of the project.
	Root string
	// The program directory of the project.
	ProgramDir string
	// Virtual environment to use, relative to `Root`.
	Virtualenv string
	// Use a typechecker to type check.
	Typechecker typeChecker
	// The package manager to use for managing dependencies.
	Toolchain toolchain
}

type PythonPackage

type PythonPackage struct {
	Name     string `json:"name"`
	Version  string `json:"version"`
	Location string `json:"location"`
}

type Toolchain

type Toolchain interface {
	// InstallDependencies installs the dependencies of the project found in `cwd`.
	InstallDependencies(ctx context.Context, cwd string, useLanguageVersionTools,
		showOutput bool, infoWriter, errorWriter io.Writer) error
	// EnsureVenv validates virtual environment of the toolchain and creates it if it doesn't exist.
	EnsureVenv(ctx context.Context, cwd string, useLanguageVersionTools,
		showOutput bool, infoWriter, errorWriter io.Writer) error
	// ValidateVenv checks if the virtual environment of the toolchain is valid.
	ValidateVenv(ctx context.Context) error
	// ListPackages returns a list of Python packages installed in the toolchain.
	ListPackages(ctx context.Context, transitive bool) ([]PythonPackage, error)
	// Command returns an *exec.Cmd for running `python` using the configured toolchain.
	Command(ctx context.Context, args ...string) (*exec.Cmd, error)
	// ModuleCommand returns an *exec.Cmd for running an installed python module using the configured toolchain.
	// https://docs.python.org/3/using/cmdline.html#cmdoption-m
	ModuleCommand(ctx context.Context, module string, args ...string) (*exec.Cmd, error)
	// About returns information about the python executable of the toolchain.
	About(ctx context.Context) (Info, error)
	// VirtualEnvPath returns the path of the virtual env used by the toolchain.
	VirtualEnvPath(ctx context.Context) (string, error)
}

func ResolveToolchain

func ResolveToolchain(options PythonOptions) (Toolchain, error)

Jump to

Keyboard shortcuts

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