Skip to content

Commit

Permalink
introduce support for custom pip index config (#1613)
Browse files Browse the repository at this point in the history
  • Loading branch information
saikonen committed Oct 26, 2023
1 parent 15cf84b commit 6f1c354
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions metaflow/plugins/pypi/pip.py
Expand Up @@ -50,6 +50,7 @@ def solve(self, id_, packages, python, platform):
for tag in pip_tags(python, platform)
]
)
custom_index_url = self.index_url(prefix)
extra_index_urls = self.extra_index_urls(prefix)
cmd = [
"install",
Expand All @@ -60,6 +61,7 @@ def solve(self, id_, packages, python, platform):
"--report=%s" % report,
"--progress-bar=off",
"--quiet",
*(["--index-url", custom_index_url] if custom_index_url else []),
*(
chain.from_iterable(
product(["--extra-index-url"], set(extra_index_urls))
Expand Down Expand Up @@ -94,6 +96,7 @@ def download(self, id_, packages, python, platform):
for tag in pip_tags(python, platform)
]
)
custom_index_url = self.index_url(prefix)
extra_index_urls = self.extra_index_urls(prefix)
cmd = [
"download",
Expand All @@ -103,6 +106,7 @@ def download(self, id_, packages, python, platform):
# if packages are present in Pip cache, this will be a local copy
"--dest=%s/.pip/wheels" % prefix,
"--quiet",
*(["--index-url", custom_index_url] if custom_index_url else []),
*(
chain.from_iterable(
product(["--extra-index-url"], set(extra_index_urls))
Expand Down Expand Up @@ -165,6 +169,17 @@ def extra_index_urls(self, prefix):
pass
return extra_indices

def index_url(self, prefix):
# get custom index url from Pip conf
try:
return self._call(
prefix, args=["config", "get", "global.index-url"], isolated=False
)
except Exception:
# Pip will throw an error when trying to get a config key that does
# not exist
return None

def _call(self, prefix, args, env=None, isolated=True):
if env is None:
env = {}
Expand Down

0 comments on commit 6f1c354

Please sign in to comment.