diff --git a/bob/devtools/build.py b/bob/devtools/build.py index 6084c7ce79fe328a0b579aa9ab6b287852470c22..90fdbdd068807f2d1f4b3053285d3ad2e613ec21 100644 --- a/bob/devtools/build.py +++ b/bob/devtools/build.py @@ -17,20 +17,9 @@ import sys import conda_build.api import yaml -logger = logging.getLogger(__name__) - - -def remove_conda_loggers(): - """Cleans-up conda API logger handlers to avoid logging repetition""" +from .log import root_logger_protection - z = logging.getLogger() # conda places their handlers inside root - if z.handlers: - handler = z.handlers[0] - z.removeHandler(handler) - logger.debug("Removed conda logger handler at %s", handler) - - -remove_conda_loggers() +logger = logging.getLogger(__name__) def comment_cleanup(lines): @@ -98,8 +87,6 @@ def next_build_number(channel_url, basename): from conda.exports import fetch_index from conda.core.index import calculate_channel_urls - remove_conda_loggers() - # get the channel index channel_urls = calculate_channel_urls([channel_url], prepend=False, use_local=False) logger.debug("Downloading channel index from %s", channel_urls) @@ -177,17 +164,15 @@ def make_conda_config(config, python, append_file, condarc_options): conda-build API's ``get_or_merge_config()`` function. """ - from conda_build.conda_interface import url_path - - remove_conda_loggers() - - retval = conda_build.api.get_or_merge_config( - None, - variant_config_files=config, - python=python, - append_sections_file=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, + python=python, + append_sections_file=append_file, + **condarc_options, + ) retval.channel_urls = [] @@ -198,7 +183,8 @@ def make_conda_config(config, python, append_file, condarc_options): 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 = url_path(url) + with root_logger_protection(): + url = url_path(url) retval.channel_urls.append(url) return retval @@ -207,19 +193,22 @@ def make_conda_config(config, python, append_file, condarc_options): def get_output_path(metadata, config): """Renders the recipe and returns the name of the output file.""" - return conda_build.api.get_output_file_paths(metadata, config=config) + with root_logger_protection(): + return conda_build.api.get_output_file_paths(metadata, config=config) def get_rendered_metadata(recipe_dir, config): """Renders the recipe and returns the interpreted YAML file.""" - return conda_build.api.render(recipe_dir, config=config) + with root_logger_protection(): + return conda_build.api.render(recipe_dir, config=config) def get_parsed_recipe(metadata): """Renders the recipe and returns the interpreted YAML file.""" - output = conda_build.api.output_yaml(metadata[0][0]) + with root_logger_protection(): + output = conda_build.api.output_yaml(metadata[0][0]) return yaml.load(output, Loader=yaml.FullLoader) @@ -626,7 +615,8 @@ def base_build( # if you get to this point, just builds the package(s) logger.info("Building %s", recipe_dir) - return conda_build.api.build(recipe_dir, config=conda_config) + with root_logger_protection(): + return conda_build.api.build(recipe_dir, config=conda_config) if __name__ == "__main__": @@ -814,7 +804,8 @@ if __name__ == "__main__": # resolved the "wrong" build number. We'll have to reparse after setting the # environment variable BOB_BUILD_NUMBER. bootstrap.set_environment("BOB_BUILD_NUMBER", str(build_number)) - conda_build.api.build(recipe_dir, config=conda_config) + with root_logger_protection(): + conda_build.api.build(recipe_dir, config=conda_config) # checks if long_description of python package renders fine if args.twine_check: diff --git a/bob/devtools/scripts/build.py b/bob/devtools/scripts/build.py index ff42b74a4b9d1797d3c581400d268a0f6a22b720..df015916e4bb0eab98c276e23e1d3d4842ac799d 100644 --- a/bob/devtools/scripts/build.py +++ b/bob/devtools/scripts/build.py @@ -18,7 +18,6 @@ from ..build import get_parsed_recipe from ..build import get_rendered_metadata from ..build import make_conda_config from ..build import next_build_number -from ..build import remove_conda_loggers from ..build import should_skip_build from ..constants import BASE_CONDARC from ..constants import CONDA_BUILD_CONFIG @@ -30,9 +29,6 @@ from ..log import verbosity_option from ..log import root_logger_protection from . import bdt -remove_conda_loggers() - - logger = get_logger(__name__) @@ -253,8 +249,7 @@ def build( set_environment("BOB_PACKAGE_VERSION", version) # pre-renders the recipe - figures out the destination - with root_logger_protection(): - metadata = get_rendered_metadata(d, conda_config) + metadata = get_rendered_metadata(d, conda_config) # checks if we should actually build this recipe if should_skip_build(metadata): @@ -263,8 +258,7 @@ def build( ) continue - with root_logger_protection(): - rendered_recipe = get_parsed_recipe(metadata) + rendered_recipe = get_parsed_recipe(metadata) logger.debug("Printing rendered recipe") logger.debug("\n" + yaml.dump(rendered_recipe)) diff --git a/bob/devtools/scripts/create.py b/bob/devtools/scripts/create.py index 15a38af05b72dcacffb3900ffde5a051f0fea3cb..0ae47da83249ad0b68b780026c8012731f7204d9 100644 --- a/bob/devtools/scripts/create.py +++ b/bob/devtools/scripts/create.py @@ -3,13 +3,13 @@ import os import sys -import subprocess import click import yaml from ..config import read_config from ..bootstrap import set_environment +from ..bootstrap import run_cmdline from ..build import conda_create from ..build import make_conda_config from ..build import parse_dependencies @@ -20,7 +20,6 @@ from ..constants import SERVER from ..log import echo_normal from ..log import get_logger from ..log import verbosity_option -from ..log import root_logger_protection from . import bdt logger = get_logger(__name__) @@ -269,16 +268,14 @@ def create( conda_config = make_conda_config( config, python, append_file, condarc_options ) - with root_logger_protection(): - deps = parse_dependencies(recipe_dir, conda_config) - # when creating a local development environment, remove the always_yes - # option + deps = parse_dependencies(recipe_dir, conda_config) + # when creating a local development environment, remove the always_yes + # option del condarc_options["always_yes"] - with root_logger_protection(): - conda_create( - conda, name, overwrite, condarc_options, deps, dry_run, use_local - ) + conda_create( + conda, name, overwrite, condarc_options, deps, dry_run, use_local + ) # part 2: pip-install everything listed in pip-extras # mix-in stuff from ~/.bdtrc and command-line @@ -292,7 +289,7 @@ def create( cmd = [conda, "run", "--live-stream", "--name", name, "pip", "install"] cmd += pip_extras if not dry_run: - subprocess.run(cmd, check=True, bufsize=1) + run_cmdline(cmd) else: logger.info(f"Command: {' '.join(cmd)}") diff --git a/bob/devtools/scripts/rebuild.py b/bob/devtools/scripts/rebuild.py index 9da0d337a4b14d8d26927b1116b6b5d810d31a3d..80ebe7f82c88c1e4a0ff6cdfaabc4a3fde496444 100644 --- a/bob/devtools/scripts/rebuild.py +++ b/bob/devtools/scripts/rebuild.py @@ -230,16 +230,14 @@ def rebuild( set_environment("BOB_PACKAGE_VERSION", version) # pre-renders the recipe - figures out the destination - with root_logger_protection(): - metadata = get_rendered_metadata(d, conda_config) + metadata = get_rendered_metadata(d, conda_config) # checks if we should actually build this recipe if should_skip_build(metadata): logger.info("Skipping UNSUPPORTED build of %s for %s", recipe_dir, arch) continue - with root_logger_protection(): - rendered_recipe = get_parsed_recipe(metadata) + rendered_recipe = get_parsed_recipe(metadata) path = get_output_path(metadata, conda_config)[0] diff --git a/bob/devtools/scripts/test.py b/bob/devtools/scripts/test.py index 6c5c5256a7c8b09110bc72ce35cd02ce95a0a6e0..1521ee42e7632ba33a21647104e35574454a3a93 100644 --- a/bob/devtools/scripts/test.py +++ b/bob/devtools/scripts/test.py @@ -12,7 +12,6 @@ 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 remove_conda_loggers from ..constants import BASE_CONDARC from ..constants import CONDA_BUILD_CONFIG from ..constants import CONDA_RECIPE_APPEND @@ -23,9 +22,6 @@ from ..log import verbosity_option from ..log import root_logger_protection from . import bdt -remove_conda_loggers() - - logger = get_logger(__name__)