def get_installed_version(prefix, pkgs): """Primarily used by conda-forge, but may be useful in general for checking when a package needs to be updated""" from conda_build.utils import ensure_list pkgs = ensure_list(pkgs) linked_pkgs = linked(prefix) versions = {} for pkg in pkgs: vers_inst = [dist.split('::', 1)[-1].rsplit('-', 2)[1] for dist in linked_pkgs if dist.split('::', 1)[-1].rsplit('-', 2)[0] == pkg] versions[pkg] = vers_inst[0] if len(vers_inst) == 1 else None return versions
def which_package(path): """ given the path (of a (presumably) conda installed file) iterate over the conda packages the file came from. Usually the iteration yields only one package. """ from os.path import abspath, join path = abspath(path) prefix = which_prefix(path) if prefix is None: raise RuntimeError("could not determine conda prefix from: %s" % path) for dist in linked(prefix): meta = is_linked(prefix, dist) if any(abspath(join(prefix, f)) == path for f in meta['files']): yield dist