partis.utils.venv module#

class ProcessEnv(*, bin_paths=None, logger=None)[source]#

Bases: object

Base process environment

Parameters:
  • bin_paths (None | list[str]) – Additional bin paths to make available when running commands.

  • logger (None | logging.Logger) – Logger to log messages.

Popen(args, **kwargs)[source]#

Runs a process with the environment using subprocess.Popen

run(args, **kwargs)[source]#

Runs a process with the environment using subprocess.run

async trio_run(args, **kwargs)[source]#

Runs a process with the environment using trio.run_process

class VirtualEnv(*, path, interpreter=None, args=None, bin_paths=None, inherit_site_packages=None, reuse_existing=False, logger=None, mutex=None)[source]#

Bases: ProcessEnv

Minimal implementation of a venv process environment manager

Parameters:
  • path (str) – Path at which to create the virtual environment.

  • interpreter (None | str) – The interpreter to use in the venv.

  • args (None | list[str]) – Additional arguments passed to create venv.

  • bin_paths (None | list[str]) – Additional bin paths to make available when running commands.

  • inherit_site_packages (None | list[str]) – Add ‘site-packages’ search paths to the new venv for the current values in sys.path. This may be used to chain virtual environments, where packages can use those already installed, but new changes will not affect the inherited venv(s). If None, the new venv will not include any additional paths. If a list of paths, the currently running search paths are added in addition to any other listed paths.

  • reuse_existing (bool) – Attempt to re-use an existing virtual environment at path. If the specified interpreter does not match, the existing venv will be deleted and re-created.

  • logger (None | logging.Logger) – Logger to log messages.

  • mutex (None | Mutex) – Mutex used to acquire locks on creating or installing to the venv at path

Note

Adapted from the nox VirtualEnv: https://github.com/theacodes/nox

static get_sys_path(exec)[source]#

The sys.path that will be used in the new venv

static get_pip_version(exec)[source]#

Version (major only) of pip currently installed in the virtual environment

property sys_path#

The sys.path that will be used in the new venv

property pip_version#

Version (major only) of pip currently installed in the virtual environment