Skip to content

Commit

Permalink
Merge pull request #604 from maresb/handle-poetry-exceptions
Browse files Browse the repository at this point in the history
Catch CalledProcessErrors from both subprocess and Poetry
  • Loading branch information
maresb authored Feb 10, 2024
2 parents 8f9de4e + 73e460d commit cf8afd5
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 3 deletions.
7 changes: 5 additions & 2 deletions conda_lock/conda_solver.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@
from typing_extensions import TypedDict

from conda_lock.interfaces.vendored_conda import MatchSpec
from conda_lock.interfaces.vendored_poetry import (
CalledProcessError as PoetryCalledProcessError,
)
from conda_lock.invoke_conda import (
PathLike,
_get_conda_flags,
Expand Down Expand Up @@ -367,7 +370,7 @@ def print_proc(proc: subprocess.CompletedProcess) -> None:

try:
proc.check_returncode()
except subprocess.CalledProcessError:
except (subprocess.CalledProcessError, PoetryCalledProcessError):
try:
err_json = json.loads(proc.stdout)
try:
Expand Down Expand Up @@ -486,7 +489,7 @@ def update_specs_for_arch(

try:
proc.check_returncode()
except subprocess.CalledProcessError as exc:
except (subprocess.CalledProcessError, PoetryCalledProcessError) as exc:
err_json = json.loads(proc.stdout)
raise RuntimeError(
f"Could not lock the environment for platform {platform}: {err_json.get('message')}"
Expand Down
2 changes: 2 additions & 0 deletions conda_lock/interfaces/vendored_poetry.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,12 @@
from conda_lock._vendor.poetry.repositories.pool import Pool
from conda_lock._vendor.poetry.repositories.pypi_repository import PyPiRepository
from conda_lock._vendor.poetry.repositories.repository import Repository
from conda_lock._vendor.poetry.utils._compat import CalledProcessError
from conda_lock._vendor.poetry.utils.env import Env


__all__ = [
"CalledProcessError",
"Chooser",
"Env",
"Factory",
Expand Down
5 changes: 4 additions & 1 deletion tests/test_conda_lock.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,9 @@
PlatformValidationError,
)
from conda_lock.interfaces.vendored_conda import MatchSpec
from conda_lock.interfaces.vendored_poetry import (
CalledProcessError as PoetryCalledProcessError,
)
from conda_lock.invoke_conda import is_micromamba, reset_conda_pkgs_dir
from conda_lock.lockfile import parse_conda_lock_file
from conda_lock.lockfile.v2prelim.models import (
Expand Down Expand Up @@ -1815,7 +1818,7 @@ def conda_supports_env(conda_exe: str):
subprocess.check_call(
[conda_exe, "env"], stdout=subprocess.PIPE, stderr=subprocess.PIPE
)
except subprocess.CalledProcessError:
except (subprocess.CalledProcessError, PoetryCalledProcessError):
return False
return True

Expand Down

0 comments on commit cf8afd5

Please sign in to comment.