API Docs

Env

class venv_pack.Env(prefix=None)

A Virtual Environment for packaging.

Parameters:
prefix : str, optional

The path to the virtual environment. If not provided, the current environment will be used.

Examples

Package the current environment into a zip archive:

>>> Env().pack(output="environment.tar.gz")
"/full/path/to/environment.tar.gz"
name

The name of the environment

exclude(pattern)

Exclude all files that match pattern from being packaged.

This can be useful to remove functionality that isn’t needed in the archive but is part of the original virtual environment.

Parameters:
pattern : str

A file pattern. May include shell-style wildcards a-la glob.

Returns:
env : Env

A new env with any matching files excluded.

See also

include

Examples

Exclude all *.pyx files, except those from cytoolz.

>>> env = (Env().exclude("*.pyx")
...             .include("lib/python3.6/site-packages/cytoolz/*.pyx"))
Env<'/full/path/to/environment', 1234 files>
include(pattern)

Re-add all excluded files that match pattern

Parameters:
pattern : str

A file pattern. May include shell-style wildcards a-la glob.

Returns:
env : Env

A new env with any matching files that were previously excluded re-included.

See also

exclude

pack(output=None, format='infer', python_prefix=None, verbose=False, force=False, compress_level=4, zip_symlinks=False, zip_64=True)

Package the virtual environment into an archive file.

Parameters:
output : str, optional

The path of the output file. Defaults to the environment name with a .tar.gz suffix (e.g. my_env.tar.gz).

format : {‘infer’, ‘zip’, ‘tar.gz’, ‘tgz’, ‘tar.bz2’, ‘tbz2’, ‘tar’}

The archival format to use. By default this is inferred by the output file extension.

python_prefix : str, optional

If provided, will be used as the new prefix path for linking python in the packaged environment. Note that this is the path to the prefix, not the path to the executable (e.g. /usr/ not /usr/lib/python3.6).

verbose : bool, optional

If True, progress is reported to stdout. Default is False.

force : bool, optional

Whether to overwrite any existing archive at the output path. Default is False.

compress_level : int, optional

The compression level to use, from 0 to 9. Higher numbers decrease output file size at the expense of compression time. Ignored for format='zip'. Default is 4.

zip_symlinks : bool, optional

Symbolic links aren’t supported by the Zip standard, but are supported by many common Zip implementations. If True, store symbolic links in the archive, instead of the file referred to by the link. This can avoid storing multiple copies of the same files. Note that the resulting archive may silently fail on decompression if the ``unzip`` implementation doesn’t support symlinks. Default is False. Ignored if format isn’t zip.

zip_64 : bool, optional

Whether to enable ZIP64 extensions. Default is True.

Returns:
out_path : str

The path to the archived environment.

File

class venv_pack.File

A single archive record.

Parameters:
source : str

Absolute path to the source.

target : str

Relative path from the target prefix (e.g. lib/foo/bar.py).

pack

venv_pack.pack(prefix=None, output=None, format='infer', python_prefix=None, verbose=False, force=False, compress_level=4, zip_symlinks=False, zip_64=True, filters=None)

Package an existing virtual environment into an archive file.

Parameters:
prefix : str, optional

A path to a virtual environment to pack.

output : str, optional

The path of the output file. Defaults to the environment name with a .tar.gz suffix (e.g. my_env.tar.gz).

format : {‘infer’, ‘zip’, ‘tar.gz’, ‘tgz’, ‘tar.bz2’, ‘tbz2’, ‘tar’}, optional

The archival format to use. By default this is inferred by the output file extension.

python_prefix : str, optional

If provided, will be used as the new prefix path for linking python in the packaged environment. Note that this is the path to the prefix, not the path to the executable (e.g. /usr/ not /usr/lib/python3.6).

verbose : bool, optional

If True, progress is reported to stdout. Default is False.

force : bool, optional

Whether to overwrite any existing archive at the output path. Default is False.

compress_level : int, optional

The compression level to use, from 0 to 9. Higher numbers decrease output file size at the expense of compression time. Ignored for format='zip'. Default is 4.

zip_symlinks : bool, optional

Symbolic links aren’t supported by the Zip standard, but are supported by many common Zip implementations. If True, store symbolic links in the archive, instead of the file referred to by the link. This can avoid storing multiple copies of the same files. Note that the resulting archive may silently fail on decompression if the ``unzip`` implementation doesn’t support symlinks. Default is False. Ignored if format isn’t zip.

zip_64 : bool, optional

Whether to enable ZIP64 extensions. Default is True.

filters : list, optional

A list of filters to apply to the files. Each filter is a tuple of (kind, pattern), where kind is either 'exclude' or 'include' and pattern is a file pattern. Filters are applied in the order specified.

Returns:
out_path : str

The path to the archived environment.