diff --git a/metaflow/plugins/pypi/pip.py b/metaflow/plugins/pypi/pip.py index 6b2c73a23eb..31b215bba00 100644 --- a/metaflow/plugins/pypi/pip.py +++ b/metaflow/plugins/pypi/pip.py @@ -324,7 +324,9 @@ def indices(self, prefix): key, value = line.split("=", 1) _, key = key.split(".") if key in ("index-url", "extra-index-url"): - values = map(lambda x: x.strip("'\""), re.split("\s+", value, re.M)) + values = map( + lambda x: x.strip("'\""), re.split(r"\\n|\s+", value, re.M) + ) (indices if key == "index-url" else extra_indices).extend(values) except Exception: pass diff --git a/test/plugins/pip/__init__.py b/test/plugins/pip/__init__.py new file mode 100644 index 00000000000..e69de29bb2d diff --git a/test/plugins/pip/test_pip_indices.py b/test/plugins/pip/test_pip_indices.py new file mode 100644 index 00000000000..e5e8d09b6e7 --- /dev/null +++ b/test/plugins/pip/test_pip_indices.py @@ -0,0 +1,32 @@ +from unittest.mock import MagicMock + +from metaflow.plugins.pypi.pip import Pip + + +def _make_pip(): + """Create a bare Pip instance for testing.""" + pip = object.__new__(Pip) + return pip + + +def test_multiple_extra_index_urls_literal_newline(monkeypatch): + """Regression test: pip config list separates multiple URLs with literal \\n.""" + pip = _make_pip() + config_output = ( + "global.index-url='https://pypi.org/simple'\n" + r"global.extra-index-url='https://extra1.example.com/simple'\n'https://extra2.example.com/simple'" + ) + + # Use monkeypatch instead of unittest.mock.patch + mock_call = MagicMock(return_value=config_output) + monkeypatch.setattr(pip, "_call", mock_call) + + # Execute + index, extras = pip.indices("dummy") + + # Assert + assert index == "https://pypi.org/simple" + assert extras == [ + "https://extra1.example.com/simple", + "https://extra2.example.com/simple", + ]