Skip to content
4 changes: 3 additions & 1 deletion metaflow/plugins/pypi/pip.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Empty file added test/plugins/pip/__init__.py
Empty file.
32 changes: 32 additions & 0 deletions test/plugins/pip/test_pip_indices.py
Original file line number Diff line number Diff line change
@@ -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",
]
Loading