py-discovery#

py-discovery aims to abstract away discovering Python interpreters on a user machine.

API#

py_discovery.__version__ = '0.1.dev2+ged06613'#

version of the package

Python discovery.

class py_discovery.PythonInfo[source]#

Bases: object

Contains information for a Python interpreter.

install_path(key)[source]#
Return type:

str

property version_str#
property version_release_str#
property python_name#
property is_old_virtualenv#
property is_venv#
sysconfig_path(key, config_var=None, sep='/')[source]#
Return type:

str

property system_include#
property system_prefix#
property system_exec_prefix#
property spec#
satisfies(spec, impl_must_match)[source]#

Check if a given specification can be satisfied by the python interpreter instance.

Return type:

bool

classmethod current()[source]#

Locate the current host interpreter information.

This might be different than what we run into in case the host python has been upgraded from underneath us.

Return type:

PythonInfo

classmethod current_system()[source]#

Locate the current host interpreter information.

This might be different than what we run into in case the host python has been upgraded from underneath us.

Return type:

PythonInfo

classmethod from_exe(exe, *, raise_on_error=True, resolve_to_host=True, env=None)[source]#

Given a path to an executable, get the python information.

Return type:

Optional[PythonInfo]

discover_exe(prefix, exact=True, env=None)[source]#
Return type:

PythonInfo

class py_discovery.VersionInfo(major, minor, micro, releaselevel, serial)#

Bases: tuple

Create new instance of VersionInfo(major, minor, micro, releaselevel, serial)

major#

Alias for field number 0

micro#

Alias for field number 2

minor#

Alias for field number 1

releaselevel#

Alias for field number 3

serial#

Alias for field number 4

class py_discovery.PythonSpec(str_spec, implementation, major, minor, micro, architecture, path)[source]#

Bases: object

Contains specification about a Python Interpreter.

classmethod from_string_spec(string_spec)[source]#
Return type:

PythonSpec

generate_names()[source]#
Return type:

Iterator[tuple[str, bool]]

property is_abs#
satisfies(spec)[source]#

Call when there’s a candidate metadata spec to see if compatible - e.g., PEP-514 on Windows.

Return type:

bool

class py_discovery.Discover(options)[source]#

Bases: object

Discover and provide the requested Python interpreter.

Create a new discovery mechanism.

Parameters:

options (Namespace) – The parsed options as defined within the add_parser_arguments().

classmethod add_parser_arguments(parser)[source]#

Add CLI arguments for this discovery mechanisms.

Parameters:

parser (ArgumentParser) – The CLI parser.

Return type:

None

abstract run()[source]#

Discovers an interpreter.

Return type:

Optional[PythonInfo]

Returns:

The interpreter ready to use for virtual environment creation

property interpreter#
Returns:

the interpreter as returned by the run(), cached

class py_discovery.Builtin(options)[source]#

Bases: Discover

Create a new discovery mechanism.

Parameters:

options (Namespace) – The parsed options as defined within the add_parser_arguments().

classmethod add_parser_arguments(parser)[source]#

Add CLI arguments for this discovery mechanisms.

Parameters:

parser (ArgumentParser) – The CLI parser.

Return type:

None

run()[source]#

Discovers an interpreter.

Return type:

Optional[PythonInfo]

Returns:

The interpreter ready to use for virtual environment creation

class py_discovery.PathPythonInfo[source]#

Bases: PythonInfo

python info from a path.

py_discovery.get_interpreter(key, try_first_with, env=None)[source]#
Return type:

Optional[PythonInfo]