python

package
v0.0.0-...-d3da680 Latest Latest
Warning

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

Go to latest
Published: Dec 4, 2024 License: Apache-2.0 Imports: 16 Imported by: 9

Documentation

Overview

Package python includes generating python venv and parsing python command line arguments.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CPython3FromCIPD

func CPython3FromCIPD(version string) generators.Generator

func CPythonFromCIPD

func CPythonFromCIPD(version string) generators.Generator

func CPythonFromPath

func CPythonFromPath(dir, cipdName string) (generators.Generator, error)

func IsolateEnvironment

func IsolateEnvironment(e *environ.Env)

IsolateEnvironment mutates e to remove any environmental influence over the Python interpreter.

If e is nil, no operation will be performed.

func VirtualenvFromCIPD

func VirtualenvFromCIPD(version string) generators.Generator

Types

type CommandLine

type CommandLine struct {
	// Target is the Python target type.
	Target Target

	// Flags are flags to the Python interpreter.
	Flags []CommandLineFlag
	// FlagSeparator, if true, means that a "--" flag separator, which separates
	// the interpreter's flags from its positional arguments, was found.
	FlagSeparator bool
	// Args are arguments passed to the Python script.
	Args []string
}

CommandLine is a parsed Python command-line.

CommandLine can be parsed from arguments via ParseCommandLine.

func ParseCommandLine

func ParseCommandLine(args []string) (*CommandLine, error)

ParseCommandLine parses Python command-line arguments and returns a structured representation.

func (*CommandLine) AddFlag

func (cl *CommandLine) AddFlag(flag CommandLineFlag)

AddFlag adds an interpreter flag to cl if it's not already present.

func (*CommandLine) AddSingleFlag

func (cl *CommandLine) AddSingleFlag(flag string)

AddSingleFlag adds a single no-argument interpreter flag to cl if it's not already specified.

func (*CommandLine) BuildArgs

func (cl *CommandLine) BuildArgs() []string

BuildArgs returns an array of Python interpreter arguments for cl.

func (*CommandLine) Clone

func (cl *CommandLine) Clone() *CommandLine

Clone returns an independent deep copy of cl.

func (*CommandLine) RemoveAllFlag

func (cl *CommandLine) RemoveAllFlag(flag string) (found bool)

RemoveAllFlag removes all instances of the specified flag from the interpreter command line.

func (*CommandLine) RemoveFlag

func (cl *CommandLine) RemoveFlag(flag CommandLineFlag) (found bool)

RemoveFlag removes all instances of the specified flag from the interpreter command line.

func (*CommandLine) RemoveFlagMatch

func (cl *CommandLine) RemoveFlagMatch(matchFn func(CommandLineFlag) bool) (found bool)

RemoveFlagMatch removes all instances of flags that match the selection function.

matchFn is a function that accepts a candidate flag and returns true if it should be removed, false if it should not.

type CommandLineFlag

type CommandLineFlag struct {
	Flag string
	Arg  string
}

CommandLineFlag is a command-line flag and its associated argument, if one is provided.

func (*CommandLineFlag) String

func (f *CommandLineFlag) String() string

String returns a string representation of this flag, which is a command-line suitable representation of its value.

type CommandTarget

type CommandTarget struct {
	// Command is the command contents.
	Command string
}

CommandTarget is a Target implementation for a command-line string (-c ...).

type Environment

type Environment struct {
	Executable string
	CPython    generators.Generator
	Virtualenv generators.Generator
}

func (*Environment) Pep425Tags

func (e *Environment) Pep425Tags() generators.Generator

func (*Environment) WithWheels

func (e *Environment) WithWheels(wheels generators.Generator) generators.Generator

type Interpreter

type Interpreter struct {
	// Python is the path to the system Python interpreter.
	Python string
}

Interpreter represents a system Python interpreter. It exposes the ability to use common functionality of that interpreter.

func (*Interpreter) Normalize

func (i *Interpreter) Normalize() error

Normalize normalizes the Interpreter configuration by resolving relative paths into absolute paths.

type ModuleTarget

type ModuleTarget struct {
	// Module is the name of the target module.
	Module string
}

ModuleTarget is a Target implementing indicating a Python module (-m ...).

type NoTarget

type NoTarget struct{}

NoTarget is a Target implementation indicating no Python target (i.e., interactive).

type ScriptTarget

type ScriptTarget struct {
	// Path is the path to the script that is being invoked.
	//
	// This may be "-", indicating that the script is being read from STDIN.
	Path string
	// FollowsSeparator is true if the script argument follows the flag separator.
	FollowsSeparator bool
}

ScriptTarget is a Python executable script target.

type Target

type Target interface {
	// contains filtered or unexported methods
}

Target describes a Python invocation target.

Targets are identified by parsing a Python command-line using ParseCommandLine.

A Target is identified through type assertion, and will be one of:

  • NoTarget
  • ScriptTarget
  • CommandTarget
  • ModuleTarget

Jump to

Keyboard shortcuts

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