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

resource: automatic determine mirrors for glibc-bootstrap and PyPI resources #13875

Merged
merged 3 commits into from
Sep 18, 2022
Merged
Show file tree
Hide file tree
Changes from 2 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
4 changes: 4 additions & 0 deletions Library/Homebrew/env_config.rb
Original file line number Diff line number Diff line change
Expand Up @@ -318,6 +318,10 @@ module EnvConfig
"outdated.",
boolean: true,
},
HOMEBREW_PIP_INDEX_URL: {
description: "If set, `brew install <formula>` will use this URL to download PyPI package resources.",
default_text: "`https://pypi.org/simple`.",
Copy link
Contributor Author

@XuehaiPan XuehaiPan Sep 15, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This would be unset by default and will not be initialized from PIP_INDEX_URL. The user need to set a new Homebrew-specific variable.

https://pypi.org/packages and https://files.pythonhosted.org/packages (this one is what we use in formulae) are mutually identical. We use https://pypi.org/simple (suffix as simple rather than package) in the docs here because https://files.pythonhosted.org/simple is private.

},
HOMEBREW_PRY: {
description: "If set, use Pry for the `brew irb` command.",
boolean: true,
Expand Down
32 changes: 30 additions & 2 deletions Library/Homebrew/resource.rb
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,11 @@ def owner=(owner)
end

def downloader
@downloader ||= download_strategy.new(url, download_name, version,
mirrors: mirrors.dup, **specs)
return @downloader if @downloader.present?

url, *mirrors = determine_url_mirrors
@downloader = download_strategy.new(url, download_name, version,
mirrors: mirrors, **specs)
end

# Removes /s from resource names; this allows Go package names
Expand Down Expand Up @@ -277,6 +280,31 @@ def detect_version(val)
version unless version.null?
end

def determine_url_mirrors
extra_urls = []

# glibc-bootstrap
if url.start_with?("https://github.com/Homebrew/glibc-bootstrap/releases/download")
if Homebrew::EnvConfig.artifact_domain.present?
extra_urls << url.sub("https://github.com", Homebrew::EnvConfig.artifact_domain)
end
if Homebrew::EnvConfig.bottle_domain != HOMEBREW_BOTTLE_DEFAULT_DOMAIN
tag, filename = url.split("/").last(2)
extra_urls << "#{Homebrew::EnvConfig.bottle_domain}/glibc-bootstrap/#{tag}/#{filename}"
end
end

# PyPI packages: PEP 503 – Simple Repository API <https://peps.python.org/pep-0503>
if Homebrew::EnvConfig.pip_index_url.present?
pip_index_base_url = Homebrew::EnvConfig.pip_index_url.chomp("/").chomp("/simple")
%w[https://files.pythonhosted.org https://pypi.org].each do |base_url|
extra_urls << url.sub(base_url, pip_index_base_url) if url.start_with?("#{base_url}/packages")
end
end

[*extra_urls, url, *mirrors].uniq
end

# A resource containing a Go package.
class Go < Resource
def stage(target, &block)
Expand Down
2 changes: 2 additions & 0 deletions Library/Homebrew/sorbet/rbi/hidden-definitions/hidden.rbi
Original file line number Diff line number Diff line change
Expand Up @@ -2655,6 +2655,8 @@ module Homebrew::EnvConfig

def self.no_proxy(); end

def self.pip_index_url(); end

def self.pry?(); end

def self.simulate_macos_on_linux?(); end
Expand Down