Commit 29b41ca9 authored by Paul McCarthy's avatar Paul McCarthy 🚵
Browse files

RF: Fix up new build_conda_recipe script, include prebuild logic

parent c54ac0a5
......@@ -4,44 +4,78 @@
#
# Author: Paul McCarthy <pauldmccarthy@gmail.com>
#
# This script must be passed the following aargments:
#
# - Output directory to store built conda package
#
# - Name of the git ref (e.g. tag, branch) to build the
# recipe from. If empty, ref specified in the recipe
# meta.yaml file is used.
#
# - An empty or non-empty value to indicate which
# FSL conda channel URL to download dependencies from.
# If empty, the FSLCONDA_PRODUCTION_CHANNEL_URL is
# used, otherwise the FSLCONDA_STAGING_CHANNEL_URL is
# used.
#
# - All other arguments
#
# (See rules/fsl-ci-conda-rules.yml)
import os
import sys
from fsl_ci_utils import sprun
from fsl_ci_utils import sprun, tempdir
def pre_build_recipe(url, ref, output_dir, *channels):
"""Checks out and builds the recipe at the given URL,
storing the built package in the given destination.
"""
with tempdir():
sprun(f'git clone {url} recipe')
build_recipe('recipe', ref, output_dir, *channels)
def build_recipe(recipe_dir, ref, output_dir, *channels):
"""Build the conda recipe in the given directory. """
env = dict(os.environ)
if ref == '':
env.pop('FSLCONDA_REVISION')
else:
env['FSLCONDA_REVISION'] = ref
cmd = 'conda build -c conda-forge -c defaults'
for chan in channels:
cmd = f'{cmd} -c {chan}'
def pre_build_recipe(url, ref, dest_dir):
pass
sprun(f'{cmd} --output-folder={output_dir} {recipe_dir}', env=env)
def main():
"""Build a conda package from a FSL recipe repository.
This script must be passed the following aargments:
- Output directory to store built conda package
- Name of the git ref (e.g. tag, branch) to build the
recipe from. If empty, ref specified in the recipe
meta.yaml file is used.
- An empty or non-empty value to indicate which
FSL conda channel URL to download dependencies from.
If empty, the FSLCONDA_PRODUCTION_CHANNEL_URL is
used, otherwise the FSLCONDA_STAGING_CHANNEL_URL is
used.
- A string containing one or more recipe repositories,
which should be pre-built and installed as dependencies
of the package being built. This string must have the
form:
"ref1:repo1 ref2:repo2 .."
i.e. each repository comprises a git reference (e.g.
tag, branch), followed by a colon, followed by the
URL to the git repository. Multiple repositories
can be specified by separating them with spaces.
"""
env = dict(os.environ)
output_dir = sys.argv[1]
project_ref = sys.argv[2]
staging = sys.argv[3]
prebuild = sys.argv[4].split()
prebuild = [p.split(';') for p in prebuild]
prebuild = [p.split(':', 1) for p in prebuild]
local_channel = './local_channel'
if staging == '':
......@@ -49,14 +83,11 @@ def main():
else:
channel_url = env['FSLCONDA_STAGING_CHANNEL_URL']
if project_ref == '':
env.pop('FSLCONDA_REVISION')
else:
env['FSLCONDA_REVISION'] = project_ref
os.mkdir(local_channel)
for url, ref in prebuild:
for ref, url in prebuild:
pre_build_recipe(url, ref, local_channel)
sprun(f'conda index {local_channel}')
sprun('conda install -y -c conda-forge conda-build')
print('************************************')
print(f'Building conda recipe for: {env["CI_PROJECT_NAME"]}')
......@@ -66,16 +97,7 @@ def main():
print(f' specified in meta.yaml): {project_ref}')
print(f'FSL conda channel URL: {channel_url}')
print('************************************')
sprun(f'conda index {local_channel}')
sprun('conda install -y -c conda-forge conda-build')
sprun('conda build '
'-c conda-forge '
'-c defaults '
f'-c {local_channel} '
f'-c {channel_url} '
f'--output-folder={output_dir}'
'./', env=env)
build_recipe('.', project_ref, output_dir, local_channel, channel_url)
if __name__ == '__main__':
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment