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()
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 upload(): emojize = build() if not emojize: LOGGER.error('Errors caught on building the artifact, bailing out...') raise SystemExit(1) if not validate_environment_variable_prerequisites( PREREQUISITES.get('upload_environment_variables', [])): LOGGER.error( 'Prerequisite environment variable for upload missing, cannot continue.' ) raise SystemExit(1) upload_command = ('twine upload dist/* ' f'-u {os.environ.get("PYPI_UPLOAD_USERNAME")} ' f'-p {os.environ.get("PYPI_UPLOAD_PASSWORD")} ' '--skip-existing ' f'--repository-url {os.environ.get("PYPI_URL")}') LOGGER.info('Trying to upload built artifact...') success = execute_command(upload_command) if success: LOGGER.info('%s Successfully uploaded artifact! %s', emojize(':white_heavy_check_mark:'), emojize(':thumbs_up:')) else: LOGGER.error('%s Errors found in uploading artifact! %s', emojize(':cross_mark:'), emojize(':crying_face:')) raise SystemExit(0 if success else 1)