VirtualEnvOnDemand.CreateEnv
index

# Copyright (c) 2015 Timothy Savannah under terms of LGPLv3. You should have received a copy of this with this distribution as "LICENSE"

 
Modules
       
atexit
shutil
sys
tempfile
virtualenv

 
Functions
       
createEnv(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)
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 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).
 
    @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
    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__ = ('createEnv', 'createEnvIfCannotImport')