python

package
v0.0.0-...-678bb0e Latest Latest
Warning

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

Go to latest
Published: Aug 8, 2017 License: Apache-2.0 Imports: 16 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type CommandLine

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

	// Flags are flags to the Python interpreter.
	Flags []string
	// 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) (cmd CommandLine, err error)

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

type CommandTarget

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

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

type Interpreter

type Interpreter struct {
	// Python is the path to the system Python interpreter.
	Python string
	// contains filtered or unexported fields
}

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

func Find

func Find(c context.Context, vers Version, lookPath LookPathFunc) (*Interpreter, error)

Find attempts to find a Python interpreter matching the supplied version using PATH.

In order to accommodate multiple configurations on operating systems, Find will attempt to identify versions that appear on the path

func (*Interpreter) GetVersion

func (i *Interpreter) GetVersion(c context.Context) (v Version, err error)

GetVersion runs the specified Python interpreter with the "--version" flag and maps it to a known specification verison.

func (*Interpreter) Hash

func (i *Interpreter) Hash() (string, error)

Hash returns the SHA256 hash string of this interpreter.

The hash value is cached; if called multiple times, the cached value will be returned.

func (*Interpreter) IsolatedCommand

func (i *Interpreter) IsolatedCommand(c context.Context, args ...string) *exec.Cmd

IsolatedCommand returns a configurable exec.Cmd structure bound to this Interpreter.

The supplied arguments have several Python isolation flags prepended to them to remove environmental factors such as:

  • The user's "site.py".
  • The current PYTHONPATH environment variable.
  • Compiled ".pyc/.pyo" files.

func (*Interpreter) Normalize

func (i *Interpreter) Normalize() error

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

type LookPathFunc

type LookPathFunc func(c context.Context, target string) (*LookPathResult, error)

LookPathFunc attempts to find a file identified by "target", similar to exec.LookPath.

"target" will be the name of the program being looked up. It will NOT be a path, relative or absolute. It also should not include an extension where otherwise applicable (e.g., "python" instead of "python.exe"); the lookup function is responsible for trying known extensions as part of the lookup.

A nil LookPathFunc will use exec.LookPath.

type LookPathResult

type LookPathResult struct {
	// Path, if not zero, is the absolute path to the identified target
	// executable.
	Path string

	// Version, if not zero, is the Python version string. Standard "vpython"
	// wrapper identification may choose to call Python with "--version" to
	// identify it. If so, it may choose to populate this field to avoid redundant
	// calls to "--version".
	Version Version
}

LookPathResult is the result of LookPathFunc.

type ModuleTarget

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

ModuleTarget is a Target implementating 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
}

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

type Version

type Version struct {
	Major int
	Minor int
	Patch int
}

Version is a Python interpreter version.

It is a simplified version of the Python interpreter version scheme defined in PEP 440: https://www.python.org/dev/peps/pep-0440/

Notably, it extracts the major, minor, and patch values out of the version.

func ParseVersion

func ParseVersion(s string) (Version, error)

ParseVersion parses a Python version from a version string (e.g., "1.2.3").

func ParseVersionOutput

func ParseVersionOutput(output string) (Version, error)

ParseVersionOutput parses a Version out of the output of a "--version" Python invocation.

func (*Version) IsSatisfiedBy

func (v *Version) IsSatisfiedBy(other Version) bool

IsSatisfiedBy returns true if "other" is a suitable match for this version. A suitable match:

  • MUST have a Major version.
  • If v is zero, other is automatically suitable.
  • If v is non-zero, other must have the same Major version as v, and a minor/patch version that is >= v's.

func (*Version) IsZero

func (v *Version) IsZero() bool

IsZero returns true if the Version is empty. This is true if the Major field, which must be set, is empty.

func (*Version) Less

func (v *Version) Less(other *Version) bool

Less returns true if "v"'s Version semantically precedes "other".

func (*Version) PythonBase

func (v *Version) PythonBase() string

PythonBase returns the base Python interpreter name for this version.

func (Version) String

func (v Version) String() string

Jump to

Keyboard shortcuts

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