mirror of
https://github.com/Homebrew/brew.git
synced 2025-07-14 16:09:03 +08:00
Fix some Style/FetchEnvVar offences
This commit is contained in:
parent
cd73e6bac5
commit
40bbdc659e
@ -57,15 +57,15 @@ module Homebrew
|
||||
reason: "reporting test flakiness")
|
||||
end
|
||||
|
||||
ENV["BUILDPULSE_ACCESS_KEY_ID"] = ENV["HOMEBREW_BUILDPULSE_ACCESS_KEY_ID"]
|
||||
ENV["BUILDPULSE_SECRET_ACCESS_KEY"] = ENV["HOMEBREW_BUILDPULSE_SECRET_ACCESS_KEY"]
|
||||
ENV["BUILDPULSE_ACCESS_KEY_ID"] = ENV.fetch("HOMEBREW_BUILDPULSE_ACCESS_KEY_ID")
|
||||
ENV["BUILDPULSE_SECRET_ACCESS_KEY"] = ENV.fetch("HOMEBREW_BUILDPULSE_SECRET_ACCESS_KEY")
|
||||
|
||||
ohai "Sending test results to BuildPulse"
|
||||
|
||||
safe_system Formula["buildpulse-test-reporter"].opt_bin/"buildpulse-test-reporter",
|
||||
"submit", "#{HOMEBREW_LIBRARY_PATH}/test/junit",
|
||||
"--account-id", ENV["HOMEBREW_BUILDPULSE_ACCOUNT_ID"],
|
||||
"--repository-id", ENV["HOMEBREW_BUILDPULSE_REPOSITORY_ID"]
|
||||
"--account-id", ENV.fetch("HOMEBREW_BUILDPULSE_ACCOUNT_ID"),
|
||||
"--repository-id", ENV.fetch("HOMEBREW_BUILDPULSE_REPOSITORY_ID")
|
||||
end
|
||||
|
||||
def changed_test_files
|
||||
@ -212,7 +212,7 @@ module Homebrew
|
||||
ENV["HOMEBREW_TESTS_GEM_USER_DIR"] = gem_user_dir
|
||||
|
||||
# Let `bundle` in PATH find its gem.
|
||||
ENV["GEM_PATH"] = "#{ENV["GEM_PATH"]}:#{gem_user_dir}"
|
||||
ENV["GEM_PATH"] = "#{ENV.fetch("GEM_PATH")}:#{gem_user_dir}"
|
||||
|
||||
# Submit test flakiness information using BuildPulse
|
||||
# BUILDPULSE used in spec_helper.rb
|
||||
|
@ -541,7 +541,7 @@ module Homebrew
|
||||
end
|
||||
|
||||
def check_git_version
|
||||
minimum_version = ENV["HOMEBREW_MINIMUM_GIT_VERSION"]
|
||||
minimum_version = ENV.fetch("HOMEBREW_MINIMUM_GIT_VERSION")
|
||||
return unless Utils::Git.available?
|
||||
return if Version.create(Utils::Git.version) >= Version.create(minimum_version)
|
||||
|
||||
@ -668,7 +668,7 @@ module Homebrew
|
||||
end
|
||||
|
||||
def check_tmpdir
|
||||
tmpdir = ENV["TMPDIR"]
|
||||
tmpdir = ENV.fetch("TMPDIR", nil)
|
||||
return if tmpdir.nil? || File.directory?(tmpdir)
|
||||
|
||||
<<~EOS
|
||||
@ -828,7 +828,7 @@ module Homebrew
|
||||
cmd_map.reject! { |_cmd_name, cmd_paths| cmd_paths.size == 1 }
|
||||
return if cmd_map.empty?
|
||||
|
||||
if ENV["CI"] && cmd_map.keys.length == 1 &&
|
||||
if ENV["CI"].present? && cmd_map.keys.length == 1 &&
|
||||
cmd_map.keys.first == "brew-test-bot"
|
||||
return
|
||||
end
|
||||
@ -1007,7 +1007,7 @@ module Homebrew
|
||||
add_info "Cask Environment Variables:", ((locale_variables + environment_variables).sort.each do |var|
|
||||
next unless ENV.key?(var)
|
||||
|
||||
var = %Q(#{var}="#{ENV[var]}")
|
||||
var = %Q(#{var}="#{ENV.fetch(var)}")
|
||||
user_tilde(var)
|
||||
end)
|
||||
end
|
||||
|
@ -26,7 +26,7 @@ module Language
|
||||
end
|
||||
|
||||
def self.each_python(build, &block)
|
||||
original_pythonpath = ENV["PYTHONPATH"]
|
||||
original_pythonpath = ENV.fetch("PYTHONPATH", nil)
|
||||
pythons = { "python@3" => "python3",
|
||||
"pypy" => "pypy",
|
||||
"pypy3" => "pypy3" }
|
||||
|
@ -508,8 +508,8 @@ class BottleSpecification
|
||||
|
||||
prefix = Pathname(cellar).parent.to_s
|
||||
|
||||
cellar_relocatable = cellar.size >= HOMEBREW_CELLAR.to_s.size && ENV["HOMEBREW_RELOCATE_BUILD_PREFIX"]
|
||||
prefix_relocatable = prefix.size >= HOMEBREW_PREFIX.to_s.size && ENV["HOMEBREW_RELOCATE_BUILD_PREFIX"]
|
||||
cellar_relocatable = cellar.size >= HOMEBREW_CELLAR.to_s.size && ENV["HOMEBREW_RELOCATE_BUILD_PREFIX"].present?
|
||||
prefix_relocatable = prefix.size >= HOMEBREW_PREFIX.to_s.size && ENV["HOMEBREW_RELOCATE_BUILD_PREFIX"].present?
|
||||
|
||||
compatible_cellar = cellar == HOMEBREW_CELLAR.to_s || cellar_relocatable
|
||||
compatible_prefix = prefix == HOMEBREW_PREFIX.to_s || prefix_relocatable
|
||||
|
@ -1,7 +1,7 @@
|
||||
# typed: false
|
||||
# frozen_string_literal: true
|
||||
|
||||
homebrew_bootsnap_enabled = !ENV["HOMEBREW_NO_BOOTSNAP"] && ENV["HOMEBREW_BOOTSNAP"]
|
||||
homebrew_bootsnap_enabled = ENV["HOMEBREW_NO_BOOTSNAP"].nil? && !ENV["HOMEBREW_BOOTSNAP"].nil?
|
||||
|
||||
# portable ruby doesn't play nice with bootsnap
|
||||
# Can't use .exclude? here because we haven't required active_support yet.
|
||||
@ -24,14 +24,14 @@ if homebrew_bootsnap_enabled
|
||||
Homebrew.install_bundler_gems!(only_warn_on_failure: true)
|
||||
|
||||
ENV["HOMEBREW_BOOTSNAP_RETRY"] = "1"
|
||||
exec ENV["HOMEBREW_BREW_FILE"], *ARGV
|
||||
exec ENV.fetch("HOMEBREW_BREW_FILE"), *ARGV
|
||||
end
|
||||
end
|
||||
|
||||
ENV.delete("HOMEBREW_BOOTSNAP_RETRY")
|
||||
|
||||
if defined?(Bootsnap)
|
||||
cache = ENV["HOMEBREW_CACHE"] || ENV["HOMEBREW_DEFAULT_CACHE"]
|
||||
cache = ENV.fetch("HOMEBREW_CACHE", nil) || ENV.fetch("HOMEBREW_DEFAULT_CACHE", nil)
|
||||
# Can't use .blank? here because we haven't required active_support yet.
|
||||
raise "Needs HOMEBREW_CACHE or HOMEBREW_DEFAULT_CACHE!" if cache.nil? || cache.empty? # rubocop:disable Rails/Blank
|
||||
|
||||
|
@ -51,5 +51,5 @@ end.freeze
|
||||
# The Ruby path and args to use for forked Ruby calls
|
||||
HOMEBREW_RUBY_EXEC_ARGS = [
|
||||
RUBY_PATH,
|
||||
ENV["HOMEBREW_RUBY_WARNINGS"],
|
||||
ENV.fetch("HOMEBREW_RUBY_WARNINGS"),
|
||||
].freeze
|
||||
|
@ -19,9 +19,9 @@ describe Cask::Artifact::Pkg, :cask do
|
||||
sudo: true,
|
||||
print_stdout: true,
|
||||
env: {
|
||||
"LOGNAME" => ENV["USER"],
|
||||
"USER" => ENV["USER"],
|
||||
"USERNAME" => ENV["USER"],
|
||||
"LOGNAME" => ENV.fetch("USER"),
|
||||
"USER" => ENV.fetch("USER"),
|
||||
"USERNAME" => ENV.fetch("USER"),
|
||||
},
|
||||
)
|
||||
|
||||
@ -68,9 +68,9 @@ describe Cask::Artifact::Pkg, :cask do
|
||||
sudo: true,
|
||||
print_stdout: true,
|
||||
env: {
|
||||
"LOGNAME" => ENV["USER"],
|
||||
"USER" => ENV["USER"],
|
||||
"USERNAME" => ENV["USER"],
|
||||
"LOGNAME" => ENV.fetch("USER"),
|
||||
"USER" => ENV.fetch("USER"),
|
||||
"USERNAME" => ENV.fetch("USER"),
|
||||
},
|
||||
)
|
||||
|
||||
|
@ -8,7 +8,7 @@ describe "brew --caskroom" do
|
||||
|
||||
it "prints Homebrew's Caskroom", :integration_test do
|
||||
expect { brew_sh "--caskroom" }
|
||||
.to output("#{ENV["HOMEBREW_PREFIX"]}/Caskroom\n").to_stdout
|
||||
.to output("#{ENV.fetch("HOMEBREW_PREFIX")}/Caskroom\n").to_stdout
|
||||
.and not_to_output.to_stderr
|
||||
.and be_a_success
|
||||
end
|
||||
|
@ -8,7 +8,7 @@ describe "brew --cellar" do
|
||||
|
||||
it "prints Homebrew's Cellar", :integration_test do
|
||||
expect { brew_sh "--cellar" }
|
||||
.to output("#{ENV["HOMEBREW_CELLAR"]}\n").to_stdout
|
||||
.to output("#{ENV.fetch("HOMEBREW_CELLAR")}\n").to_stdout
|
||||
.and not_to_output.to_stderr
|
||||
.and be_a_success
|
||||
end
|
||||
|
@ -8,14 +8,14 @@ describe "brew --prefix" do
|
||||
|
||||
it "prints Homebrew's prefix", :integration_test do
|
||||
expect { brew_sh "--prefix" }
|
||||
.to output("#{ENV["HOMEBREW_PREFIX"]}\n").to_stdout
|
||||
.to output("#{ENV.fetch("HOMEBREW_PREFIX")}\n").to_stdout
|
||||
.and not_to_output.to_stderr
|
||||
.and be_a_success
|
||||
end
|
||||
|
||||
it "prints the prefix for a Formula", :integration_test do
|
||||
expect { brew_sh "--prefix", "wget" }
|
||||
.to output("#{ENV["HOMEBREW_PREFIX"]}/opt/wget\n").to_stdout
|
||||
.to output("#{ENV.fetch("HOMEBREW_PREFIX")}/opt/wget\n").to_stdout
|
||||
.and not_to_output.to_stderr
|
||||
.and be_a_success
|
||||
end
|
||||
|
@ -8,7 +8,7 @@ describe "brew --repository" do
|
||||
|
||||
it "prints Homebrew's repository", :integration_test do
|
||||
expect { brew_sh "--repository" }
|
||||
.to output("#{ENV["HOMEBREW_REPOSITORY"]}\n").to_stdout
|
||||
.to output("#{ENV.fetch("HOMEBREW_REPOSITORY")}\n").to_stdout
|
||||
.and not_to_output.to_stderr
|
||||
.and be_a_success
|
||||
end
|
||||
|
@ -35,7 +35,7 @@ require "find"
|
||||
require "byebug"
|
||||
require "timeout"
|
||||
|
||||
$LOAD_PATH.push(File.expand_path("#{ENV["HOMEBREW_LIBRARY"]}/Homebrew/test/support/lib"))
|
||||
$LOAD_PATH.push(File.expand_path("#{ENV.fetch("HOMEBREW_LIBRARY")}/Homebrew/test/support/lib"))
|
||||
|
||||
require_relative "../global"
|
||||
|
||||
|
@ -82,7 +82,6 @@ RSpec.shared_context "integration test" do # rubocop:disable RSpec/ContextWordin
|
||||
"HOMEBREW_BREW_FILE" => HOMEBREW_PREFIX/"bin/brew",
|
||||
"HOMEBREW_INTEGRATION_TEST" => command_id_from_args(args),
|
||||
"HOMEBREW_TEST_TMPDIR" => TEST_TMPDIR,
|
||||
"HOMEBREW_DEVELOPER" => ENV["HOMEBREW_DEVELOPER"],
|
||||
"HOMEBREW_DEV_CMD_RUN" => "true",
|
||||
"GEM_HOME" => nil,
|
||||
)
|
||||
@ -127,7 +126,7 @@ RSpec.shared_context "integration test" do # rubocop:disable RSpec/ContextWordin
|
||||
|
||||
def brew_sh(*args)
|
||||
Bundler.with_clean_env do
|
||||
stdout, stderr, status = Open3.capture3("#{ENV["HOMEBREW_PREFIX"]}/bin/brew", *args)
|
||||
stdout, stderr, status = Open3.capture3("#{ENV.fetch("HOMEBREW_PREFIX")}/bin/brew", *args)
|
||||
$stdout.print stdout
|
||||
$stderr.print stderr
|
||||
status
|
||||
@ -216,7 +215,7 @@ RSpec.shared_context "integration test" do # rubocop:disable RSpec/ContextWordin
|
||||
|
||||
full_name = Tap.fetch(name).full_name
|
||||
# Check to see if the original Homebrew process has taps we can use.
|
||||
system_tap_path = Pathname("#{ENV["HOMEBREW_LIBRARY"]}/Taps/#{full_name}")
|
||||
system_tap_path = Pathname("#{ENV.fetch("HOMEBREW_LIBRARY")}/Taps/#{full_name}")
|
||||
if system_tap_path.exist?
|
||||
system "git", "clone", "--shared", system_tap_path, tap.path
|
||||
system "git", "-C", tap.path, "checkout", "master"
|
||||
|
@ -3,10 +3,10 @@
|
||||
|
||||
raise "HOMEBREW_BREW_FILE was not exported! Please call bin/brew directly!" unless ENV["HOMEBREW_BREW_FILE"]
|
||||
|
||||
HOMEBREW_BREW_FILE = Pathname.new(ENV["HOMEBREW_BREW_FILE"]).freeze
|
||||
HOMEBREW_BREW_FILE = Pathname.new(ENV.fetch("HOMEBREW_BREW_FILE")).freeze
|
||||
|
||||
TEST_TMPDIR = ENV.fetch("HOMEBREW_TEST_TMPDIR") do |k|
|
||||
dir = Dir.mktmpdir("homebrew-tests-", ENV["HOMEBREW_TEMP"] || "/tmp")
|
||||
dir = Dir.mktmpdir("homebrew-tests-", ENV.fetch("HOMEBREW_TEMP"))
|
||||
at_exit do
|
||||
# Child processes inherit this at_exit handler, but we don't want them
|
||||
# to clean TEST_TMPDIR up prematurely (i.e., when they exit early for a test).
|
||||
@ -35,7 +35,7 @@ HOMEBREW_LOGS = (HOMEBREW_PREFIX.parent/"logs").freeze
|
||||
HOMEBREW_TEMP = (HOMEBREW_PREFIX.parent/"temp").freeze
|
||||
HOMEBREW_RUBY_EXEC_ARGS = [
|
||||
RUBY_PATH,
|
||||
ENV["HOMEBREW_RUBY_WARNINGS"],
|
||||
ENV.fetch("HOMEBREW_RUBY_WARNINGS"),
|
||||
"-I", HOMEBREW_LIBRARY_PATH/"test/support/lib"
|
||||
].freeze
|
||||
|
||||
|
@ -6,7 +6,7 @@ require "utils/user"
|
||||
describe User do
|
||||
subject { described_class.current }
|
||||
|
||||
it { is_expected.to eq ENV["USER"] }
|
||||
it { is_expected.to eq ENV.fetch("USER") }
|
||||
|
||||
describe "#gui?" do
|
||||
before do
|
||||
@ -17,8 +17,8 @@ describe User do
|
||||
context "when the current user is in a console session" do
|
||||
let(:who_output) {
|
||||
<<~EOS
|
||||
#{ENV["USER"]} console Oct 1 11:23
|
||||
#{ENV["USER"]} ttys001 Oct 1 11:25
|
||||
#{ENV.fetch("USER")} console Oct 1 11:23
|
||||
#{ENV.fetch("USER")} ttys001 Oct 1 11:25
|
||||
EOS
|
||||
}
|
||||
|
||||
@ -28,7 +28,7 @@ describe User do
|
||||
context "when the current user is not in a console session" do
|
||||
let(:who_output) {
|
||||
<<~EOS
|
||||
#{ENV["USER"]} ttys001 Oct 1 11:25
|
||||
#{ENV.fetch("USER")} ttys001 Oct 1 11:25
|
||||
fake_user ttys002 Oct 1 11:27
|
||||
EOS
|
||||
}
|
||||
|
@ -114,10 +114,10 @@ describe "globally-scoped helper methods" do
|
||||
ENV["LC_ALL"] = "en_US.UTF-8"
|
||||
|
||||
with_custom_locale("C") do
|
||||
expect(ENV["LC_ALL"]).to eq("C")
|
||||
expect(ENV.fetch("LC_ALL")).to eq("C")
|
||||
end
|
||||
|
||||
expect(ENV["LC_ALL"]).to eq("en_US.UTF-8")
|
||||
expect(ENV.fetch("LC_ALL")).to eq("en_US.UTF-8")
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -387,7 +387,7 @@ module Kernel
|
||||
|
||||
ENV["DISPLAY"] = Homebrew::EnvConfig.display
|
||||
|
||||
with_env(DBUS_SESSION_BUS_ADDRESS: ENV["HOMEBREW_DBUS_SESSION_BUS_ADDRESS"]) do
|
||||
with_env(DBUS_SESSION_BUS_ADDRESS: ENV.fetch("HOMEBREW_DBUS_SESSION_BUS_ADDRESS", nil)) do
|
||||
safe_system(browser, *args)
|
||||
end
|
||||
end
|
||||
|
@ -34,7 +34,7 @@ module Utils
|
||||
--data aip=1
|
||||
--data t=#{type}
|
||||
--data tid=#{analytics_id}
|
||||
--data cid=#{ENV["HOMEBREW_ANALYTICS_USER_UUID"]}
|
||||
--data cid=#{ENV.fetch("HOMEBREW_ANALYTICS_USER_UUID")}
|
||||
--data an=#{HOMEBREW_PRODUCT}
|
||||
--data av=#{HOMEBREW_VERSION}
|
||||
]
|
||||
|
@ -18,7 +18,7 @@ module Homebrew
|
||||
end
|
||||
|
||||
def gem_user_dir
|
||||
ENV["HOMEBREW_TESTS_GEM_USER_DIR"] || Gem.user_dir
|
||||
ENV.fetch("HOMEBREW_TESTS_GEM_USER_DIR", nil) || Gem.user_dir
|
||||
end
|
||||
|
||||
def gem_user_bindir
|
||||
@ -60,7 +60,7 @@ module Homebrew
|
||||
|
||||
# Set TMPDIR so Xcode's `make` doesn't fall back to `/var/tmp/`,
|
||||
# which may be not user-writable.
|
||||
ENV["TMPDIR"] = ENV["HOMEBREW_TEMP"]
|
||||
ENV["TMPDIR"] = ENV.fetch("HOMEBREW_TEMP", nil)
|
||||
|
||||
return unless setup_path
|
||||
|
||||
@ -108,7 +108,7 @@ module Homebrew
|
||||
|
||||
odie_if_defined <<~EOS
|
||||
the '#{name}' gem is installed but couldn't find '#{executable}' in the PATH:
|
||||
#{ENV["PATH"]}
|
||||
#{ENV.fetch("PATH")}
|
||||
EOS
|
||||
end
|
||||
|
||||
@ -129,11 +129,11 @@ module Homebrew
|
||||
end
|
||||
|
||||
def install_bundler_gems!(only_warn_on_failure: false, setup_path: true, groups: [])
|
||||
old_path = ENV["PATH"]
|
||||
old_gem_path = ENV["GEM_PATH"]
|
||||
old_gem_home = ENV["GEM_HOME"]
|
||||
old_bundle_gemfile = ENV["BUNDLE_GEMFILE"]
|
||||
old_bundle_with = ENV["BUNDLE_WITH"]
|
||||
old_path = ENV.fetch("PATH", nil)
|
||||
old_gem_path = ENV.fetch("GEM_PATH", nil)
|
||||
old_gem_home = ENV.fetch("GEM_HOME", nil)
|
||||
old_bundle_gemfile = ENV.fetch("BUNDLE_GEMFILE", nil)
|
||||
old_bundle_with = ENV.fetch("BUNDLE_WITH", nil)
|
||||
|
||||
install_bundler!
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user