Exemplo n.º 1
0
def package_is_installed(prefix, dist, exact=False, pip=False):
    packages = list(get_egg_info(prefix) if pip else linked(prefix))
    if '::' not in text_type(dist):
        packages = [p.dist_name for p in packages]
    if exact:
        return dist in packages
    return any(p.startswith(dist) for p in packages)
Exemplo n.º 2
0
def package_is_installed(prefix, dist, exact=False, pip=False):
    packages = list(get_egg_info(prefix) if pip else linked(prefix))
    if '::' not in text_type(dist):
        packages = [p.dist_name for p in packages]
    if exact:
        return dist in packages
    return any(p.startswith(dist) for p in packages)
Exemplo n.º 3
0
def from_environment(name, prefix, no_builds=False, ignore_channels=False):
    """
        Get environment object from prefix
    Args:
        name: The name of environment
        prefix: The path of prefix
        no_builds: Whether has build requirement
        ignore_channels: whether ignore_channels

    Returns:     Environment object
    """
    installed = linked(prefix, ignore_channels=ignore_channels)
    conda_pkgs = copy(installed)
    # json=True hides the output, data is added to installed
    add_pip_installed(prefix, installed, json=True)

    pip_pkgs = sorted(installed - conda_pkgs)

    if no_builds:
        dependencies = ['='.join((a.name, a.version)) for a in sorted(conda_pkgs)]
    else:
        dependencies = ['='.join((a.name, a.version, a.build)) for a in sorted(conda_pkgs)]
    if len(pip_pkgs) > 0:
        dependencies.append({'pip': ['=='.join(a.rsplit('-', 2)[:2]) for a in pip_pkgs]})
    # conda uses ruamel_yaml which returns a ruamel_yaml.comments.CommentedSeq
    # this doesn't dump correctly using pyyaml
    channels = list(context.channels)
    if not ignore_channels:
        for dist in conda_pkgs:
            if dist.channel not in channels:
                channels.insert(0, dist.channel)
    return Environment(name=name, dependencies=dependencies, channels=channels, prefix=prefix)
Exemplo n.º 4
0
def from_environment(name, prefix, no_builds=False, ignore_channels=False):
    """
        Get environment object from prefix
    Args:
        name: The name of environment
        prefix: The path of prefix
        no_builds: Whether has build requirement
        ignore_channels: whether ignore_channels

    Returns:     Environment object
    """
    installed = linked(prefix, ignore_channels=ignore_channels)
    conda_pkgs = copy(installed)
    # json=True hides the output, data is added to installed
    add_pip_installed(prefix, installed, json=True)

    pip_pkgs = sorted(installed - conda_pkgs)

    if no_builds:
        dependencies = [
            '='.join((a.name, a.version)) for a in sorted(conda_pkgs)
        ]
    else:
        dependencies = [
            '='.join((a.name, a.version, a.build)) for a in sorted(conda_pkgs)
        ]
    if len(pip_pkgs) > 0:
        dependencies.append(
            {'pip': ['=='.join(a.rsplit('-', 2)[:2]) for a in pip_pkgs]})
    # conda uses ruamel_yaml which returns a ruamel_yaml.comments.CommentedSeq
    # this doesn't dump correctly using pyyaml
    channels = list(context.channels)
    if not ignore_channels:
        for dist in conda_pkgs:
            if dist.channel not in channels:
                channels.insert(0, dist.channel)
    return Environment(name=name,
                       dependencies=dependencies,
                       channels=channels,
                       prefix=prefix)
Exemplo n.º 5
0
def assert_package_is_installed(prefix, package, exact=False, pip=False):
    if not package_is_installed(prefix, package, exact, pip):
        print(list(linked(prefix)))
        raise AssertionError("package {0} is not in prefix".format(package))
Exemplo n.º 6
0
def assert_package_is_installed(prefix, package, exact=False, pip=False):
    if not package_is_installed(prefix, package, exact, pip):
        print(list(linked(prefix)))
        raise AssertionError("package {0} is not in prefix".format(package))