From 6837a64121384e269eb2583d103ca905e5a7032f Mon Sep 17 00:00:00 2001 From: Ethan Paul Date: Thu, 15 Aug 2024 11:59:54 -0400 Subject: [PATCH] Add handling of error when poetry.lock does not exist Fixes #81 --- tox_poetry_installer/exceptions.py | 5 +++++ tox_poetry_installer/hooks/tox_on_install.py | 14 ++++++++++---- 2 files changed, 15 insertions(+), 4 deletions(-) diff --git a/tox_poetry_installer/exceptions.py b/tox_poetry_installer/exceptions.py index 44d476f..6e40215 100644 --- a/tox_poetry_installer/exceptions.py +++ b/tox_poetry_installer/exceptions.py @@ -11,6 +11,7 @@ All exceptions should inherit from the common base exception :exc:`ToxPoetryInst +-- LockedDepNotFoundError +-- ExtraNotFoundError +-- LockedDepsRequiredError + +-- LockfileParsingError """ @@ -41,3 +42,7 @@ class ExtraNotFoundError(ToxPoetryInstallerException): class LockedDepsRequiredError(ToxPoetryInstallerException): """Environment cannot specify unlocked dependencies when locked dependencies are required""" + + +class LockfileParsingError(ToxPoetryInstallerException): + """Failed to load or parse the Poetry lockfile""" diff --git a/tox_poetry_installer/hooks/tox_on_install.py b/tox_poetry_installer/hooks/tox_on_install.py index 236dd70..ae324c0 100644 --- a/tox_poetry_installer/hooks/tox_on_install.py +++ b/tox_poetry_installer/hooks/tox_on_install.py @@ -41,10 +41,16 @@ def tox_on_install( virtualenv = convert_virtualenv(tox_env) - 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 not poetry.locker.is_fresh(): + logger.warning( + f"The Poetry lock file is not up to date with the latest changes in {poetry.file}" + ) + except FileNotFoundError as err: + logger.error(f"Could not parse lockfile: {err}") + raise exceptions.LockfileParsingError( + f"Could not parse lockfile: {err}" + ) from err try: if tox_env.conf["require_locked_deps"] and tox_env.conf["deps"].lines():