environment-helpers

Collection of helpers for managing Python environments.

API Documentation

environment_helpers module

Collection of helpers for managing Python environments.

class environment_helpers.CurrentEnvironment(*args, **kwargs)

Bases: Environment

Object representing the current environment.

property base: Path
property interpreter: Path
property scheme: SchemeDict[Path]

Default install scheme for the environment.

property scripts: Path
class environment_helpers.Environment(*args, **kwargs)

Bases: Protocol

Object representing a Python environment.

property base: Path
property env: Mapping[str, str]
install(requirements, method=None)
Return type:

None

install_from_path(path, scheme=None, from_sdist=True)
Return type:

None

install_wheel(path, scheme=None)
Return type:

None

property interpreter: Path
property introspectable: Introspectable

Introspectable object for the environment.

run(*args, **kwargs)
Return type:

bytes

run_interpreter(*args, **kwargs)
Return type:

bytes

run_script(name, *args)
Return type:

bytes

property scheme: SchemeDict[Path]

Default install scheme for the environment.

property scripts: Path
class environment_helpers.VirtualEnvironment(path)

Bases: Environment

Object representing a virtual environment (using the venv scheme).

property base: Path
property env: Mapping[str, str]
property interpreter: Path
property scheme: SchemeDict[Path]

Default install scheme for the environment.

property scripts: Path
environment_helpers.create_venv(path, **kwargs)
Return type:

Environment

environment_helpers.build module

environment_helpers.build.build_sdist(srcdir, outdir, config_settings=None, isolated=True, quiet=False)
Return type:

Path

environment_helpers.build.build_wheel(srcdir, outdir, config_settings=None, isolated=True, quiet=False)
Return type:

Path

environment_helpers.build.build_wheel_via_sdist(srcdir, outdir, config_settings=None, isolated=True, quiet=False)
Return type:

Path

environment_helpers.install module

environment_helpers.install.install_wheel(wheel, interpreter, scheme=None)

Install a wheel file to a Python environment.

Return type:

None

environment_helpers.introspect module

class environment_helpers.introspect.Introspectable(interpreter)

Bases: object

call(func, *args, **kwargs)

Call the a function in the target environment.

Parameters:
  • interpreter – Path to the Python interpreter to introspect.

  • func (Union[str, Callable[[Any], TypeVar(T)]]) – Function to call.

  • args (Any) – Positional arguments to pass to the function.

  • kwargs (Any) – Keyword arguments to pass to the function.

Return type:

TypeVar(T)

get_launcher_kind()

Find the launcher kind.

This helper needs to run the Python interpreter for the target environment.

Return type:

Optional[Literal['posix', 'win-ia32', 'win-amd64', 'win-arm', 'win-arm64']]

get_scheme(scheme=None)

Finds the installation paths for a certain Python install scheme.

This helper needs to run the Python interpreter for the target environment.

Parameters:
  • interpreter – Path to the Python interpreter to introspect.

  • scheme (Optional[str]) – Name of the target scheme name. If None, it uses the default scheme.

Return type:

SchemeDict[Path]

get_system_scheme()

Finds the installation paths for the system Python install scheme.

Certain vendors, such as Debian, have a different scheme for system packages. This function finds the install scheme for system packages.

This helper needs to run the Python interpreter for the target environment.

Return type:

SchemeDict[Path]

get_version()
Return type:

PythonVersion

class environment_helpers.introspect.PythonVersion(major, minor, micro, releaselevel, serial)

Bases: NamedTuple

major: int

Alias for field number 0

micro: int

Alias for field number 2

minor: int

Alias for field number 1

releaselevel: str

Alias for field number 3

serial: int

Alias for field number 4

class environment_helpers.introspect.SchemeDict

Bases: TypedDict

data: TypeVar(T)
include: TypeVar(T)
platinclude: TypeVar(T)
platlib: TypeVar(T)
platstdlib: TypeVar(T)
purelib: TypeVar(T)
scripts: TypeVar(T)
stdlib: TypeVar(T)
environment_helpers.introspect.get_virtual_environment_scheme(path)

Calculates the installation paths for the scheme used by a certain virtual environment.

Parameters:

path (PathLike[str] | str) – Path of the target virtual environment.

Return type:

SchemeDict[Path]

environment_helpers.introspect.scheme_dict_as_sysconfig(scheme)
Return type:

SchemeDict[str]