build-locally.py 2.14 KB
Newer Older
1 2 3 4 5 6
#!/usr/bin/env python3
#
# This file has been generated by conda-smithy in order to build the recipe
# locally.
#
import glob
Amir MOHAMMADI's avatar
Amir MOHAMMADI committed
7
import os
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29
import subprocess
from argparse import ArgumentParser


def setup_environment(ns):
    os.environ["CONFIG"] = ns.config
    os.environ["UPLOAD_PACKAGES"] = "False"
    if ns.debug:
        os.environ["BUILD_WITH_CONDA_DEBUG"] = "1"
        if ns.output_id:
            os.environ["BUILD_OUTPUT_ID"] = ns.output_id


def run_docker_build(ns):
    script = ".scripts/run_docker_build.sh"
    subprocess.check_call([script])


def verify_config(ns):
    valid_configs = {
        os.path.basename(f)[:-5] for f in glob.glob(".ci_support/*.yaml")
    }
Amir MOHAMMADI's avatar
Amir MOHAMMADI committed
30
    print("valid configs are {valid_configs}".format(valid_configs=valid_configs))
31 32 33 34 35 36 37 38 39 40
    if ns.config in valid_configs:
        print("Using " + ns.config + " configuration")
        return
    elif len(valid_configs) == 1:
        ns.config = valid_configs.pop()
        print("Found " + ns.config + " configuration")
    elif ns.config is None:
        print("config not selected, please choose from the following:\n")
        selections = list(enumerate(sorted(valid_configs), 1))
        for i, c in selections:
Amir MOHAMMADI's avatar
Amir MOHAMMADI committed
41
            print("{i}. {c}".format(i=i, c=c))
42 43 44
        s = input("\n> ")
        idx = int(s) - 1
        ns.config = selections[idx][1]
Amir MOHAMMADI's avatar
Amir MOHAMMADI committed
45
        print("selected {config}".format(config=ns.config))
46 47 48 49 50
    else:
        raise ValueError("config " + ns.config + " is not valid")
    # Remove the following, as implemented
    if not ns.config.startswith("linux"):
        raise ValueError(
Amir MOHAMMADI's avatar
Amir MOHAMMADI committed
51
            "only Linux configs currently supported, got {config}".format(config=ns.config)
52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75
        )


def main(args=None):
    p = ArgumentParser("build-locally")
    p.add_argument("config", default=None, nargs="?")
    p.add_argument(
        "--debug",
        action="store_true",
        help="Setup debug environment using `conda debug`",
    )
    p.add_argument(
        "--output-id", help="If running debug, specify the output to setup."
    )

    ns = p.parse_args(args=args)
    verify_config(ns)
    setup_environment(ns)

    run_docker_build(ns)


if __name__ == "__main__":
    main()