Repository: benchopt/benchopt
Pull request #770 (2024-09-10 08:44:04)

FIX channel specified with one colon instead of 2
The proposed approach used to handle deprecation fails, this is a fix, which adds test for the deprecated behavior.

codecov[bot]: ## [Codecov](https://app.codecov.io/gh/benchopt/benchopt/pull/770?dropdown=coverage&src=pr&el=h1&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=benchopt) Report
All modified and coverable lines are covered by tests :white_check_mark:
> Project coverage is 82.23%. Comparing base [(`bb3a086`)](https://app.codecov.io/gh/benchopt/benchopt/commit/bb3a086970c067e062e387d4a8b2d73cd7264f86?dropdown=coverage&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=benchopt) to head [(`e4e314b`)](https://app.codecov.io/gh/benchopt/benchopt/commit/e4e314bd93458b27781a570a2b123266786cbf2d?dropdown=coverage&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=benchopt).
> Report is 1 commits behind head on main.

<details><summary>Additional details and impacted files</summary>


```diff
@@           Coverage Diff           @@
##             main     #770   +/-   ##
=======================================
  Coverage   82.23%   82.23%           
=======================================
  Files          46       46           
  Lines        3169     3169           
=======================================
  Hits         2606     2606           
  Misses        563      563           
```

</details>

Patch:
diff --git a/benchopt/utils/conda_env_cmd.py b/benchopt/utils/conda_env_cmd.py
index 368a0d3..307c310 100644
--- a/benchopt/utils/conda_env_cmd.py
+++ b/benchopt/utils/conda_env_cmd.py
@@ -191,15 +191,11 @@ def get_cmd_from_requirements(packages):
             "The use of ':' to specify the channel of a dependency is "
             "deprecated. Please use '::' instead.", DeprecationWarning
         )
+        packages = [pkg.replace(":", "::", 1) for pkg in packages]
 
     cmd = []
     conda_packages = [pkg for pkg in packages if not pkg.startswith('pip::')]
     if conda_packages:
-
-        conda_packages = [
-            pkg.replace(":", "::") if ":" in pkg and "::" not in pkg else pkg
-            for pkg in conda_packages
-        ]
         channels = ' '.join(set(
             f"-c {pkg.rsplit('::', 1)[0]}"
             for pkg in conda_packages if '::' in pkg
@@ -211,10 +207,8 @@ def get_cmd_from_requirements(packages):
             f"{CONDA_CMD} install --update-all -y {channels} {conda_packages}"
         )
 
-    # TODO: simplify in benchopt 1.7
     pip_packages = [
-        pkg.replace("pip::", "").replace("pip:", "")
-        for pkg in packages if pkg.startswith('pip:')
+        pkg.replace("pip::", "") for pkg in packages if pkg.startswith('pip::')
     ]
     if pip_packages:
         packages = ' '.join(pip_packages)


Test patch:
diff --git a/benchopt/tests/test_deprecation.py b/benchopt/tests/test_deprecation.py
new file mode 100644
index 0000000..7e40728
--- /dev/null
+++ b/benchopt/tests/test_deprecation.py
@@ -0,0 +1,32 @@
+import pytest
+
+from benchopt.utils.conda_env_cmd import get_cmd_from_requirements
+from benchopt.utils.conda_env_cmd import CONDA_CMD, PIP_CMD
+
+
+# TODO: remove this test in benchopt 1.7
+def test_deprecated_channel_spec():
+    with pytest.warns(DeprecationWarning):
+        cmd = get_cmd_from_requirements(["chan:pkg"])
+
+    assert len(cmd) == 1
+    assert cmd[0] == f"{CONDA_CMD} install --update-all -y -c chan pkg"
+
+    with pytest.warns(DeprecationWarning):
+        cmd = get_cmd_from_requirements(["pip:pkg"])
+
+    assert len(cmd) == 1
+    assert cmd[0] == f"{PIP_CMD} install pkg"
+
+    with pytest.warns(DeprecationWarning):
+        cmd = get_cmd_from_requirements(["pip:git+https://test.org"])
+
+    assert len(cmd) == 1
+    assert cmd[0] == f"{PIP_CMD} install git+https://test.org"
+
+    with pytest.warns(DeprecationWarning):
+        cmd = get_cmd_from_requirements(["pkg1", "chan:pkg2", "pip:pkg3"])
+
+    assert len(cmd) == 2
+    assert cmd[0] == f"{CONDA_CMD} install --update-all -y -c chan pkg1 pkg2"
+    assert cmd[1] == f"{PIP_CMD} install pkg3"