Skip to content

Commit 6ce3d4b

Browse files
committed
improve CondaEnv._get_version_pin
1 parent c4b533c commit 6ce3d4b

File tree

2 files changed

+8
-3
lines changed

2 files changed

+8
-3
lines changed

bioimageio/spec/conda_env.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,8 @@ def _ensure_valid_conda_env_name(cls, value: Optional[str]) -> Optional[str]:
5050
def wo_name(self):
5151
return self.model_construct(**{k: v for k, v in self if k != "name"})
5252

53-
def _get_version(self, package: str):
54-
"""Helper to return any verison pin for **package**
53+
def _get_version_pin(self, package: str):
54+
"""Helper to return any version pin for **package**
5555
5656
TODO: improve: interprete version pin and return structured information.
5757
"""
@@ -62,6 +62,10 @@ def _get_version(self, package: str):
6262
return p[len(package) :]
6363
elif d.startswith(package):
6464
return d[len(package) :]
65+
elif "::" in d and (d_wo_channel := d.split("::", 1)[-1]).startswith(
66+
package
67+
):
68+
return d_wo_channel[len(package) :]
6569

6670
def get_pip_deps(self) -> List[str]:
6771
"""Get the pip dependencies of this conda env."""

tests/test_get_conda_env.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,8 @@ def test_get_default_pytorch_env():
121121
]
122122
for p in ["torchvision", "torchaudio"]:
123123
versions[p] = [
124-
env._get_version(p) for env in envs # pyright: ignore[reportPrivateUsage]
124+
env._get_version_pin(p) # pyright: ignore[reportPrivateUsage]
125+
for env in envs
125126
]
126127

127128
def assert_lt(p: str, i: int):

0 commit comments

Comments
 (0)