API Docs

CondaEnv

class conda_pack.CondaEnv(prefix, files, excluded_files=None)

A Conda Environment for packaging.

Use CondaEnv.from_prefix(), CondaEnv.from_name(), or CondaEnv.from_default() instead of the default constructor.

Examples

Package the current environment, excluding all *.pyc and *.pyx files, into a tar.gz archive:

>>> (CondaEnv.from_default()
...          .exclude("*.pyc")
...          .exclude("*.pyx")
...          .pack(output="output.tar.gz"))
"/full/path/to/output.tar.gz"

Package the environment foo into a zip archive:

>>> (CondaEnv.from_name("foo")
...          .pack(output="foo.zip"))
"/full/path/to/foo.zip"
Attributes:
prefix : str

The path to the conda environment.

files : list of File

A list of File objects representing all files in conda environment.

name : str

The name of the environment

name

The name of the environment

classmethod from_prefix(prefix, **kwargs)

Create a CondaEnv from a given prefix.

Parameters:
prefix : str

The path to the conda environment.

Returns:
env : CondaEnv
classmethod from_name(name, **kwargs)

Create a CondaEnv from a named environment.

Parameters:
name : str

The name of the conda environment.

Returns:
env : CondaEnv
classmethod from_default(**kwargs)

Create a CondaEnv from the current environment.

Returns:
env : CondaEnv
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 conda package.

Parameters:
pattern : str

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

Returns:
env : CondaEnv

A new env with any matching files excluded.

See also

include

Examples

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

>>> env = (CondaEnv.from_default()
...                .exclude("*.pyx")
...                .include("lib/python3.6/site-packages/cytoolz/*.pyx"))
CondaEnv<'~/miniconda/envs/example', 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 : CondaEnv

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

See also

exclude

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

Package the conda 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.

arcroot : str, optional

The relative path in the archive to the conda environment. Defaults to ‘’.

dest_prefix : str, optional

If present, prefixes will be rewritten to this path before packaging. In this case the conda-unpack script will not be generated.

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 conda_pack.File(source, target, is_conda=True, file_mode=None, prefix_placeholder=None)

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).

is_conda : bool, optional

Whether the file was installed by conda, or comes from somewhere else.

file_mode : {None, ‘text’, ‘binary’, ‘unknown’}, optional

The type of record.

prefix_placeholder : None or str, optional

The prefix placeholder in the file (if any)

pack

conda_pack.pack(name=None, prefix=None, output=None, format='infer', arcroot='', dest_prefix=None, verbose=False, force=False, compress_level=4, zip_symlinks=False, zip_64=True, filters=None)

Package an existing conda environment into an archive file.

Parameters:
name : str, optional

The name of the conda environment to pack.

prefix : str, optional

A path to a conda 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.

arcroot : str, optional

The relative path in the archive to the conda environment. Defaults to ‘’.

dest_prefix : str, optional

If present, prefixes will be rewritten to this path before packaging. In this case the conda-unpack script will not be generated.

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.