Skip to content

Commit

Permalink
Merge pull request #80 from CDAT/build_tool_update.2
Browse files Browse the repository at this point in the history
Build tool update.2 --- use **kwargs
  • Loading branch information
muryanto1 authored Jun 15, 2020
2 parents 40b4769 + b4ba8af commit 1a27857
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 57 deletions.
38 changes: 13 additions & 25 deletions build_tools/conda_build.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,7 @@
import glob
import argparse
import os
import sys
import subprocess
import shlex
import shutil
import requests
import time
import re

from Utils import run_cmd, run_cmds, run_cmd_capture_output
from Utils import SUCCESS, FAILURE
Expand Down Expand Up @@ -57,7 +51,7 @@

parser.add_argument("-p", "--package_name",
help="Package name to build")
parser.add_argument("-o", "--github_organization_name",
parser.add_argument("-o", "--organization",
help="github organization name", default="CDAT")
parser.add_argument("-r", "--repo_name",
help="repo name to build")
Expand Down Expand Up @@ -95,14 +89,6 @@
print("Local repository {} does not exist".format(local_repo))
sys.exit(FAILURE)

if args.repo_name:
repo_name = args.repo_name
else:
repo_name = pkg_name

# github organization of projects
organization = args.github_organization_name

status = FAILURE

# for calling run_cmds
Expand All @@ -129,6 +115,10 @@ def construct_pkg_ver(repo_dir, arg_version, arg_last_stable):

kwargs = vars(args)
kwargs["conda_activate"] = args.conda_activate or find_conda_activate()
if kwargs["repo_name"] is None:
kwargs["repo_name"] = pkg_name

repo_name = kwargs["repo_name"]

if kwargs["conda_activate"] is None or not os.path.exists(kwargs["conda_activate"]):
print("Could not find conda activate script, try passing with --conda_activate argument and check file exists")
Expand All @@ -142,7 +132,7 @@ def construct_pkg_ver(repo_dir, arg_version, arg_last_stable):

if args.do_rerender:
if local_repo is None:
ret, repo_dir = clone_repo(organization, repo_name, branch, workdir)
ret, repo_dir = clone_repo(**kwargs)
if ret != SUCCESS:
sys.exit(ret)
else:
Expand All @@ -157,28 +147,26 @@ def construct_pkg_ver(repo_dir, arg_version, arg_last_stable):

if is_conda_forge_pkg:
if args.do_rerender:
status = clone_feedstock(pkg_name, workdir)
status = clone_feedstock(**kwargs)
if status != SUCCESS:
sys.exit(status)

status = prepare_recipe_in_local_feedstock_repo(pkg_name=pkg_name, organization=organization, repo_dir=repo_dir, pkg_version=version, **kwargs)
status = prepare_recipe_in_local_feedstock_repo(pkg_version=version, repo_dir=repo_dir, **kwargs)
if status != SUCCESS:
sys.exit(status)

status = copy_file_from_repo_recipe(pkg_name, repo_dir, workdir,
"conda_build_config.yaml")
status = copy_file_from_repo_recipe(repo_dir=repo_dir, filename="conda_build_config.yaml", **kwargs)
if status != SUCCESS:
sys.exit(status)

status = copy_file_from_repo_recipe(pkg_name, repo_dir, workdir,
"build.sh")
status = copy_file_from_repo_recipe(repo_dir=repo_dir, filename="build.sh", **kwargs)
if status != SUCCESS:
sys.exit(status)

status = rerender_in_local_feedstock(pkg_name=pkg_name, **kwargs)
status = rerender_in_local_feedstock(**kwargs)

if args.do_build:
status = build_in_local_feedstock(pkg_name=pkg_name, py_version=args.build_version, **kwargs)
status = build_in_local_feedstock(**kwargs)

else:
print("Building non conda-forge package")
Expand All @@ -200,7 +188,7 @@ def construct_pkg_ver(repo_dir, arg_version, arg_last_stable):
feedstock_dir = os.path.join(workdir, "{}-feedstock".format(pkg_name))

if args.do_build:
status = build_in_local_repo(repo_dir=feedstock_dir, py_version=args.build_version, **kwargs)
status = build_in_local_repo(repo_dir=feedstock_dir, **kwargs)

sys.exit(status)

Expand Down
49 changes: 17 additions & 32 deletions build_tools/release_tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,8 +118,8 @@ def check_if_conda_forge_pkg(pkg_name):
print("{p} is not a conda-forge package".format(p=pkg_name))
return False

def clone_feedstock(pkg_name, workdir):
pkg_feedstock = "{p}-feedstock".format(p=pkg_name)
def clone_feedstock(package_name, workdir, **kwargs):
pkg_feedstock = "{p}-feedstock".format(p=package_name)
conda_forge_pkg_feedstock = "conda-forge/{p}".format(p=pkg_feedstock)

feedstock_repo_dir = os.path.join(workdir, pkg_feedstock)
Expand All @@ -132,7 +132,7 @@ def clone_feedstock(pkg_name, workdir):

return ret

def clone_repo(organization, repo_name, branch, workdir):
def clone_repo(organization, repo_name, branch, workdir, **kwargs):
repo_dir = os.path.join(workdir, repo_name)
if os.path.exists(repo_dir):
shutil.rmtree(repo_dir)
Expand All @@ -148,10 +148,10 @@ def clone_repo(organization, repo_name, branch, workdir):

return ret, repo_dir

def prepare_recipe_in_local_feedstock_repo(pkg_name, organization, repo_name, branch, pkg_version, build, repo_dir, workdir, local_repo, **kwargs):
def prepare_recipe_in_local_feedstock_repo(package_name, organization, repo_name, branch, pkg_version, build, repo_dir, workdir, local_repo, **kwargs):
repo_url = "https://github.com/{o}/{r}.git\n\n".format(o=organization,r=repo_name)

pkg_feedstock = "{p}-feedstock".format(p=pkg_name)
pkg_feedstock = "{p}-feedstock".format(p=package_name)
feedstock_dir = os.path.join(workdir, pkg_feedstock)
recipe_file = os.path.join(feedstock_dir, 'recipe', 'meta.yaml')

Expand Down Expand Up @@ -184,7 +184,7 @@ def prepare_recipe_in_local_feedstock_repo(pkg_name, organization, repo_name, br
if match_obj:
start_copy = False
output_fh.write("package:\n")
output_fh.write(" name: {n}\n".format(n=pkg_name))
output_fh.write(" name: {n}\n".format(n=package_name))
output_fh.write(" version: {v}\n\n".format(v=pkg_version))

output_fh.write("source:\n")
Expand Down Expand Up @@ -246,29 +246,13 @@ def prepare_recipe_in_local_repo(branch, build, version, repo_dir, local_repo, *

return SUCCESS

def copy_conda_config_yaml(pkg_name, repo_dir, workdir):
config = os.path.join(repo_dir, "recipe", "conda_build_config.yaml")
if os.path.isfile(config):
print("{c} exists in repo".format(c=config))
pkg_feedstock = "{p}-feedstock".format(p=pkg_name)
feedstock_recipe_dir = os.path.join(workdir, pkg_feedstock, "recipe")
cmd = "cp {c} {d}".format(c=config,
d=feedstock_recipe_dir)
#print("CMD: {c}".format(c=cmd))
#os.system(cmd)
ret = run_cmd(cmd, join_stderr, shell_cmd, verbose, workdir)

else:
print("No {c} in repo".format(c=config))
return SUCCESS

def copy_file_from_repo_recipe(pkg_name, repo_dir, workdir, filename):
def copy_file_from_repo_recipe(package_name, repo_dir, workdir, filename, **kwargs):

ret = SUCCESS
the_file = os.path.join(repo_dir, "recipe", filename)
if os.path.isfile(the_file):
print("{f} exists in repo".format(f=the_file))
pkg_feedstock = "{p}-feedstock".format(p=pkg_name)
pkg_feedstock = "{p}-feedstock".format(p=package_name)
feedstock_recipe_dir = os.path.join(workdir, pkg_feedstock, "recipe")
cmd = "cp {f} {d}".format(f=the_file,
d=feedstock_recipe_dir)
Expand Down Expand Up @@ -299,7 +283,8 @@ def rerender(conda_activate, conda_env, conda_rc, dir, **kwargs):
return ret

def do_build(conda_activate, conda_env, conda_rc, dir, py_version, copy_conda_package, **kwargs):
print("...do_build..., py_version: {v}".format(v=py_version))
print("...do_build..., py_version: {v}, dir: {d}".format(v=py_version,
d=dir))
ret = SUCCESS
env = {"CONDARC": conda_rc}
variant_files_dir = os.path.join(dir, ".ci_support")
Expand Down Expand Up @@ -332,20 +317,20 @@ def do_build(conda_activate, conda_env, conda_rc, dir, py_version, copy_conda_pa

return ret

def rerender_in_local_feedstock(pkg_name, workdir, **kwargs):
pkg_feedstock = "{p}-feedstock".format(p=pkg_name)
def rerender_in_local_feedstock(package_name, workdir, **kwargs):
pkg_feedstock = "{p}-feedstock".format(p=package_name)
repo_dir = os.path.join(workdir, pkg_feedstock)

ret = rerender(dir=repo_dir, **kwargs)
if ret != SUCCESS:
print("FAIL...rerender in {d}".format(d=repo_dir))
return ret

def build_in_local_feedstock(pkg_name, workdir, py_version, **kwargs):
pkg_feedstock = "{p}-feedstock".format(p=pkg_name)
def build_in_local_feedstock(package_name, workdir, build_version, **kwargs):
pkg_feedstock = "{p}-feedstock".format(p=package_name)
repo_dir = os.path.join(workdir, pkg_feedstock)

ret = do_build(dir=repo_dir, py_version=py_version, **kwargs)
ret = do_build(dir=repo_dir, py_version=build_version, **kwargs)
return ret

def rerender_in_local_repo(repo_dir, **kwargs):
Expand All @@ -361,10 +346,10 @@ def rerender_in_local_repo(repo_dir, **kwargs):
ret = update_variant_files(repo_dir)
return ret

def build_in_local_repo(repo_dir, py_version, **kwargs):
def build_in_local_repo(repo_dir, build_version, **kwargs):

print("...build_in_local_repo...")
ret = do_build(dir=repo_dir, py_version=py_version, **kwargs)
ret = do_build(dir=repo_dir, py_version=build_version, **kwargs)
return ret

def find_conda_activate():
Expand Down

0 comments on commit 1a27857

Please sign in to comment.