diff --git a/metaflow/plugins/pypi/pip.py b/metaflow/plugins/pypi/pip.py index 6b2c73a23eb..972d219d48a 100644 --- a/metaflow/plugins/pypi/pip.py +++ b/metaflow/plugins/pypi/pip.py @@ -324,7 +324,7 @@ 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/unit/test_pip_indices.py b/test/unit/test_pip_indices.py new file mode 100644 index 00000000000..45584d0e6bd --- /dev/null +++ b/test/unit/test_pip_indices.py @@ -0,0 +1,24 @@ +from unittest.mock import patch + +from metaflow.plugins.pypi.pip import Pip + + +def _make_pip(): + pip = object.__new__(Pip) + return pip + + +def test_multiple_extra_index_urls_literal_newline(): + """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'" + ) + with patch.object(pip, "_call", return_value=config_output): + index, extras = pip.indices("dummy") + assert index == "https://pypi.org/simple" + assert extras == [ + "https://extra1.example.com/simple", + "https://extra2.example.com/simple", + ]