Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feature: support custom index config for pypi decorator #1613

Merged
merged 1 commit into from
Oct 26, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
15 changes: 15 additions & 0 deletions metaflow/plugins/pypi/pip.py
Original file line number Diff line number Diff line change
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