Documentation
¶
Overview ¶
Package interpreter implements useful utilites for getting, searching, sorting and otherwise dealing with python interpreters on $PATH
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Interpreter ¶
type Interpreter struct {
Major int // The interpreter major version e.g. 3
Minor int // The interpreter minor version e.g. 10
Path string // The absolute path to the interpreter executable
}
Interpreter represents a version of a python interpreter only major and minor are included because this is how the executables are stored on disk (e.g. /usr/local/bin/python3.9)
func (*Interpreter) FromFilePath ¶
func (i *Interpreter) FromFilePath(path string) error
FromFilePath extracts the version information from a python interpreter's filepath and loads the information into the calling `Interpreter` If the filename does not start with `python` or does not have a valid two digit version after it, an error will be returned
A valid filepath will look like `/usr/local/bin/python3.9` things like `/usr/local/bin/python` will be rejected as these typically refer to the system version of python which should not be used
func (Interpreter) SatisfiesExact ¶
func (i Interpreter) SatisfiesExact(major, minor int) bool
SatisfiesExact tests whether the calling Interpreter satisfies the exact version contraint given by `major` and `minor`
func (Interpreter) SatisfiesMajor ¶
func (i Interpreter) SatisfiesMajor(version int) bool
SatisfiesMajor tests whether the calling Interpreter satisfies the constraint of it's major version supporting the requested `version`
func (Interpreter) String ¶
func (i Interpreter) String() string
String satisfies the "stringer" interface and allows an `Interpreter` to be printed using fmt.Println, in this case showing the absolute path to the interpreter
func (Interpreter) ToString ¶
func (i Interpreter) ToString() string
ToString is the pretty print representation of an `Interpreter`
Example
i := Interpreter{Major: 3, Minor: 10, Path:"/usr/bin/python3.10"}
fmt.Println(i.ToString())
Output: "3.10 │ /usr/bin/python3.10"
type List ¶
type List []Interpreter
InterpreterList represents a list of python interpreters and enables us to implement sorting which is how we tell which one is the latest python version without relying on filesystem lexical order which may not be deterministic
func GetAll ¶
GetAll looks under each path in `paths` for valid python interpreters and returns the ones it finds
This is allowed in this context because in usage in this program, `paths` will be populated by searching through $PATH, meaning we don't have to bother checking if files are executable etc and $PATH is unlikely to be cluttered with random files called `python` unless they are the interpreter executables