interpreter

package
v0.3.2 Latest Latest
Warning

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

Go to latest
Published: Apr 1, 2023 License: MIT Imports: 6 Imported by: 0

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 {
	Path  string // The absolute path to the interpreter executable
	Major int    // The intepreter major version e.g. 3
	Minor int    // The interpreter minor version e.g. 10
}

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 GetAll

func GetAll(paths []string) ([]Interpreter, error)

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.

func Sort

func Sort(interpreters []Interpreter) []Interpreter

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".

Jump to

Keyboard shortcuts

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