build-locally.py 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. #!/usr/bin/env python3
  2. #
  3. # This file has been generated by conda-smithy in order to build the recipe
  4. # locally.
  5. #
  6. import os
  7. import glob
  8. import subprocess
  9. from argparse import ArgumentParser
  10. def setup_environment(ns):
  11. os.environ["CONFIG"] = ns.config
  12. os.environ["UPLOAD_PACKAGES"] = "False"
  13. def run_docker_build(ns):
  14. script = ".scripts/run_docker_build.sh"
  15. subprocess.check_call([script])
  16. def verify_config(ns):
  17. valid_configs = {
  18. os.path.basename(f)[:-5] for f in glob.glob(".ci_support/*.yaml")
  19. }
  20. print(f"valid configs are {valid_configs}")
  21. if ns.config in valid_configs:
  22. print("Using " + ns.config + " configuration")
  23. return
  24. elif len(valid_configs) == 1:
  25. ns.config = valid_configs.pop()
  26. print("Found " + ns.config + " configuration")
  27. elif ns.config is None:
  28. print("config not selected, please choose from the following:\n")
  29. selections = list(enumerate(sorted(valid_configs), 1))
  30. for i, c in selections:
  31. print(f"{i}. {c}")
  32. s = input("\n> ")
  33. idx = int(s) - 1
  34. ns.config = selections[idx][1]
  35. print(f"selected {ns.config}")
  36. else:
  37. raise ValueError("config " + ns.config + " is not valid")
  38. # Remove the following, as implemented
  39. if not ns.config.startswith("linux"):
  40. raise ValueError(
  41. f"only Linux configs currently supported, got {ns.config}"
  42. )
  43. def main(args=None):
  44. p = ArgumentParser("build-locally")
  45. p.add_argument("config", default=None, nargs="?")
  46. ns = p.parse_args(args=args)
  47. verify_config(ns)
  48. setup_environment(ns)
  49. run_docker_build(ns)
  50. if __name__ == "__main__":
  51. main()