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

[log] Fix excessive logging after loading conda modules

parent f7ae91f3
No related branches found
No related tags found
1 merge request!196Fix excessive logging after executing conda functions
Pipeline #45658 passed
...@@ -3,9 +3,10 @@ ...@@ -3,9 +3,10 @@
"""Logging utilities.""" """Logging utilities."""
import logging
import os import os
import sys import sys
import logging
import contextlib
import click import click
import termcolor import termcolor
...@@ -243,3 +244,19 @@ def verbosity_option(**kwargs): ...@@ -243,3 +244,19 @@ def verbosity_option(**kwargs):
)(f) )(f)
return custom_verbosity_option 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
...@@ -27,6 +27,7 @@ from ..constants import MATPLOTLIB_RCDIR ...@@ -27,6 +27,7 @@ from ..constants import MATPLOTLIB_RCDIR
from ..constants import SERVER from ..constants import SERVER
from ..log import get_logger from ..log import get_logger
from ..log import verbosity_option from ..log import verbosity_option
from ..log import root_logger_protection
from . import bdt from . import bdt
remove_conda_loggers() remove_conda_loggers()
...@@ -70,7 +71,9 @@ Examples: ...@@ -70,7 +71,9 @@ Examples:
help="Version of python to build the environment for", help="Version of python to build the environment for",
) )
@click.option( @click.option(
"-r", "--condarc", help="Use custom conda configuration file instead of our own", "-r",
"--condarc",
help="Use custom conda configuration file instead of our own",
) )
@click.option( @click.option(
"-m", "-m",
...@@ -81,7 +84,10 @@ Examples: ...@@ -81,7 +84,10 @@ Examples:
help="overwrites the path leading to " "variant configuration file to use", help="overwrites the path leading to " "variant configuration file to use",
) )
@click.option( @click.option(
"-n", "--no-test", is_flag=True, help="Do not test the package, only builds it", "-n",
"--no-test",
is_flag=True,
help="Do not test the package, only builds it",
) )
@click.option( @click.option(
"-a", "-a",
...@@ -191,7 +197,11 @@ def build( ...@@ -191,7 +197,11 @@ def build(
condarc_options = yaml.load(BASE_CONDARC, Loader=yaml.FullLoader) condarc_options = yaml.load(BASE_CONDARC, Loader=yaml.FullLoader)
channels, upload_channel = get_channels( channels, upload_channel = get_channels(
public=(not private), stable=stable, server=server, intranet=ci, group=group, public=(not private),
stable=stable,
server=server,
intranet=ci,
group=group,
) )
if "channels" not in condarc_options: if "channels" not in condarc_options:
...@@ -208,7 +218,9 @@ def build( ...@@ -208,7 +218,9 @@ def build(
prefix = get_env_directory(os.environ["CONDA_EXE"], "base") prefix = get_env_directory(os.environ["CONDA_EXE"], "base")
condarc_options["croot"] = os.path.join(prefix, "conda-bld") condarc_options["croot"] = os.path.join(prefix, "conda-bld")
conda_config = make_conda_config(config, python, append_file, condarc_options) conda_config = make_conda_config(
config, python, append_file, condarc_options
)
set_environment("MATPLOTLIBRC", MATPLOTLIB_RCDIR) set_environment("MATPLOTLIBRC", MATPLOTLIB_RCDIR)
...@@ -216,7 +228,11 @@ def build( ...@@ -216,7 +228,11 @@ def build(
# and derived documentation building via Sphinx) # and derived documentation building via Sphinx)
set_environment("DOCSERVER", server) set_environment("DOCSERVER", server)
doc_urls = get_docserver_setup( doc_urls = get_docserver_setup(
public=(not private), stable=stable, server=server, intranet=ci, group=group, public=(not private),
stable=stable,
server=server,
intranet=ci,
group=group,
) )
set_environment("BOB_DOCUMENTATION_SERVER", doc_urls) set_environment("BOB_DOCUMENTATION_SERVER", doc_urls)
...@@ -224,7 +240,6 @@ def build( ...@@ -224,7 +240,6 @@ def build(
set_environment("NOSE_EVAL_ATTR", test_mark_expr) set_environment("NOSE_EVAL_ATTR", test_mark_expr)
set_environment("PYTEST_ADDOPTS", f"-m '{test_mark_expr}'") set_environment("PYTEST_ADDOPTS", f"-m '{test_mark_expr}'")
arch = conda_arch() arch = conda_arch()
for d in recipe_dir: for d in recipe_dir:
...@@ -238,21 +253,28 @@ def build( ...@@ -238,21 +253,28 @@ def build(
set_environment("BOB_PACKAGE_VERSION", version) set_environment("BOB_PACKAGE_VERSION", version)
# pre-renders the recipe - figures out the destination # pre-renders the recipe - figures out the destination
metadata = get_rendered_metadata(d, conda_config) with root_logger_protection():
metadata = get_rendered_metadata(d, conda_config)
# checks if we should actually build this recipe # checks if we should actually build this recipe
if should_skip_build(metadata): if should_skip_build(metadata):
logger.info("Skipping UNSUPPORTED build of %s for %s", recipe_dir, arch) logger.info(
"Skipping UNSUPPORTED build of %s for %s", recipe_dir, arch
)
continue continue
rendered_recipe = get_parsed_recipe(metadata) with root_logger_protection():
rendered_recipe = get_parsed_recipe(metadata)
logger.debug("Printing rendered recipe") logger.debug("Printing rendered recipe")
logger.debug("\n" + yaml.dump(rendered_recipe)) logger.debug("\n" + yaml.dump(rendered_recipe))
logger.debug("Finished printing rendered recipe") logger.debug("Finished printing rendered recipe")
path = get_output_path(metadata, conda_config)[0] path = get_output_path(metadata, conda_config)[0]
# gets the next build number # gets the next build number
build_number, _ = next_build_number(upload_channel, os.path.basename(path)) build_number, _ = next_build_number(
upload_channel, os.path.basename(path)
)
logger.info( logger.info(
"Building %s-%s-py%s (build: %d) for %s", "Building %s-%s-py%s (build: %d) for %s",
...@@ -267,7 +289,10 @@ def build( ...@@ -267,7 +289,10 @@ def build(
# set $BOB_BUILD_NUMBER and force conda_build to reparse recipe to # set $BOB_BUILD_NUMBER and force conda_build to reparse recipe to
# get it right # get it right
set_environment("BOB_BUILD_NUMBER", str(build_number)) set_environment("BOB_BUILD_NUMBER", str(build_number))
paths = conda_build.api.build(d, config=conda_config, notest=no_test) with root_logger_protection():
paths = conda_build.api.build(
d, config=conda_config, notest=no_test
)
# if you get to this point, the package was successfully rebuilt # if you get to this point, the package was successfully rebuilt
# set environment to signal caller we may dispose of it # set environment to signal caller we may dispose of it
os.environ["BDT_BUILD"] = ":".join(paths) os.environ["BDT_BUILD"] = ":".join(paths)
...@@ -20,6 +20,7 @@ from ..constants import SERVER ...@@ -20,6 +20,7 @@ from ..constants import SERVER
from ..log import echo_normal from ..log import echo_normal
from ..log import get_logger from ..log import get_logger
from ..log import verbosity_option from ..log import verbosity_option
from ..log import root_logger_protection
from . import bdt from . import bdt
logger = get_logger(__name__) logger = get_logger(__name__)
...@@ -95,7 +96,8 @@ Examples: ...@@ -95,7 +96,8 @@ Examples:
"--python", "--python",
default=("%d.%d" % sys.version_info[:2]), default=("%d.%d" % sys.version_info[:2]),
show_default=True, show_default=True,
help="Version of python to build the " "environment for [default: %(default)s]", help="Version of python to build the "
"environment for [default: %(default)s]",
) )
@click.option( @click.option(
"-o", "-o",
...@@ -106,7 +108,9 @@ Examples: ...@@ -106,7 +108,9 @@ Examples:
show_default=True, show_default=True,
) )
@click.option( @click.option(
"-r", "--condarc", help="Use custom conda configuration file instead of our own", "-r",
"--condarc",
help="Use custom conda configuration file instead of our own",
) )
@click.option( @click.option(
"-l", "-l",
...@@ -262,11 +266,19 @@ def create( ...@@ -262,11 +266,19 @@ def create(
"\n - ".join(condarc_options["channels"]), "\n - ".join(condarc_options["channels"]),
) )
conda_config = make_conda_config(config, python, append_file, condarc_options) conda_config = make_conda_config(
deps = parse_dependencies(recipe_dir, conda_config) config, python, append_file, condarc_options
# when creating a local development environment, remove the always_yes option )
with root_logger_protection():
deps = parse_dependencies(recipe_dir, conda_config)
# when creating a local development environment, remove the always_yes
# option
del condarc_options["always_yes"] del condarc_options["always_yes"]
conda_create(conda, name, overwrite, condarc_options, deps, dry_run, use_local) with root_logger_protection():
conda_create(
conda, name, overwrite, condarc_options, deps, dry_run, use_local
)
# part 2: pip-install everything listed in pip-extras # part 2: pip-install everything listed in pip-extras
# mix-in stuff from ~/.bdtrc and command-line # mix-in stuff from ~/.bdtrc and command-line
...@@ -284,4 +296,4 @@ def create( ...@@ -284,4 +296,4 @@ def create(
else: else:
logger.info(f"Command: {' '.join(cmd)}") logger.info(f"Command: {' '.join(cmd)}")
echo_normal(f">>> Execute on your shell: \"conda activate {name}\"") echo_normal(f'>>> Execute on your shell: "conda activate {name}"')
...@@ -27,6 +27,7 @@ from ..constants import MATPLOTLIB_RCDIR ...@@ -27,6 +27,7 @@ from ..constants import MATPLOTLIB_RCDIR
from ..constants import SERVER from ..constants import SERVER
from ..log import get_logger from ..log import get_logger
from ..log import verbosity_option from ..log import verbosity_option
from ..log import root_logger_protection
from . import bdt from . import bdt
logger = get_logger(__name__) logger = get_logger(__name__)
...@@ -229,14 +230,17 @@ def rebuild( ...@@ -229,14 +230,17 @@ def rebuild(
set_environment("BOB_PACKAGE_VERSION", version) set_environment("BOB_PACKAGE_VERSION", version)
# pre-renders the recipe - figures out the destination # pre-renders the recipe - figures out the destination
metadata = get_rendered_metadata(d, conda_config) with root_logger_protection():
metadata = get_rendered_metadata(d, conda_config)
# checks if we should actually build this recipe # checks if we should actually build this recipe
if should_skip_build(metadata): if should_skip_build(metadata):
logger.info("Skipping UNSUPPORTED build of %s for %s", recipe_dir, arch) logger.info("Skipping UNSUPPORTED build of %s for %s", recipe_dir, arch)
continue continue
rendered_recipe = get_parsed_recipe(metadata) with root_logger_protection():
rendered_recipe = get_parsed_recipe(metadata)
path = get_output_path(metadata, conda_config)[0] path = get_output_path(metadata, conda_config)[0]
# Get the latest build number # Get the latest build number
...@@ -261,7 +265,8 @@ def rebuild( ...@@ -261,7 +265,8 @@ def rebuild(
# rebuild the package or not # rebuild the package or not
logger.info("Testing %s", src) logger.info("Testing %s", src)
try: try:
result = conda_build.api.test(destpath, config=conda_config) with root_logger_protection():
result = conda_build.api.test(destpath, config=conda_config)
should_build = not result should_build = not result
except Exception as error: except Exception as error:
logger.exception(error) logger.exception(error)
......
...@@ -20,6 +20,7 @@ from ..constants import MATPLOTLIB_RCDIR ...@@ -20,6 +20,7 @@ from ..constants import MATPLOTLIB_RCDIR
from ..constants import SERVER from ..constants import SERVER
from ..log import get_logger from ..log import get_logger
from ..log import verbosity_option from ..log import verbosity_option
from ..log import root_logger_protection
from . import bdt from . import bdt
remove_conda_loggers() remove_conda_loggers()
...@@ -202,4 +203,5 @@ def test( ...@@ -202,4 +203,5 @@ def test(
for p in package: for p in package:
logger.info("Testing %s at %s", p, arch) logger.info("Testing %s at %s", p, arch)
if not dry_run: if not dry_run:
conda_build.api.test(p, config=conda_config) with root_logger_protection():
conda_build.api.test(p, config=conda_config)
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