Esempio n. 1
0
def test_ensure_valid_spec():
    assert environ._ensure_valid_spec('python') == 'python'
    assert environ._ensure_valid_spec('python 2.7') == 'python 2.7.*'
    assert environ._ensure_valid_spec('python 2.7.2') == 'python 2.7.2.*'
    assert environ._ensure_valid_spec('python 2.7.12 0') == 'python 2.7.12 0'
    assert environ._ensure_valid_spec('python >=2.7,<2.8') == 'python >=2.7,<2.8'
    assert environ._ensure_valid_spec('numpy x.x') == 'numpy x.x'
    assert environ._ensure_valid_spec(MatchSpec('numpy x.x')) == MatchSpec('numpy x.x')
Esempio n. 2
0
def update_me():
    """
    Update the webservice on Heroku by pushing a commit to this repo.
    """
    pkgs = ["conda-build", "conda-smithy", "conda-forge-pinning"]
    installed_vers = get_installed_version(root_dir, pkgs)
    index = get_index(channel_urls=['conda-forge'])
    r = Resolve(index)

    to_install = {}

    for pkg in pkgs:
        available_versions = [p.version for p in r.get_pkgs(MatchSpec(pkg))]
        available_versions = sorted(available_versions, key=VersionOrder)
        latest_version = available_versions[-1]
        print(latest_version, installed_vers[pkg])
        if VersionOrder(latest_version) > VersionOrder(installed_vers[pkg]):
            to_install[pkg] = latest_version

    if not to_install:
        return

    with tmp_directory() as tmp_dir:
        repo_name = "conda-forge-webservices"
        clone_dir = os.path.join(tmp_dir, repo_name)
        url = "https://{}@github.com/conda-forge/{}.git".format(
            os.environ['GH_TOKEN'], repo_name)

        repo = Repo.clone_from(url, clone_dir)
        msg_vers = ", ".join(
            ["{}={}".format(k, v) for k, v in to_install.items()])
        author = Actor("conda-forge-admin", "*****@*****.**")
        repo.index.commit("Empty commit to rebuild for {}".format(msg_vers))
        repo.git.push("origin", "master")
Esempio n. 3
0
    def test_python(self):
        for spec, ver, res_spec in [
            ('python', '3.4', 'python 3.4*'),
            ('python 2.7.8', '2.7', 'python 2.7.8'),
            ('python 2.7.8', '3.5', 'python 2.7.8'),
            ('python 2.7.8', None, 'python 2.7.8'),
            ('python', None, 'python'),
            ('python x.x', '2.7', 'python 2.7*'),
            ('python', '27', 'python 2.7*'),
            ('python', 27, 'python 2.7*'),
        ]:
            ms = MatchSpec(spec)
            self.assertEqual(handle_config_version(ms, ver),
                             MatchSpec(res_spec))

        self.assertRaises(RuntimeError, handle_config_version,
                          MatchSpec('python x.x'), None)
Esempio n. 4
0
    def test_numpy(self):
        for spec, ver, res_spec, kwargs in [
                ('numpy', None, 'numpy', {}),
                ('numpy', 18, 'numpy 1.8*', {'dep_type': 'build'}),
                ('numpy', 18, 'numpy', {'dep_type': 'run'}),
                ('numpy', 110, 'numpy', {}),
                ('numpy x.x', 17, 'numpy 1.7*', {}),
                ('numpy x.x', 110, 'numpy 1.10*', {}),
                ('numpy 1.9.1', 18, 'numpy 1.9.1', {}),
                ('numpy 1.9.0 py27_2', None, 'numpy 1.9.0 py27_2', {}),
        ]:
            ms = MatchSpec(spec)
            self.assertEqual(handle_config_version(ms, ver, **kwargs),
                             MatchSpec(res_spec))

        self.assertRaises(RuntimeError,
                          handle_config_version,
                          MatchSpec('numpy x.x'), None)
