def initialize_template_environment(): from configuration import (LOGGING_LEVEL, ENVIRONMENT_VARIABLES, PREREQUISITES) from library import (setup_logging, validate_binary_prerequisites, validate_environment_variable_prerequisites, is_venv_created, execute_command, load_environment_variables, load_dot_env_file, activate_virtual_environment) load_environment_variables(ENVIRONMENT_VARIABLES) load_dot_env_file() if not validate_binary_prerequisites(PREREQUISITES.get('executables', [])): LOGGER.error('Prerequisite binary missing, cannot continue.') raise SystemExit(1) if not validate_environment_variable_prerequisites( PREREQUISITES.get('environment_variables', [])): LOGGER.error( 'Prerequisite environment variable missing, cannot continue.') raise SystemExit(1) if not is_venv_created(): LOGGER.debug('Trying to create virtual environment.') success = execute_command('pipenv install --dev --ignore-pipfile') if success: activate_virtual_environment() from emoji import emojize LOGGER.info( '%s Successfully created virtual environment and loaded it! %s', emojize(':white_heavy_check_mark:'), emojize(':thumbs_up:')) else: LOGGER.error( 'Creation of virtual environment failed, cannot continue, ' 'please clean up .venv directory and try again...') raise SystemExit(1) setup_logging(os.environ.get('LOGGING_LEVEL') or LOGGING_LEVEL)
def bootstrap(): setup_logging(os.environ.get("LOGGING_LEVEL") or LOGGING_LEVEL) load_environment_variables(ENVIRONMENT_VARIABLES) load_dot_env_file() if not validate_binary_prerequisites(PREREQUISITES.get('executables', [])): LOGGER.error('Prerequisite binary missing, cannot continue.') raise SystemExit(1) if not validate_environment_variable_prerequisites(PREREQUISITES.get('environment_variables', [])): LOGGER.error('Prerequisite environment variable missing, cannot continue.') raise SystemExit(1) if not is_venv_created(): LOGGER.debug('Trying to create virtual environment.') skip_lock = '--skip-lock' if os.environ.get('PIPENV_SKIP_LOCK') else '' exit_code = execute_command(f'pipenv install --dev --ignore-pipfile {skip_lock}') success = not exit_code if success: activate_virtual_environment() emojize = get_emojize() LOGGER.info('%s Successfully created virtual environment and loaded it! %s', emojize(':white_heavy_check_mark:'), emojize(':thumbs_up:')) else: LOGGER.error('Creation of virtual environment failed, cannot continue, ' 'please clean up .venv directory and try again...') raise SystemExit(1) return get_emojize()