diff --git a/conda_lock/conda_lock.py b/conda_lock/conda_lock.py index 0c96d4c84..bbafb65e6 100644 --- a/conda_lock/conda_lock.py +++ b/conda_lock/conda_lock.py @@ -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, @@ -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- " diff --git a/conda_lock/lockfile/__init__.py b/conda_lock/lockfile/__init__.py index 4cc93dea4..1457da89d 100644 --- a/conda_lock/lockfile/__init__.py +++ b/conda_lock/lockfile/__init__.py @@ -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]: @@ -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(