Documentation
¶
Index ¶
- Constants
- func ActivateVirtualEnv(environ []string, virtualEnvDir string) []string
- func Command(ctx context.Context, arg ...string) (*exec.Cmd, error)
- func CommandPath() (string, string, error)
- func InstallDependencies(ctx context.Context, cwd, venvDir string, ...) error
- func IsVirtualEnv(dir string) bool
- func Name(tc toolchain) string
- func NewVirtualEnvError(dir, fullPath string) error
- func VirtualEnvCommand(virtualEnvDir, name string, arg ...string) *exec.Cmd
- type Info
- type PythonOptions
- type PythonPackage
- type Toolchain
Constants ¶
const ( // TypeCheckerNone is the default typeChecker TypeCheckerNone typeChecker = iota // TypeCheckerMypy is the mypy typeChecker TypeCheckerMypy // TypeCheckerPyright is the pyright typeChecker TypeCheckerPyright )
const ( Pip toolchain = iota Poetry Uv )
Variables ¶
This section is empty.
Functions ¶
func ActivateVirtualEnv ¶
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 ¶
Command returns an *exec.Cmd for running `python`. Uses `ComandPath` internally to find the correct executable.
func CommandPath ¶
CommandPath finds the correct path and command for Python. If the `CODEINFRA_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 IsVirtualEnv ¶
IsVirtualEnv returns true if the specified directory contains a python binary.
func NewVirtualEnvError ¶
NewVirtualEnvError creates an error about the virtual environment with more info on how to resolve the issue.
Types ¶
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 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)
}
func ResolveToolchain ¶
func ResolveToolchain(options PythonOptions) (Toolchain, error)