def tox_runtest_pre(venv: VirtualEnv) -> None: envconfig = venv.envconfig container_names = envconfig.docker log = make_logger(venv) env_container_configs = [] seen = set() for container_name in container_names: if container_name not in CONTAINER_CONFIGS: raise ValueError(f"Missing [docker:{container_name}] in tox.ini") if container_name in seen: raise ValueError(f"Container {container_name!r} specified more than once") seen.add(container_name) env_container_configs.append(CONTAINER_CONFIGS[container_name]) for container_config in env_container_configs: docker_pull(container_config, log) ENV_CONTAINERS.setdefault(venv, {}) running_containers = ENV_CONTAINERS[venv] for container_config in env_container_configs: container = docker_run(container_config, running_containers, log) running_containers[container_config.runas_name] = container for running_name, container in running_containers.items(): container_name = _config_name(running_name) container_config = CONTAINER_CONFIGS[container_name] try: docker_health_check(container_config, container, log) except HealthCheckFailed: msg = f"{container_config.image!r} (from {container_name!r}) failed health check" venv.status = msg tox_runtest_post(venv) raise for running_name, container in running_containers.items(): container_name = _config_name(running_name) container_config = CONTAINER_CONFIGS[container_name] for key, val in get_env_vars(container_config, container).items(): venv.envconfig.setenv[key] = val
def tox_testenv_install_deps(venv: ToxVirtualEnv, action: ToxAction) -> Optional[bool]: """Install the dependencies for the current environment Loads the local Poetry environment and the corresponding lockfile then pulls the dependencies specified by the Tox environment. Finally these dependencies are installed into the Tox environment using the Poetry ``PipInstaller`` backend. :param venv: Tox virtual environment object with configuration for the local Tox environment. :param action: Tox action object """ try: poetry = utilities.check_preconditions(venv, action) except exceptions.SkipEnvironment as err: if isinstance(err, exceptions.PoetryNotInstalledError) and ( venv.envconfig.config.option.require_poetry or venv.envconfig.require_poetry): venv.status = err.__class__.__name__ logger.error(str(err)) return False logger.info(str(err)) return None logger.info(f"Loaded project pyproject.toml from {poetry.file}") virtualenv = utilities.convert_virtualenv(venv) if not poetry.locker.is_fresh(): logger.warning( f"The Poetry lock file is not up to date with the latest changes in {poetry.file}" ) try: if venv.envconfig.require_locked_deps and venv.envconfig.deps: raise exceptions.LockedDepsRequiredError( f"Unlocked dependencies '{venv.envconfig.deps}' specified for environment '{venv.name}' which requires locked dependencies" ) packages: PackageMap = { package.name: package for package in poetry.locker.locked_repository(True).packages } if venv.envconfig.install_dev_deps: dev_deps = utilities.find_dev_deps(packages, virtualenv, poetry) logger.info( f"Identified {len(dev_deps)} development dependencies to install to env" ) else: dev_deps = [] logger.info( "Env does not install development dependencies, skipping") env_deps = utilities.find_additional_deps(packages, virtualenv, poetry, venv.envconfig.locked_deps) logger.info( f"Identified {len(env_deps)} environment dependencies to install to env" ) install_project_deps = (venv.envconfig.install_project_deps if venv.envconfig.install_project_deps is not None else (not venv.envconfig.skip_install and not venv.envconfig.config.skipsdist)) if install_project_deps: project_deps = utilities.find_project_deps(packages, virtualenv, poetry, venv.envconfig.extras) logger.info( f"Identified {len(project_deps)} project dependencies to install to env" ) else: project_deps = [] logger.info( "Env does not install project package dependencies, skipping") except exceptions.ToxPoetryInstallerException as err: venv.status = err.__class__.__name__ logger.error(str(err)) return False except Exception as err: venv.status = "InternalError" logger.error(f"Internal plugin error: {err}") raise err dependencies = dev_deps + env_deps + project_deps if (venv.envconfig.config.option.parallel_install_threads != constants.DEFAULT_INSTALL_THREADS): parallel_threads = venv.envconfig.config.option.parallel_install_threads else: parallel_threads = ( venv.envconfig.config.option.parallelize_locked_install if venv.envconfig.config.option.parallelize_locked_install is not None else constants.DEFAULT_INSTALL_THREADS) log_parallel = f" (using {parallel_threads} threads)" if parallel_threads else "" action.setactivity( __about__.__title__, f"Installing {len(dependencies)} dependencies from Poetry lock file{log_parallel}", ) installer.install( poetry, venv, dependencies, parallel_threads, ) return venv.envconfig.require_locked_deps or None