diff --git a/conda_lock/conda_solver.py b/conda_lock/conda_solver.py index 54c276711..2e1da38cc 100644 --- a/conda_lock/conda_solver.py +++ b/conda_lock/conda_solver.py @@ -565,9 +565,10 @@ def fake_conda_environment( channel = urlunsplit( (url.scheme, url.hostname, str(path.parent), None, None) ) - while path.suffix in {".tar", ".bz2", ".gz", ".conda"}: - path = path.with_suffix("") - build = path.name.split("-")[-1] + truncated_path = path + while truncated_path.suffix in {".tar", ".bz2", ".gz", ".conda"}: + truncated_path = truncated_path.with_suffix("") + build = truncated_path.name.split("-")[-1] try: build_number = int(build.split("_")[-1]) except ValueError: @@ -588,6 +589,6 @@ def fake_conda_environment( if dep.hash.sha256 is not None: entry["sha256"] = dep.hash.sha256 - with open(conda_meta / (path.name + ".json"), "w") as f: + with open(conda_meta / (truncated_path.name + ".json"), "w") as f: json.dump(entry, f, indent=2) yield prefix diff --git a/tests/test_conda_lock.py b/tests/test_conda_lock.py index 6f32ac3bf..2bee0e8c5 100644 --- a/tests/test_conda_lock.py +++ b/tests/test_conda_lock.py @@ -2605,16 +2605,6 @@ def test_fake_conda_env(conda_exe: str, conda_lock_yaml: Path): with fake_conda_environment( lockfile_content.package, platform="linux-64" ) as prefix: - subprocess.call( - [ - conda_exe, - "list", - "--debug", - "-p", - prefix, - "--json", - ] - ) packages = json.loads( subprocess.check_output( [ @@ -2654,7 +2644,10 @@ def test_fake_conda_env(conda_exe: str, conda_lock_yaml: Path): else: assert env_package["base_url"] == expected_base_url assert env_package["channel"] == expected_channel - assert env_package["dist_name"] == f"{path.name[:-8]}" + expected_dist = path + while expected_dist.name.endswith((".tar", ".bz2", ".gz", ".conda")): + expected_dist = expected_dist.with_suffix("") + assert env_package["dist_name"] == expected_dist.name assert platform == path.parent.name