def main():
    """Get current versions from the heroku app and update if they are old.

    Note this script runs on CircleCI, not on the heroku app.
    """
    # keep these imports here to protect the webservice from memory errors
    # due to conda
    from conda_build.conda_interface import (
        VersionOrder, MatchSpec, get_index, Resolve)

    r = requests.get(
        "https://conda-forge.herokuapp.com/conda-webservice-update/versions")
    r.raise_for_status()
    installed_vers = r.json()

    index = get_index(channel_urls=['conda-forge'])
    r = Resolve(index)

    to_install = {}
    final_install = {}

    for pkg in PKGS:
        available_versions = [p.version for p in r.get_pkgs(MatchSpec(pkg))]
        available_versions = sorted(available_versions, key=VersionOrder)
        latest_version = available_versions[-1]
        LOGGER.info("%s|latest|installed:" % pkg, latest_version, installed_vers[pkg])
        if VersionOrder(latest_version) != VersionOrder(installed_vers[pkg]):
            to_install[pkg] = latest_version
            final_install[pkg] = latest_version
        else:
            final_install[pkg] = installed_vers[pkg]

    if to_install:
        tmpdir = None
        try:
            tmpdir = tempfile.mkdtemp('_recipe')

            repo_name = "conda-forge-webservices"
            clone_dir = os.path.join(tmpdir, repo_name)
            url = "https://{}@github.com/conda-forge/{}.git".format(
                os.environ['GH_TOKEN'], repo_name)

            repo = Repo.clone_from(url, clone_dir, depth=1)

            # keep a record around
            pth = os.path.join(clone_dir, "pkg_versions.json")
            with open(pth, "w") as fp:
                json.dump(final_install, fp)
            repo.index.add(pth)

            msg_vers = ", ".join(["{}={}".format(k, v) for k, v in to_install.items()])
            repo.index.commit("redeploy for '%s'" % msg_vers)
            repo.git.push("origin", "master")

        finally:
            if tmpdir is not None:
                shutil.rmtree(tmpdir)
Esempio n. 6
0
def latest_pkg_version(pkg):
    '''
    :returns: the latest version of the specified conda package available
    '''
    r = Resolve(get_index())
    try:
        pkg_list = sorted(r.get_pkgs(MatchSpec(pkg)))
    except:
        pkg_list = None
    if pkg_list:
        pkg_version = parse_version(pkg_list[-1].version)
    else:
        pkg_version = None
    return pkg_version
Esempio n. 7
0
def check_version_uptodate(resolve, name, installed_version, error_on_warn):
    from conda_build.conda_interface import VersionOrder, MatchSpec
    available_versions = [pkg.version for pkg in resolve.get_pkgs(MatchSpec(name))]
    available_versions = sorted(available_versions, key=VersionOrder)
    most_recent_version = available_versions[-1]
    if installed_version is None:
        msg = "{} is not installed in root env.".format(name)
    elif VersionOrder(installed_version) < VersionOrder(most_recent_version):
        msg = "{} version in root env ({}) is out-of-date ({}).".format(
            name, installed_version, most_recent_version)
    else:
        return
    if error_on_warn:
        raise RuntimeError("{} Exiting.".format(msg))
    else:
        print(msg)
Esempio n. 8
0
    def get_variants(env):
        specs = {}
        variants = {}

        for s in env:
            spec = CondaBuildSpec(s)
            specs[spec.name] = spec

        for n, cb_spec in specs.items():
            if cb_spec.raw.startswith("COMPILER_"):
                print(n)
                # This is a compiler package
                _, lang = cb_spec.raw.split()
                compiler = conda_build.jinja_context.compiler(lang, config)

                config_key = f"{lang}_compiler"
                config_version_key = f"{lang}_compiler_version"

                variants[config_key] = conda_build_config[config_key]
                variants[config_version_key] = conda_build_config[
                    config_version_key]

            if n in conda_build_config:
                vlist = conda_build_config[n]
                # we need to check if v matches the spec
                if cb_spec.is_simple:
                    variants[cb_spec.name] = vlist
                elif cb_spec.is_pin:
                    # ignore variants?
                    pass
                else:
                    # check intersection of MatchSpec and variants
                    ms = MatchSpec(cb_spec.raw)
                    filtered = []
                    for var in vlist:
                        vsplit = var.split()
                        if len(vsplit) == 1:
                            p = {
                                "name": n,
                                "version": vsplit[0],
                                'build_number': 0
                            }
                        elif len(vsplit) == 2:
                            p = {
                                "name": n,
                                "version": var.split()[0],
                                "build": var.split()[1],
                                'build_number': 0
                            }
                        else:
                            raise InvalidRecipeError(
                                "Check your conda_build_config")

                        if ms.match(p):
                            filtered.append(var)
                        else:
                            print(
                                f"Configured variant ignored because of the recipe requirement:\n  {cb_spec.raw} : {var}"
                            )

                    if len(filtered):
                        variants[cb_spec.name] = filtered

        return variants