diff --git a/bob/devtools/build.py b/bob/devtools/build.py index 90fdbdd068807f2d1f4b3053285d3ad2e613ec21..167407341746fae9a30b45b0732be12183f66eca 100644 --- a/bob/devtools/build.py +++ b/bob/devtools/build.py @@ -4,24 +4,38 @@ """Tools for self-building and other utilities.""" -import distutils.version -import glob +import os +import re +import sys import json +import glob +import copy import logging -import os import platform -import re import subprocess -import sys +import contextlib +import distutils.version -import conda_build.api import yaml - -from .log import root_logger_protection +import conda_build.api logger = logging.getLogger(__name__) +@contextlib.contextmanager +def root_logger_protection(): + """Protects the root logger against spurious (conda) manipulation""" + + root_logger = logging.getLogger() + level = root_logger.level + handlers = copy.copy(root_logger.handlers) + + yield + + root_logger.setLevel(level) + root_logger.handlers = handlers + + def comment_cleanup(lines): """Cleans-up comments and empty lines from textual data read from files.""" @@ -88,7 +102,9 @@ def next_build_number(channel_url, basename): from conda.core.index import calculate_channel_urls # get the channel index - channel_urls = calculate_channel_urls([channel_url], prepend=False, use_local=False) + channel_urls = calculate_channel_urls( + [channel_url], prepend=False, use_local=False + ) logger.debug("Downloading channel index from %s", channel_urls) index = fetch_index(channel_urls=channel_urls) @@ -99,7 +115,8 @@ def next_build_number(channel_url, basename): name, version, build = basename[:-6].rsplit("-", 2) else: raise RuntimeError( - "Package name %s does not end in either " ".tar.bz2 or .conda" % (basename,) + "Package name %s does not end in either " + ".tar.bz2 or .conda" % (basename,) ) # remove the build number as we're looking for the next value @@ -135,7 +152,11 @@ def next_build_number(channel_url, basename): ): # match! url = index[dist].url logger.debug( - "Found match at %s for %s-%s-%s", url, name, version, build_variant, + "Found match at %s for %s-%s-%s", + url, + name, + version, + build_variant, ) build_number = max(build_number, dist.build_number + 1) urls[index[dist].timestamp] = url.replace(channel_url, "") @@ -166,6 +187,7 @@ def make_conda_config(config, python, append_file, condarc_options): with root_logger_protection(): from conda_build.conda_interface import url_path + retval = conda_build.api.get_or_merge_config( None, variant_config_files=config, @@ -182,7 +204,9 @@ def make_conda_config(config, python, append_file, condarc_options): # appropriate platform-specific subdir (e.g. win-64) if os.path.isdir(url): if not os.path.isabs(url): - url = os.path.normpath(os.path.abspath(os.path.join(os.getcwd(), url))) + url = os.path.normpath( + os.path.abspath(os.path.join(os.getcwd(), url)) + ) with root_logger_protection(): url = url_path(url) retval.channel_urls.append(url) @@ -240,7 +264,8 @@ def exists_on_channel(channel_url, basename): name, version, build = name[:-8].rsplit("-", 2) else: raise RuntimeError( - "Package name %s does not end in either " ".tar.bz2 or .conda" % (name,) + "Package name %s does not end in either " + ".tar.bz2 or .conda" % (name,) ) # remove the build number as we're looking for the next value @@ -279,11 +304,15 @@ def parse_dependencies(recipe_dir, config): + remove_pins(recipe["requirements"].get("host", [])) + recipe["requirements"].get("run", []) + recipe.get("test", {}).get("requires", []) - + ["bob.buildout"] #required for basic bootstrap of most recipes - + ["ipython"] #for ipdb + + ["bob.buildout"] # required for basic bootstrap of most recipes + + ["ipython"] # for ipdb # Also add anaconda compilers to make sure source installed packages are # compiled properly - + ["clangxx_osx-64" if platform.system() == "Darwin" else "gxx_linux-64"] + + [ + "clangxx_osx-64" + if platform.system() == "Darwin" + else "gxx_linux-64" + ] ) # by last, packages required for local dev @@ -418,7 +447,8 @@ def get_docserver_setup(public, stable, server, intranet, group): if (not public) and (not intranet): raise RuntimeError( "You cannot request for private channels and set" - " intranet=False (server=%s) - these are conflicting options" % server + " intranet=False (server=%s) - these are conflicting options" + % server ) entries = [] @@ -442,7 +472,9 @@ def get_docserver_setup(public, stable, server, intranet, group): server + prefix + "/docs/" + group + "/%(name)s/stable/", ] else: - entries += [server + prefix + "/docs/" + group + "/%(name)s/master/"] + entries += [ + server + prefix + "/docs/" + group + "/%(name)s/master/" + ] return "|".join(entries) @@ -479,7 +511,8 @@ def check_version(workdir, envtag): '"version.txt" indicates version is a ' 'pre-release (v%s) - but environment provided tag "%s", ' "which indicates this is a **stable** build. " - "Have you created the tag using ``bdt release``?" % (version, envtag) + "Have you created the tag using ``bdt release``?" + % (version, envtag) ) else: # it is a stable build if envtag is None: @@ -532,11 +565,20 @@ def git_clean_build(runner, verbose): if not verbose: flags += "q" - runner(["git", "clean", flags] + ["--exclude=%s" % k for k in exclude_from_cleanup]) + runner( + ["git", "clean", flags] + + ["--exclude=%s" % k for k in exclude_from_cleanup] + ) def base_build( - bootstrap, server, intranet, group, recipe_dir, conda_build_config, condarc_options, + bootstrap, + server, + intranet, + group, + recipe_dir, + conda_build_config, + condarc_options, ): """Builds a non-beat/non-bob software dependence that doesn't exist on defaults. @@ -583,18 +625,24 @@ def base_build( "\n - ".join(condarc_options["channels"]), ) logger.info("Merging conda configuration files...") - conda_config = make_conda_config(conda_build_config, None, None, condarc_options) + conda_config = make_conda_config( + conda_build_config, None, None, condarc_options + ) metadata = get_rendered_metadata(recipe_dir, conda_config) arch = conda_arch() # checks we should actually build this recipe if should_skip_build(metadata): - logger.warn('Skipping UNSUPPORTED build of "%s" on %s', recipe_dir, arch) + logger.warn( + 'Skipping UNSUPPORTED build of "%s" on %s', recipe_dir, arch + ) return paths = get_output_path(metadata, conda_config) - urls = [exists_on_channel(upload_channel, os.path.basename(k)) for k in paths] + urls = [ + exists_on_channel(upload_channel, os.path.basename(k)) for k in paths + ] if all(urls): logger.info( @@ -623,7 +671,9 @@ if __name__ == "__main__": import argparse - parser = argparse.ArgumentParser(description="Builds bob.devtools on the CI") + parser = argparse.ArgumentParser( + description="Builds bob.devtools on the CI" + ) parser.add_argument( "-g", "--group", @@ -642,7 +692,8 @@ if __name__ == "__main__": default=os.environ.get( "CONDA_ROOT", os.path.realpath(os.path.join(os.curdir, "miniconda")) ), - help="The location where we should install miniconda " "[default: %(default)s]", + help="The location where we should install miniconda " + "[default: %(default)s]", ) parser.add_argument( "-V", @@ -722,7 +773,9 @@ if __name__ == "__main__": bootstrap.set_environment("BOB_PACKAGE_VERSION", version) # create the build configuration - conda_build_config = os.path.join(args.work_dir, "conda", "conda_build_config.yaml") + conda_build_config = os.path.join( + args.work_dir, "conda", "conda_build_config.yaml" + ) recipe_append = os.path.join(args.work_dir, "data", "recipe_append.yaml") condarc = os.path.join(args.conda_root, "condarc") @@ -786,7 +839,8 @@ if __name__ == "__main__": "typically means this build is running on a shared builder and " "the file ~/.conda/environments.txt is polluted with other " "environment paths. To fix, empty that file and set its mode " - "to read-only for all." % (path, os.path.join(args.conda_root, "conda-bld")) + "to read-only for all." + % (path, os.path.join(args.conda_root, "conda-bld")) ) # retrieve the current build number(s) for this build diff --git a/bob/devtools/log.py b/bob/devtools/log.py index a6f70c4d42c39c12cd80439503f2959f1f322ad4..8e55848371cb742b68a33e151648e99b1301bea1 100644 --- a/bob/devtools/log.py +++ b/bob/devtools/log.py @@ -6,7 +6,6 @@ import os import sys import logging -import contextlib import click import termcolor @@ -244,19 +243,3 @@ def verbosity_option(**kwargs): )(f) return custom_verbosity_option - - -@contextlib.contextmanager -def root_logger_protection(): - """Protects the root logger against spurious (conda) manipulation""" - - import copy - - root_logger = logging.getLogger() - level = root_logger.level - handlers = copy.copy(root_logger.handlers) - - yield - - root_logger.setLevel(level) - root_logger.handlers = handlers diff --git a/bob/devtools/scripts/build.py b/bob/devtools/scripts/build.py index df015916e4bb0eab98c276e23e1d3d4842ac799d..d436c5931bb39fecb083c43a423ff34d28fe79fa 100644 --- a/bob/devtools/scripts/build.py +++ b/bob/devtools/scripts/build.py @@ -19,6 +19,7 @@ from ..build import get_rendered_metadata from ..build import make_conda_config from ..build import next_build_number from ..build import should_skip_build +from ..build import root_logger_protection from ..constants import BASE_CONDARC from ..constants import CONDA_BUILD_CONFIG from ..constants import CONDA_RECIPE_APPEND @@ -26,7 +27,6 @@ from ..constants import MATPLOTLIB_RCDIR from ..constants import SERVER from ..log import get_logger from ..log import verbosity_option -from ..log import root_logger_protection from . import bdt logger = get_logger(__name__) diff --git a/bob/devtools/scripts/rebuild.py b/bob/devtools/scripts/rebuild.py index 80ebe7f82c88c1e4a0ff6cdfaabc4a3fde496444..92457ca747430ffbf1f38d01f7215912f3681d4e 100644 --- a/bob/devtools/scripts/rebuild.py +++ b/bob/devtools/scripts/rebuild.py @@ -20,6 +20,7 @@ from ..build import get_rendered_metadata from ..build import make_conda_config from ..build import next_build_number from ..build import should_skip_build +from ..build import root_logger_protection from ..constants import BASE_CONDARC from ..constants import CONDA_BUILD_CONFIG from ..constants import CONDA_RECIPE_APPEND @@ -27,7 +28,6 @@ from ..constants import MATPLOTLIB_RCDIR from ..constants import SERVER from ..log import get_logger from ..log import verbosity_option -from ..log import root_logger_protection from . import bdt logger = get_logger(__name__) diff --git a/bob/devtools/scripts/test.py b/bob/devtools/scripts/test.py index 1521ee42e7632ba33a21647104e35574454a3a93..076d6d9b0f43ad9d5cafd45db9ae28acc57b5a29 100644 --- a/bob/devtools/scripts/test.py +++ b/bob/devtools/scripts/test.py @@ -12,6 +12,7 @@ from ..build import conda_arch from ..build import get_docserver_setup from ..build import get_env_directory from ..build import make_conda_config +from ..build import root_logger_protection from ..constants import BASE_CONDARC from ..constants import CONDA_BUILD_CONFIG from ..constants import CONDA_RECIPE_APPEND @@ -19,7 +20,6 @@ from ..constants import MATPLOTLIB_RCDIR from ..constants import SERVER from ..log import get_logger from ..log import verbosity_option -from ..log import root_logger_protection from . import bdt logger = get_logger(__name__)