From e6cd21edfb21e0b380294d2290f7f765daf3b158 Mon Sep 17 00:00:00 2001 From: Thomas Sibley Date: Wed, 17 Feb 2021 12:50:43 -0800 Subject: [PATCH] Try to render the recipe again if it requires downloading source Preserves the faster path for most recipes by not downloading source, but now allows recipes to use some of Conda's recipe features which require source (e.g. load_setup_py_data()). --- bioconda_utils/utils.py | 30 +++++++++++++++++++++++++----- 1 file changed, 25 insertions(+), 5 deletions(-) diff --git a/bioconda_utils/utils.py b/bioconda_utils/utils.py index b71c0c506e..b6f6258924 100644 --- a/bioconda_utils/utils.py +++ b/bioconda_utils/utils.py @@ -421,12 +421,32 @@ def load_all_meta(recipe, config=None, finalize=True): # To avoid adding a separate `bypass_env_check` alongside every `finalize` # parameter, just assume we always want to bypass if `finalize is True`. bypass_env_check = (not finalize) - return [meta for (meta, _, _) in api.render(recipe, - config=config, - finalize=finalize, - bypass_env_check=bypass_env_check, - )] + def metas(config): + return [meta for (meta, _, _) in api.render(recipe, + config=config, + finalize=finalize, + bypass_env_check=bypass_env_check, + )] + + try: + return metas(config) + except ValueError as error: + # Try again with downloading allowed if rendering the recipe requires + # downloading the source, e.g. if meta.yaml uses Conda's + # load_setup_py_data() function. The conditional targets the following + # exception: + # + # ValueError: no_download_source specified, but can't fully render + # recipe without downloading source. Please fix the recipe, or + # don't use no_download_source. + # + if str(error).startswith("no_download_source specified"): + logger.warn("Recipe appears to require downloading source; re-trying.") + config.no_download_source = False + return metas(config) + else: + raise def load_meta_fast(recipe: str, env=None):