VirtualEnvOnDemand.CreateEnv
index
/home/media/projects/VirtualEnvOnDemand/VirtualEnvOnDemand/CreateEnv.py

CreateEnv - Methods for creating a virtual environment

 
Modules
       
atexit
os
shutil
sys
tempfile
virtualenv

 
Functions
       
activateEnv(venv)
activateEnv - Activates a virtualenv (allows you to import installed modules).
 
@param venv <str/VirtualEnvInfo> - A path to the root of a virtualenv, or a VirtualEnvInfo.VirtualEnvInfo object (Like from VirtualEnvInfo.getInfoFromVirtualEnv)
 
@raises - TypeError - if venv is not correct type
@raises - ValueError - if venv is not a usable virtual environment.
 
@return <str> - The path of the site-packages directory which as added to the python import path.
createEnv(packages=None, parentDirectory=None, name=None, stdout=<_io.TextIOWrapper name='<stdout>' mode='w' encoding='UTF-8'>, stderr=<_io.TextIOWrapper name='<stderr>' mode='w' encoding='UTF-8'>, deleteOnClose=True, activateEnvironment=True)
createEnv - Creates a temporary virtual environment and installs the required modules for the current running application.
    You can use this, for example, to "recover" from a failed import by installing the software on demand.
 
    @param packages - Describes the required packages. Takes one of the following forms:
 
        String - Directly becomes contents of requirements.txt file to be ingested by pip
        List   - A list/tuple/set of package names (optionally including version requirements, e.x. MyPkg==1.2.3)
        Dict   - A dictionary of package names to versions. If no value is present, the latest will be fetched.
 
    @param parentDirectory <str> - Parent directory of the directory which will be created to hold the temporary environment and packages. Defaults to tempfile.tempdir
 
    @param name <str> - If provided, will use this as the virtualenv name. Otherwise, a random name will be generated. This should not contain any directories, use #parentDirectory to specify the directory.
 
    @param stdout <iostream/None> - Stream to be used as stdout for installation. Default is sys.stdout. Use "None" to swallow output.
 
    @param stderr <iostream/None> - Stream to be used as stderr for installation. Default is sys.stderr. Use "None" to swallow output.
 
    @param deleteOnClose <bool> - If True (Default), this temporary environment and packages will be erased after program terminates. Note, this cannot trap everything (e.x. SIGKILL).
 
    @param activateEnvironment <bool> Default True, If True, this virtualenv will immediately be activated (so you can import installed packages)
 
    @return - On success, returns a VirtualEnvInfo object, which can be used as a dict with the following fields:
        {
            'virtualenvDirectory'   : Absolute path to the root virtualenv directory
            'sitePackagesDirectory' : Absolute path to the site-packages directory within
            'requirements.txt'      : Full generated requirements.txt file used for pip installation
        }
 
@raises - 
    VirtualEnvOnDemand.exceptions.PipInstallFailed -  if cannot install packages
    ValueError - If parent directory does not exist.
    Others (Exception, etc)                        -  If permissions problem to write to specified directory, etc
createEnvIfCannotImport(importName, packages, parentDirectory=None, stdout=<_io.TextIOWrapper name='<stdout>' mode='w' encoding='UTF-8'>, stderr=<_io.TextIOWrapper name='<stderr>' mode='w' encoding='UTF-8'>, deleteOnClose=True)
createEnvIfCannotImport - Tries to import a given name, and if fails, creates a temporary env and installs given packages and tries again.
 
@see createEnv for most params.
 
@param importName - Name of module to import
 
@raises - 
    VirtualEnvOnDemand.exceptions.PipInstallFailed -  if cannot install packages
    ImportError                                    -  if cannot import even after successful installation of the packages.
    Others (Exception, etc)                        -  If permissions problem to write to specified directory, etc
 
@return - None if no env was created, otherwise the return VirtualEnvInfo object from the createEnv call. @see createEnv

 
Data
        __all__ = ('activateEnv', 'createEnv', 'createEnvIfCannotImport')