Skip to content

Commit

Permalink
Merge pull request #744 from maresb/fix-fake-conda-env
Browse files Browse the repository at this point in the history
Minor bugfix: don't truncate the extension in conda-meta filenames
  • Loading branch information
maresb authored Nov 7, 2024
2 parents 28b949b + d1cefab commit d65aad5
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 15 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
15 changes: 4 additions & 11 deletions tests/test_conda_lock.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
[
Expand Down Expand Up @@ -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


Expand Down

0 comments on commit d65aad5

Please sign in to comment.