def test_pyversion_warning_on_load(tmp_path_factory, capsys, example_bento_service_class): # Set logging level so version mismatch warnings are outputted bentoml.configure_logging(logging_level=logging.WARNING) # (Note that logger.warning() is captured by pytest in stdout, NOT stdlog. # So the warning is in capsys.readouterr().out, NOT caplog.text.) test_model = TestModel() svc = example_bento_service_class() svc.pack('model', test_model) # Should not warn for default `_python_version` value match_dir = tmp_path_factory.mktemp("match") svc.save_to_dir(match_dir) _ = bentoml.load(str(match_dir)) assert "Python version mismatch" not in capsys.readouterr().out # Should warn for any version mismatch (major, minor, or micro) svc.env._python_version = "X.Y.Z" mismatch_dir = tmp_path_factory.mktemp("mismatch") svc.save_to_dir(mismatch_dir) _ = bentoml.load(str(mismatch_dir)) assert "Python version mismatch" in capsys.readouterr().out # Reset logging level to default bentoml.configure_logging()
def set_debug_mode(debug_mode_on: bool): config().set('core', 'debug', str(debug_mode_on)) from bentoml.utils.log import configure_logging configure_logging() # reconfigure logging and set log level to debug logger.debug( f"Setting debug mode: {'ON' if debug_mode_on else 'OFF'} for current session" )
def wrapper(quiet, verbose, *args, **kwargs): if quiet: configure_logging(logging.ERROR) if verbose: logger.warning( "The bentoml command option `--verbose/--debug` is ignored when" "the `--quiet` flag is also in use") elif verbose: set_debug_mode(True) return func(*args, **kwargs)
def _reset_bentoml_home(new_bentoml_home_directory): global _config # pylint: disable=global-statement global DEFAULT_BENTOML_HOME, BENTOML_HOME # pylint: disable=global-statement DEFAULT_BENTOML_HOME = new_bentoml_home_directory BENTOML_HOME = new_bentoml_home_directory # reload config _config = load_config() # re-config logging from bentoml import configure_logging root = logging.getLogger() map(root.removeHandler, root.handlers[:]) map(root.removeFilter, root.filters[:]) configure_logging()
def wrapper(quiet, verbose, *args, **kwargs): if verbose: from bentoml import config config().set('core', 'debug', 'true') configure_logging(logging.DEBUG) elif quiet: configure_logging(logging.ERROR) else: configure_logging() # use default setting in local bentoml.cfg return func(*args, **kwargs)
import os import sys import logging from bentoml import saved_bundle, configure_logging from bentoml.cli import create_bento_service_cli # By default, ignore warnings when loading BentoService installed as PyPI distribution # CLI will change back to default log level in config(info), and by adding --quiet or # --verbose CLI option, user can change the CLI output behavior configure_logging(logging.ERROR) __VERSION__ = "20200727163421_432B4B" __module_path = os.path.abspath(os.path.dirname(__file__)) IrisClassifier = saved_bundle.load_bento_service_class(__module_path) cli=create_bento_service_cli(__module_path) def load(): return saved_bundle.load(__module_path) __all__ = ['__version__', 'IrisClassifier', 'load']