Python invirtualenv module code documentation¶
Python module support functions for the invirtualenv scripts
InVirtualEnv Python Virtualenv Installer Module
Configuration Manipulation¶
Functions for handling the configuration settings
-
invirtualenv.config.cast_types(configuration, types_dict=None)[source]¶ Update in place the configuration dictionary with inferred values if they aren’t specified.
Parameters:
-
invirtualenv.config.generate_parsed_config_file(source=None, dest=None)[source]¶ Generate a conf file with the environment variables expanded
Parameters: Returns: Path to the generated config file
Return type:
-
invirtualenv.config.get_configuration(configuration=None)[source]¶ Parse a configuration file
Parameters: configuration (str or list, optional) – A configuration file or list of configuration files to parse, defaults to the deploy_default.conf file in the package and deploy.conf in the current working directory. Returns: The parsed configuration Return type: configparser
-
invirtualenv.config.get_configuration_dict(configuration=None, value_types=None)[source]¶ Parse the configuration files
Parameters: Returns: Configuration dictionary
Return type:
-
invirtualenv.config.parse_arguments(configuration=None)[source]¶ Parse the command line arguments
Parameters: configuration (list, optional) – A list of config files to parse, defaults to the packaged deploy_default.conf and the deploy.conf file in the current directory. Returns: With the configuration based on the passed command line arguments and defaults from the deploy_default.conf file in the package. Return type: argparse namespace object
Deployment¶
Module to create/deploy a virtualenv
-
invirtualenv.deploy.build_deploy_virtualenv(arguments=None, configuration=None, update_existing=True, verbose=None)[source]¶ Build and deploy a python virtualenv
Parameters: - arguments (argparse namespace, optional) – An argparse namespace with all of the required command line arguments defaults to parsing the command line arguments if not provided.
- configuration (str or list, optional) – A configuration file or list of configuration files to parse, defaults to the deploy_default.conf file in the package and deploy.conf in the current working directory.
- update_existing (bool) – If True, allow updating an existing virtualenv, Otherwise generate an exception. Default=True
- verbose (bool) – If True, provides status output while running.
Raises: AlreadyExists– The virtualenv already existsBuildError– The specified package manifest cannot be deployed to the virtualenvInsufficientPermissions– The current user lacks permissions to complete the specified operationNoPackageVersions– A virtualenv_version_package was specified in the configuration but no versions for that package where found on artifactory.
-
invirtualenv.deploy.deployed_bin_files(venv)[source]¶ Gets files that where deployed to the bin directory of the virtualenv.
Parameters: venv (str) – Path the to virtualenv to do this bin_file links for Returns: Key = filename Value = sha256 hash Return type: dict
-
invirtualenv.deploy.fix_file_ownership(virtualenv, user, group)[source]¶ Fix the file ownership of a virtualenv
Parameters: :param : :type : return:
-
invirtualenv.deploy.install_python_dependencies(virtualenv, deps=None, requirements=None, upgrade=False, verbose=False, pip_version=None, use_index=True)[source]¶ Install python dependencies from a requirements file or deploy.conf manifest
Parameters: - virtualenv (str) – The virtualenv to install into
- deps (list, optional) – A list of python packages to install
- requirements (str, optional) – The requirements.txt file to install from
- upgrade (bool, optional) – Tell pip to upgrade packages when installing, Default=False
- verbose (bool, optional) – Display command output when running the dependency operations, Default=False
- use_index (bool, optional) – Allow pip to use an external index Default=True
Raises: BuildException - If package installation fails
-
invirtualenv.deploy.install_rpm_dependencies(deps=None, fail_missing=True)[source]¶ Install rpm dependencies from deploy.conf manifest
Parameters: Raises: BuildException - If package installation fails
Exceptions¶
Exceptions generated by the invirtualenv module
-
exception
invirtualenv.exceptions.BuildException[source]¶ There was an error Building the VirtualEnv
-
exception
invirtualenv.exceptions.InsufficientPermissions[source]¶ The current user has insufficient permissions to complete the specified operation.
-
exception
invirtualenv.exceptions.NoPackageVersions[source]¶ Query of the Python PyPi repo returned no packages with the specified name.
Package Manipulation¶
Functions for managing packaging
-
invirtualenv.package.install_prereq_packages(test=False)[source]¶ Install packages required to build python
Parameters: test (bool, optional) – Don’t run the actual command, if True
-
invirtualenv.package.latest_package_version(package)[source]¶ Get the latest version number for a package
Parameters: package (str) – Package to get the latest version of Returns: Latest package version or an empty string if no versions are found Return type: str
-
invirtualenv.package.package_scripts_directory()[source]¶ Get the package scripts directory
Returns str
The path to the directory containing the package scripts
-
invirtualenv.package.package_versions(package, pypi_url=None)[source]¶ Get all versions of a package from pypi
Parameters: Returns: A list of all packages found on pypi. The list will be empty if there were no versions found.
Return type:
Utility¶
General utility functionality module
-
invirtualenv.utility.change_uid_gid(user_uid=None, user_gid=None)[source]¶ preexec_fn to change the uid/gid when using subprocess
Parameters:
-
invirtualenv.utility.chown_recursive(path, uid, gid)[source]¶ Change the ownership of all files and directories in path
Parameters:
-
invirtualenv.utility.csv_list(value)[source]¶ Convert a comma separated string into a list
Parameters: value (str) – The string object to convert to a list Returns: A list based on splitting the string on the ‘,’ character Return type: list
-
invirtualenv.utility.display_header(text='', width=None, separator=None, outfile=None, collapse=False)[source]¶ Display a textual header message. :param text: The text to print/display :type text: str :param width: The width (text wrap) of the header message.
This will be the current terminal width as determined by the ‘stty size’ shell command if not specified.Parameters: - separator (str, optional) – The character or string to use as a horizontal separator. Will use ‘=’ if one is not specified.
- outfile (File, optional) – The File object to print the header text to. This will use sys.stdout if not specified.
:param : :type : return:
-
invirtualenv.utility.get_terminal_size()[source]¶ Get the terminal rows and columns if we are running on an interactive terminal. :returns: * rows (int) – The number of rows on the current terminal.
- columns (int) – The number of columns on the current terminal.
-
invirtualenv.utility.str_format_env(value)[source]¶ Substitute values with environment variables in a string
Parameters: value (str) – The string object to be formatted and converted into a list Returns: With env variable values substituded Return type: str
-
invirtualenv.utility.str_to_bool(value)[source]¶ Convert a string too a bool object
Parameters: value (str) – The string object to convert to a bool. The following case insensitive strings evaluate to True [‘true’, 1’, ‘up’, ‘on’] Returns: Boolean based on the string Return type: bool
-
invirtualenv.utility.str_to_dict(value)[source]¶ Convert a newline terminated string of key=value into a dictionary.
Parameters: value (str) – The string object to convert to a dictionary Returns: Dictionary based on the string Return type: dict
-
invirtualenv.utility.str_to_list(value)[source]¶ Convert a newline terminated string into a list. Any empty lines will be removed from the result list.
Parameters: value (str) – The string object to convert to a list Returns: List based on the string Return type: list
-
invirtualenv.utility.update_recursive(basedict, updatedict)[source]¶ Recursively run update on a dictionary
Parameters: Returns: basedict updated to contain the values from updatedict
Return type:
Static Standalone Binary Creation¶
Virtualenv Management¶
Functions for creating and managing python virtual environments
-
invirtualenv.virtualenv.build_virtualenv(name, directory, python_interpreter=None, user=None, verbose=False)[source]¶ Build a virtualenv in a directory
Parameters: - name (str) – Name of the virtualenv to create
- directory (str) – Directory to create the virtualenv in
- python_interpreter (str, optional) – Python interpreter to provide in the virtualenv, defaults to the interpreter that is running the virtualenv command
- verbose (bool) – If True, provides status output while running.
Returns: Full path to the root of the virtualenv directory
Return type: Raises: BuildException– The Virtualenv build failed
-
invirtualenv.virtualenv.default_virtualenv_directory()[source]¶ Get the default virtualenv directory for the current system/platform
Returns: The path to the default virtualenv directory Return type: str
-
invirtualenv.virtualenv.install_requirements(requirements, virtualenv, user=None, upgrade=False, verbose=False, pip_version=None, use_index=True)[source]¶ Open one or more requirements files and run pip -r to install them
Parameters: - requirements (str) – Filename containing requirements
- virtualenv (str) – Full path to the virtualenv to install into
- user (str, optional) – The user:group to run the install as
- upgrade (bool) – If True, tell pip to upgrade when running the install. Default=False
- verbose (bool) – If True, provides status output while running.
- pip_version (str, optional) – Install the requirements with the specified version of pip
- use_index (bool, optional) – Allow pip to use an external index Default=True
-
invirtualenv.virtualenv.remove_virtualenv(name, directory=None)[source]¶ Remove a virtualenv from a directory :param name: :param directory: :return:
-
invirtualenv.virtualenv.upgrade_package_tools(virtualenv_directory, verbose=False)[source]¶ Upgrade the packages used to install/build packages in the virtualenv :param virtualenv_directory: The directory that contains the virtualenv :type virtualenv_directory: str