Skip to content
Snippets Groups Projects
Commit 77ca0009 authored by André Anjos's avatar André Anjos :speech_balloon:
Browse files

Merge branch 'bob.conda-issue-71' into 'master'

Implements support for specific build-config and recipe-append files

Closes bob.conda#71

See merge request !78
parents 7fe864ec 99f16beb
Branches
Tags
1 merge request!78Implements support for specific build-config and recipe-append files
Pipeline #32279 passed
...@@ -119,3 +119,79 @@ def uniq(seq, idfun=None): ...@@ -119,3 +119,79 @@ def uniq(seq, idfun=None):
seen[marker] = 1 seen[marker] = 1
result.append(item) result.append(item)
return result 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
...@@ -11,10 +11,10 @@ import pkg_resources ...@@ -11,10 +11,10 @@ import pkg_resources
from click_plugins import with_plugins from click_plugins import with_plugins
from . import bdt from . import bdt
from ..constants import SERVER, CONDA_BUILD_CONFIG, CONDA_RECIPE_APPEND, \ from ..constants import SERVER, WEBDAV_PATHS, BASE_CONDARC
WEBDAV_PATHS, BASE_CONDARC
from ..deploy import deploy_conda_package, deploy_documentation 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 from ..log import verbosity_option, get_logger, echo_normal
logger = get_logger(__name__) logger = get_logger(__name__)
...@@ -329,14 +329,9 @@ def base_build(order, group, python, dry_run): ...@@ -329,14 +329,9 @@ def base_build(order, group, python, dry_run):
logger.info('Ignoring directory "%s" - no meta.yaml found' % recipe) logger.info('Ignoring directory "%s" - no meta.yaml found' % recipe)
continue continue
# Use custom variants file if available on recipe-dir variants_file = select_conda_build_config(paths=[recipe, os.curdir],
variants_file = CONDA_BUILD_CONFIG branch=os.environ.get('CI_COMMIT_REF_NAME'))
_candidate = os.path.join(recipe, 'conda_build_config.yaml') logger.info('Conda build configuration file: %s', variants_file)
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)
_build( _build(
bootstrap=bootstrap, bootstrap=bootstrap,
...@@ -380,21 +375,13 @@ def test(ctx, dry_run): ...@@ -380,21 +375,13 @@ def test(ctx, dry_run):
# Use custom variants and append files if available on recipe-dir # Use custom variants and append files if available on recipe-dir
recipe_dir = os.path.join(os.path.realpath(os.curdir), 'conda') recipe_dir = os.path.join(os.path.realpath(os.curdir), 'conda')
variants_file = CONDA_BUILD_CONFIG variants_file = select_conda_build_config(paths=[recipe_dir, os.curdir],
_candidate = os.path.join(recipe_dir, 'conda_build_config.yaml') branch=os.environ.get('CI_COMMIT_REF_NAME'))
if os.path.exists(_candidate): logger.info('Conda build configuration file: %s', variants_file)
variants_file = _candidate
logger.warn('Using local conda_build_config.yaml from recipe-dir (%s)' \ append_file = select_conda_recipe_append(paths=[recipe_dir, os.curdir],
'instead of default variants file (%s)', variants_file, branch=os.environ.get('CI_COMMIT_REF_NAME'))
CONDA_BUILD_CONFIG) logger.info('Conda build recipe-append file: %s', append_file)
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)
from .test import test from .test import test
ctx.invoke(test, ctx.invoke(test,
...@@ -442,21 +429,13 @@ def build(ctx, dry_run): ...@@ -442,21 +429,13 @@ def build(ctx, dry_run):
# Use custom variants and append files if available on recipe-dir # Use custom variants and append files if available on recipe-dir
recipe_dir = os.path.join(os.path.realpath(os.curdir), 'conda') recipe_dir = os.path.join(os.path.realpath(os.curdir), 'conda')
variants_file = CONDA_BUILD_CONFIG variants_file = select_conda_build_config(paths=[recipe_dir, os.curdir],
_candidate = os.path.join(recipe_dir, 'conda_build_config.yaml') branch=os.environ.get('CI_COMMIT_REF_NAME'))
if os.path.exists(_candidate): logger.info('Conda build configuration file: %s', variants_file)
variants_file = _candidate
logger.warn('Using local conda_build_config.yaml from recipe-dir (%s)' \ append_file = select_conda_recipe_append(paths=[recipe_dir, os.curdir],
'instead of default variants file (%s)', variants_file, branch=os.environ.get('CI_COMMIT_REF_NAME'))
CONDA_BUILD_CONFIG) logger.info('Conda build recipe-append file: %s', append_file)
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)
from .build import build from .build import build
ctx.invoke(build, ctx.invoke(build,
...@@ -573,21 +552,13 @@ def nightlies(ctx, order, dry_run): ...@@ -573,21 +552,13 @@ def nightlies(ctx, order, dry_run):
# Use custom variants and append files if available on recipe-dir # Use custom variants and append files if available on recipe-dir
recipe_dir = os.path.join(clone_to, 'conda') recipe_dir = os.path.join(clone_to, 'conda')
variants_file = CONDA_BUILD_CONFIG variants_file = select_conda_build_config(paths=[recipe_dir, os.curdir],
_candidate = os.path.join(recipe_dir, 'conda_build_config.yaml') branch=os.environ.get('CI_COMMIT_REF_NAME'))
if os.path.exists(_candidate): logger.info('Conda build configuration file: %s', variants_file)
variants_file = _candidate
logger.warn('Using local conda_build_config.yaml from recipe-dir (%s)' \ append_file = select_conda_recipe_append(paths=[recipe_dir, os.curdir],
'instead of default variants file (%s)', variants_file, branch=os.environ.get('CI_COMMIT_REF_NAME'))
CONDA_BUILD_CONFIG) logger.info('Conda build recipe-append file: %s', append_file)
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)
ctx.invoke(build, ctx.invoke(build,
recipe_dir=[recipe_dir], recipe_dir=[recipe_dir],
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment