Skip to content

Commit

Permalink
Don't truncate the filename extension in 'fn' for fake conda-metas
Browse files Browse the repository at this point in the history
  • Loading branch information
maresb committed Nov 7, 2024
1 parent 9882e5e commit d1cefab
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 5 deletions.
9 changes: 5 additions & 4 deletions conda_lock/conda_solver.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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
5 changes: 4 additions & 1 deletion tests/test_conda_lock.py
Original file line number Diff line number Diff line change
Expand Up @@ -2644,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


Expand Down

0 comments on commit d1cefab

Please sign in to comment.