diff --git a/bob/devtools/ci.py b/bob/devtools/ci.py index 3fd21a867023b8a311aa81b334259ecd4c53e797..46b0200739e54a41e473eae40dec471fc1f46a85 100644 --- a/bob/devtools/ci.py +++ b/bob/devtools/ci.py @@ -119,3 +119,79 @@ def uniq(seq, idfun=None): seen[marker] = 1 result.append(item) return result + + +def select_build_file(basename, paths, branch): + '''Selects the file to use for a build + + This method will return the name of the most adequate build-accessory file + (conda_build_config.yaml, recipe_append.yaml) for a given build, in this + order of priority: + + 1. The first file found is returned + 2. We first search for a *specific* file if ``branch`` is set + 3. If that file does not exist, returns the unbranded filename if that exists + in one of the paths + 4. If no candidates exists, returns ``None`` + + The candidate filename is built using + ``os.path.splitext(os.path.basename(basename))[0]``. + + Args: + + basename: Name of the file to use for the search + paths (list): A list of paths leading to the location of the variants file + to use. Priority is given to paths that come first + branch (str): Optional key to be set when searching for the variants file + to use. This is typically the git-branch name of the current branch of + the repo being built. + + + Returns: + + str: A string containing the full, resolved path of the file to use. + Returns ``None``, if no candidate is found + + ''' + + import os + + basename, extension = os.path.splitext(os.path.basename(basename)) + + if branch: + specific_basename = '%s-%s' % (basename, branch) + for path in paths: + path = os.path.realpath(path) + candidate = os.path.join(path, '%s%s' % (specific_basename, extension)) + if os.path.exists(candidate): + return candidate + + for path in paths: + path = os.path.realpath(path) + candidate = os.path.join(path, '%s%s' % (basename, extension)) + if os.path.exists(candidate): + return candidate + + +def select_conda_build_config(paths, branch): + '''Selects the default conda_build_config.yaml. + + See :py:func:`select_build_file` for implementation details. If no build + config file is found by :py:func:`select_build_file`, then returns the + default ``conda_build_config.yaml`` shipped with this package. + ''' + + from .constants import CONDA_BUILD_CONFIG as default + return select_build_file(default, paths, branch) or default + + +def select_conda_recipe_append(paths, branch): + '''Selects the default recipe_append.yaml. + + See :py:func:`select_build_file` for implementation details. If no recipe + append file is found by :py:func:`select_build_file`, then returns the + default ``recipe_append.yaml`` shipped with this package. + ''' + + from .constants import CONDA_RECIPE_APPEND as default + return select_build_file(default, paths, branch) or default diff --git a/bob/devtools/scripts/ci.py b/bob/devtools/scripts/ci.py index a4888e337f3d2cc57ffcc671bc46987dade4d7fa..88dd09c799210e42aa3d7ea7765f41f78338fd4e 100644 --- a/bob/devtools/scripts/ci.py +++ b/bob/devtools/scripts/ci.py @@ -11,10 +11,10 @@ import pkg_resources from click_plugins import with_plugins from . import bdt -from ..constants import SERVER, CONDA_BUILD_CONFIG, CONDA_RECIPE_APPEND, \ - WEBDAV_PATHS, BASE_CONDARC +from ..constants import SERVER, WEBDAV_PATHS, BASE_CONDARC from ..deploy import deploy_conda_package, deploy_documentation -from ..ci import read_packages, comment_cleanup, uniq +from ..ci import read_packages, comment_cleanup, uniq, \ + select_conda_build_config, select_conda_recipe_append from ..log import verbosity_option, get_logger, echo_normal logger = get_logger(__name__) @@ -329,14 +329,9 @@ def base_build(order, group, python, dry_run): logger.info('Ignoring directory "%s" - no meta.yaml found' % recipe) continue - # Use custom variants file if available on recipe-dir - variants_file = CONDA_BUILD_CONFIG - _candidate = os.path.join(recipe, 'conda_build_config.yaml') - if os.path.exists(_candidate): - variants_file = _candidate - logger.warn('Using local conda_build_config.yaml from recipe-dir (%s)' \ - 'instead of default variants file (%s)', variants_file, - CONDA_BUILD_CONFIG) + variants_file = select_conda_build_config(paths=[recipe, os.curdir], + branch=os.environ.get('CI_COMMIT_REF_NAME')) + logger.info('Conda build configuration file: %s', variants_file) _build( bootstrap=bootstrap, @@ -380,21 +375,13 @@ def test(ctx, dry_run): # Use custom variants and append files if available on recipe-dir recipe_dir = os.path.join(os.path.realpath(os.curdir), 'conda') - variants_file = CONDA_BUILD_CONFIG - _candidate = os.path.join(recipe_dir, 'conda_build_config.yaml') - if os.path.exists(_candidate): - variants_file = _candidate - logger.warn('Using local conda_build_config.yaml from recipe-dir (%s)' \ - 'instead of default variants file (%s)', variants_file, - CONDA_BUILD_CONFIG) - - append_file = CONDA_RECIPE_APPEND - _candidate = os.path.join(recipe_dir, 'append_file.yaml') - if os.path.exists(_candidate): - append_file = _candidate - logger.warn('Using local recipe_append.yaml from recipe-dir (%s)' \ - 'instead of default append file (%s)', append_file, - CONDA_RECIPE_APPEND) + variants_file = select_conda_build_config(paths=[recipe_dir, os.curdir], + branch=os.environ.get('CI_COMMIT_REF_NAME')) + logger.info('Conda build configuration file: %s', variants_file) + + append_file = select_conda_recipe_append(paths=[recipe_dir, os.curdir], + branch=os.environ.get('CI_COMMIT_REF_NAME')) + logger.info('Conda build recipe-append file: %s', append_file) from .test import test ctx.invoke(test, @@ -442,21 +429,13 @@ def build(ctx, dry_run): # Use custom variants and append files if available on recipe-dir recipe_dir = os.path.join(os.path.realpath(os.curdir), 'conda') - variants_file = CONDA_BUILD_CONFIG - _candidate = os.path.join(recipe_dir, 'conda_build_config.yaml') - if os.path.exists(_candidate): - variants_file = _candidate - logger.warn('Using local conda_build_config.yaml from recipe-dir (%s)' \ - 'instead of default variants file (%s)', variants_file, - CONDA_BUILD_CONFIG) - - append_file = CONDA_RECIPE_APPEND - _candidate = os.path.join(recipe_dir, 'append_file.yaml') - if os.path.exists(_candidate): - append_file = _candidate - logger.warn('Using local recipe_append.yaml from recipe-dir (%s)' \ - 'instead of default append file (%s)', append_file, - CONDA_RECIPE_APPEND) + variants_file = select_conda_build_config(paths=[recipe_dir, os.curdir], + branch=os.environ.get('CI_COMMIT_REF_NAME')) + logger.info('Conda build configuration file: %s', variants_file) + + append_file = select_conda_recipe_append(paths=[recipe_dir, os.curdir], + branch=os.environ.get('CI_COMMIT_REF_NAME')) + logger.info('Conda build recipe-append file: %s', append_file) from .build import build ctx.invoke(build, @@ -573,21 +552,13 @@ def nightlies(ctx, order, dry_run): # Use custom variants and append files if available on recipe-dir recipe_dir = os.path.join(clone_to, 'conda') - variants_file = CONDA_BUILD_CONFIG - _candidate = os.path.join(recipe_dir, 'conda_build_config.yaml') - if os.path.exists(_candidate): - variants_file = _candidate - logger.warn('Using local conda_build_config.yaml from recipe-dir (%s)' \ - 'instead of default variants file (%s)', variants_file, - CONDA_BUILD_CONFIG) - - append_file = CONDA_RECIPE_APPEND - _candidate = os.path.join(recipe_dir, 'append_file.yaml') - if os.path.exists(_candidate): - append_file = _candidate - logger.warn('Using local recipe_append.yaml from recipe-dir (%s)' \ - 'instead of default append file (%s)', append_file, - CONDA_RECIPE_APPEND) + variants_file = select_conda_build_config(paths=[recipe_dir, os.curdir], + branch=os.environ.get('CI_COMMIT_REF_NAME')) + logger.info('Conda build configuration file: %s', variants_file) + + append_file = select_conda_recipe_append(paths=[recipe_dir, os.curdir], + branch=os.environ.get('CI_COMMIT_REF_NAME')) + logger.info('Conda build recipe-append file: %s', append_file) ctx.invoke(build, recipe_dir=[recipe_dir],