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

[build] Localize better where to protect from conda root-logger fiddling

parent 52757458
No related branches found
No related tags found
1 merge request!196Fix excessive logging after executing conda functions
Pipeline #45659 failed
......@@ -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:
......
......@@ -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))
......
......@@ -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)}")
......
......@@ -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]
......
......@@ -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__)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment