VirtualEnvOnDemand (version 2.0.0)
index

# Copyright (c) 2015 Timothy Savannah under terms of LGPLv3. You should have received a copy of this with this distribution as "LICENSE"
#
#  VirtualEnvOnDemand provides a simple means for an application, without restarting, to temporarily install and use its runtime requirements

 
Package Contents
       
CreateEnv
GlobalEnv
InstallPackages
exceptions

 
Classes
       
exceptions.Exception(exceptions.BaseException)
VirtualEnvOnDemand.exceptions.PipInstallFailed

 
class PipInstallFailed(exceptions.Exception)
    PipInstallFailed - Exception raised when pip fails to install a list of packages
 
 
Method resolution order:
PipInstallFailed
exceptions.Exception
exceptions.BaseException
__builtin__.object

Methods defined here:
__init__(self, returnCode=None, reqFileContents='')
Create a PipInstallFailed exception, building a message from some pieces of information
 
    @param returnCode <int> - Return code of subprocess, or None if undetermined
    @param reqFileContents <str> - String of requirements file to reproduce error

Data descriptors defined here:
__weakref__
list of weak references to the object (if defined)

Data and other attributes inherited from exceptions.Exception:
__new__ = <built-in method __new__ of type object>
T.__new__(S, ...) -> a new object with type S, a subtype of T

Methods inherited from exceptions.BaseException:
__delattr__(...)
x.__delattr__('name') <==> del x.name
__getattribute__(...)
x.__getattribute__('name') <==> x.name
__getitem__(...)
x.__getitem__(y) <==> x[y]
__getslice__(...)
x.__getslice__(i, j) <==> x[i:j]
 
Use of negative indices is not supported.
__reduce__(...)
__repr__(...)
x.__repr__() <==> repr(x)
__setattr__(...)
x.__setattr__('name', value) <==> x.name = value
__setstate__(...)
__str__(...)
x.__str__() <==> str(x)
__unicode__(...)

Data descriptors inherited from exceptions.BaseException:
__dict__
args
message

 
Functions
       
createEnv(packages, parentDirectory=None, stdout=<open file '<stdout>', mode 'w'>, stderr=<open file '<stderr>', mode 'w'>, deleteOnClose=False)
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 the following dict:
        {
            '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=<open file '<stdout>', mode 'w'>, stderr=<open file '<stderr>', mode 'w'>, 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 dict from the createEnv call. @see createEnv
enableOnDemandImporter()
enableOnDemandImporter - Calling this method turns on the "on demand" importer. A temporary global env is created, and all failed imports will attempt an installation.

 
Data
        __all__ = ('createEnv', 'createEnvIfCannotImport', 'enableOnDemandImporter', 'PipInstallFailed', '__version__', '__version_tuple__')
__version__ = '2.0.0'
__version_tuple__ = (2, 0, 0)