Skip to content

Commit

Permalink
resource: automatic determine mirrors for PyPI resources
Browse files Browse the repository at this point in the history
  • Loading branch information
XuehaiPan committed Sep 15, 2022
1 parent 2216d6e commit a9ef3ae
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 0 deletions.
7 changes: 7 additions & 0 deletions Library/Homebrew/env_config.rb
Original file line number Diff line number Diff line change
Expand Up @@ -474,5 +474,12 @@ def cask_opts_quarantine?
def cask_opts_require_sha?
cask_opts.include?("--require-sha")
end

sig { returns(T::Array[String]) }
def pip_index_urls
"#{ENV.fetch("PIP_INDEX_URL", "")} #{ENV.fetch("PIP_EXTRA_INDEX_URL", "")}".split.map do |url|
url.chomp("/")
end.uniq
end
end
end
8 changes: 8 additions & 0 deletions Library/Homebrew/resource.rb
Original file line number Diff line number Diff line change
Expand Up @@ -294,6 +294,14 @@ def determine_mirror_urls
end
end

# PyPI (PEP 503): https://peps.python.org/pep-0503
if url.start_with?("https://files.pythonhosted.org/packages")
extra_urls = Homebrew::EnvConfig.pip_index_urls.map do |pip_index_url|
url.sub("https://files.pythonhosted.org", pip_index_url.chomp("/simple"))
end
urls = extra_urls + urls
end

urls
end

Expand Down
1 change: 1 addition & 0 deletions bin/brew
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,7 @@ PATH="/usr/bin:/bin:/usr/sbin:/sbin"
FILTERED_ENV=()
ENV_VAR_NAMES=(
HOME SHELL PATH TERM TERMINFO TERMINFO_DIRS COLUMNS DISPLAY LOGNAME USER CI SSH_AUTH_SOCK SUDO_ASKPASS
PIP_INDEX_URL PIP_EXTRA_INDEX_URL
http_proxy https_proxy ftp_proxy no_proxy all_proxy HTTPS_PROXY FTP_PROXY ALL_PROXY
GITHUB_ACTIONS GITHUB_WORKSPACE GITHUB_ACTIONS_HOMEBREW_SELF_HOSTED
GITHUB_REPOSITORY GITHUB_RUN_ID GITHUB_RUN_ATTEMPT GITHUB_SHA GITHUB_HEAD_REF GITHUB_BASE_REF GITHUB_REF
Expand Down

0 comments on commit a9ef3ae

Please sign in to comment.