def test_get_local_config_file(): config_file = get_local_config_file() assert config_file is None os.environ["BENTOML_CONFIG"] = "/tmp/bentoml.cfg" config_file = get_local_config_file() assert config_file == "/tmp/bentoml.cfg" del os.environ["BENTOML_CONFIG"]
def test_get_local_config_file(): config_file = get_local_config_file() assert config_file == os.path.join(BENTOML_HOME, "bentoml.cfg") os.environ["BENTOML_CONFIG"] = "/tmp/bentoml.cfg" config_file = get_local_config_file() assert config_file == "/tmp/bentoml.cfg" del os.environ["BENTOML_CONFIG"]
def set_command(updates): track_cli('config-set') local_config = ConfigParser() local_config_file = get_local_config_file() local_config.read(local_config_file, encoding='utf-8') try: for update in updates: item, value = update.split('=') if '.' in item: sec, opt = item.split('.') else: sec = 'core' # default section opt = item if not local_config.has_section(sec): local_config.add_section(sec) local_config.set(sec.strip(), opt.strip(), value.strip()) local_config.write(open(local_config_file, 'w')) return except ValueError: _echo('Wrong config format: %s' % str(updates), CLI_COLOR_ERROR) _echo(EXAMPLE_CONFIG_USAGE) return
def reset(): local_config_file = get_local_config_file() if os.path.isfile(local_config_file): logger.info("Removing existing BentoML config file: %s", local_config_file) os.remove(local_config_file) create_local_config_file_if_not_found() return
def view(): track_cli('config-view') local_config = ConfigParser() with open(get_local_config_file(), 'rb') as config_file: local_config.read_string(config_file.read().decode('utf-8')) local_config.write(sys.stdout) return
def reset(): track_cli('config-reset') local_config_file = get_local_config_file() if os.path.isfile(local_config_file): LOG.info("Removing existing BentoML config file: %s", local_config_file) os.remove(local_config_file) create_local_config_file_if_not_found() return
def unset(updates): local_config = ConfigParser() local_config_file = get_local_config_file() local_config.read(local_config_file, encoding=CONFIG_FILE_ENCODING) try: for update in updates: if '.' in update: sec, opt = update.split('.') else: sec = 'core' # default section opt = update if not local_config.has_section(sec): local_config.add_section(sec) local_config.remove_option(sec.strip(), opt.strip()) local_config.write(open(local_config_file, 'w')) return except ValueError: raise CLIException( f'Wrong config format: {str(updates)}{EXAMPLE_CONFIG_USAGE}' )
def unset(updates): track_cli('config-unset') local_config = ConfigParser() local_config_file = get_local_config_file() with open(local_config_file, 'rb') as config_file: local_config.read_string(config_file.read().decode('utf-8')) try: for update in updates: if '.' in update: sec, opt = update.split('.') else: sec = 'core' # default section opt = update if not local_config.has_section(sec): local_config.add_section(sec) local_config.remove_option(sec.strip(), opt.strip()) local_config.write(open(local_config_file, 'w')) return except ValueError: _echo('Wrong config format: %s' % str(updates), CLI_COLOR_ERROR) _echo(EXAMPLE_CONFIG_USAGE) return
def view(): track_cli('config-view') local_config = ConfigParser() local_config.read(get_local_config_file(), encoding='utf-8') local_config.write(sys.stdout) return
def create_local_config_file_if_not_found(): local_config_file = get_local_config_file() if not os.path.isfile(local_config_file): logger.info("Creating local BentoML config file at: %s", local_config_file) shutil.copyfile(DEFAULT_CONFIG_FILE, local_config_file)
def view(): local_config = ConfigParser() local_config.read(get_local_config_file(), encoding=CONFIG_FILE_ENCODING) local_config.write(sys.stdout) return