Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TEST: Dont catch UnknownLockfileVersion #503

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 9 additions & 4 deletions conda_lock/conda_lock.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,11 @@
determine_conda_executable,
is_micromamba,
)
from conda_lock.lockfile import parse_conda_lock_file, write_conda_lock_file
from conda_lock.lockfile import (
UnknownLockfileVersion,
parse_conda_lock_file,
write_conda_lock_file,
)
from conda_lock.lockfile.v2prelim.models import (
GitMeta,
InputMeta,
Expand Down Expand Up @@ -933,14 +937,15 @@ def _render_lockfile_for_install(

"""

if not filename.name.endswith(DEFAULT_LOCKFILE_NAME):
try:
lock_content = parse_conda_lock_file(pathlib.Path(filename))
except yaml.YAMLError:
# This indicates a kind explicit lockfile, which is already rendered
yield filename
return

from ensureconda.resolve import platform_subdir

lock_content = parse_conda_lock_file(pathlib.Path(filename))

platform = platform_subdir()
if platform not in lock_content.metadata.platforms:
suggested_platforms_section = "platforms:\n- "
Expand Down
6 changes: 5 additions & 1 deletion conda_lock/lockfile/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@
from conda_lock.models.lock_spec import Dependency


class UnknownLockfileVersion(ValueError):
pass


def _seperator_munge_get(
d: Mapping[str, Union[List[LockedDependency], LockedDependency]], key: str
) -> Union[List[LockedDependency], LockedDependency]:
Expand Down Expand Up @@ -136,7 +140,7 @@ def parse_conda_lock_file(path: pathlib.Path) -> Lockfile:
if version == 1:
return lockfile_v1_to_v2(LockfileV1.parse_obj(content))
else:
raise ValueError(f"{path} has unknown version {version}")
raise UnknownLockfileVersion(f"{path} has unknown version {version}")


def write_conda_lock_file(
Expand Down
Loading