From 74e3ed01c0626c041008d4c40229c69becdf7e62 Mon Sep 17 00:00:00 2001 From: Ethan Paul <24588726+enpaul@users.noreply.github.com> Date: Thu, 22 Oct 2020 21:05:33 -0400 Subject: [PATCH] Fix handling of nonexistent extras with custom app exception --- tox_poetry_installer.py | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/tox_poetry_installer.py b/tox_poetry_installer.py index 855f7c9..00dea23 100644 --- a/tox_poetry_installer.py +++ b/tox_poetry_installer.py @@ -72,6 +72,10 @@ class LockedDepNotFoundError(ToxPoetryInstallerException): """Locked dependency was not found in the lockfile""" +class ExtraNotFoundError(ToxPoetryInstallerException): + """Project package extra not defined in project's pyproject.toml""" + + def _sort_env_deps(venv: ToxVirtualEnv) -> _SortedEnvDeps: """Sorts the environment dependencies by lock status @@ -221,13 +225,18 @@ def _install_package_dependencies( ) base_dependencies = [ - packages[item.name] for item in poetry.packages.requires if not item.is_optional + packages[item.name] for item in poetry.package.requires if not item.is_optional ] for extra in venv.envconfig.extras: - extra_dependencies = [ - packages[item.name] for item in poetry.package.extras[extra] - ] + try: + extra_dependencies = [ + packages[item.name] for item in poetry.package.extras[extra] + ] + except KeyError: + raise ExtraNotFoundError( + f"Environment '{venv.name}' specifies project extra '{extra}' which was not found in the lockfile" + ) from None dependencies: List[PoetryPackage] = [] for dep in base_dependencies + extra_dependencies: