Skip to content

Commit 210a858

Browse files
simideivid-rodriguez
authored andcommitted
Merge pull request #7612 from rubygems/deivid-rodriguez/circular-require
Fix circular require warning (cherry picked from commit 0ecd098)
1 parent 7b14e01 commit 210a858

File tree

3 files changed

+91
-78
lines changed

3 files changed

+91
-78
lines changed

bundler/spec/runtime/setup_spec.rb

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -767,6 +767,18 @@ def clean_load_path(lp)
767767
expect(err).to be_empty
768768
end
769769

770+
it "can require rubygems without warnings, when using a local cache", rubygems: ">= 3.5.10" do
771+
install_gemfile <<-G
772+
source "#{file_uri_for(gem_repo1)}"
773+
gem "rack"
774+
G
775+
776+
bundle "package"
777+
bundle %(exec ruby -w -e "require 'rubygems'")
778+
779+
expect(err).to be_empty
780+
end
781+
770782
context "when the user has `MANPATH` set", :man do
771783
before { ENV["MANPATH"] = "/foo#{File::PATH_SEPARATOR}" }
772784

lib/rubygems/deprecate.rb

Lines changed: 79 additions & 77 deletions
Original file line numberDiff line numberDiff line change
@@ -69,99 +69,101 @@
6969
# end
7070
# end
7171

72-
module Gem::Deprecate
73-
def self.skip # :nodoc:
74-
@skip ||= false
75-
end
72+
module Gem
73+
module Deprecate
74+
def self.skip # :nodoc:
75+
@skip ||= false
76+
end
7677

77-
def self.skip=(v) # :nodoc:
78-
@skip = v
79-
end
78+
def self.skip=(v) # :nodoc:
79+
@skip = v
80+
end
8081

81-
##
82-
# Temporarily turn off warnings. Intended for tests only.
82+
##
83+
# Temporarily turn off warnings. Intended for tests only.
8384

84-
def skip_during
85-
original = Gem::Deprecate.skip
86-
Gem::Deprecate.skip = true
87-
yield
88-
ensure
89-
Gem::Deprecate.skip = original
90-
end
85+
def skip_during
86+
original = Gem::Deprecate.skip
87+
Gem::Deprecate.skip = true
88+
yield
89+
ensure
90+
Gem::Deprecate.skip = original
91+
end
9192

92-
def self.next_rubygems_major_version # :nodoc:
93-
Gem::Version.new(Gem.rubygems_version.segments.first).bump
94-
end
93+
def self.next_rubygems_major_version # :nodoc:
94+
Gem::Version.new(Gem.rubygems_version.segments.first).bump
95+
end
9596

96-
##
97-
# Simple deprecation method that deprecates +name+ by wrapping it up
98-
# in a dummy method. It warns on each call to the dummy method
99-
# telling the user of +repl+ (unless +repl+ is :none) and the
100-
# year/month that it is planned to go away.
97+
##
98+
# Simple deprecation method that deprecates +name+ by wrapping it up
99+
# in a dummy method. It warns on each call to the dummy method
100+
# telling the user of +repl+ (unless +repl+ is :none) and the
101+
# year/month that it is planned to go away.
101102

102-
def deprecate(name, repl, year, month)
103-
class_eval do
104-
old = "_deprecated_#{name}"
105-
alias_method old, name
106-
define_method name do |*args, &block|
107-
klass = is_a? Module
108-
target = klass ? "#{self}." : "#{self.class}#"
109-
msg = [
110-
"NOTE: #{target}#{name} is deprecated",
111-
repl == :none ? " with no replacement" : "; use #{repl} instead",
112-
format(". It will be removed on or after %4d-%02d.", year, month),
113-
"\n#{target}#{name} called from #{Gem.location_of_caller.join(":")}",
114-
]
115-
warn "#{msg.join}." unless Gem::Deprecate.skip
116-
send old, *args, &block
103+
def deprecate(name, repl, year, month)
104+
class_eval do
105+
old = "_deprecated_#{name}"
106+
alias_method old, name
107+
define_method name do |*args, &block|
108+
klass = is_a? Module
109+
target = klass ? "#{self}." : "#{self.class}#"
110+
msg = [
111+
"NOTE: #{target}#{name} is deprecated",
112+
repl == :none ? " with no replacement" : "; use #{repl} instead",
113+
format(". It will be removed on or after %4d-%02d.", year, month),
114+
"\n#{target}#{name} called from #{Gem.location_of_caller.join(":")}",
115+
]
116+
warn "#{msg.join}." unless Gem::Deprecate.skip
117+
send old, *args, &block
118+
end
119+
ruby2_keywords name if respond_to?(:ruby2_keywords, true)
117120
end
118-
ruby2_keywords name if respond_to?(:ruby2_keywords, true)
119121
end
120-
end
121122

122-
##
123-
# Simple deprecation method that deprecates +name+ by wrapping it up
124-
# in a dummy method. It warns on each call to the dummy method
125-
# telling the user of +repl+ (unless +repl+ is :none) and the
126-
# Rubygems version that it is planned to go away.
123+
##
124+
# Simple deprecation method that deprecates +name+ by wrapping it up
125+
# in a dummy method. It warns on each call to the dummy method
126+
# telling the user of +repl+ (unless +repl+ is :none) and the
127+
# Rubygems version that it is planned to go away.
127128

128-
def rubygems_deprecate(name, replacement=:none)
129-
class_eval do
130-
old = "_deprecated_#{name}"
131-
alias_method old, name
132-
define_method name do |*args, &block|
133-
klass = is_a? Module
134-
target = klass ? "#{self}." : "#{self.class}#"
135-
msg = [
136-
"NOTE: #{target}#{name} is deprecated",
137-
replacement == :none ? " with no replacement" : "; use #{replacement} instead",
138-
". It will be removed in Rubygems #{Gem::Deprecate.next_rubygems_major_version}",
139-
"\n#{target}#{name} called from #{Gem.location_of_caller.join(":")}",
140-
]
141-
warn "#{msg.join}." unless Gem::Deprecate.skip
142-
send old, *args, &block
129+
def rubygems_deprecate(name, replacement=:none)
130+
class_eval do
131+
old = "_deprecated_#{name}"
132+
alias_method old, name
133+
define_method name do |*args, &block|
134+
klass = is_a? Module
135+
target = klass ? "#{self}." : "#{self.class}#"
136+
msg = [
137+
"NOTE: #{target}#{name} is deprecated",
138+
replacement == :none ? " with no replacement" : "; use #{replacement} instead",
139+
". It will be removed in Rubygems #{Gem::Deprecate.next_rubygems_major_version}",
140+
"\n#{target}#{name} called from #{Gem.location_of_caller.join(":")}",
141+
]
142+
warn "#{msg.join}." unless Gem::Deprecate.skip
143+
send old, *args, &block
144+
end
145+
ruby2_keywords name if respond_to?(:ruby2_keywords, true)
143146
end
144-
ruby2_keywords name if respond_to?(:ruby2_keywords, true)
145147
end
146-
end
147148

148-
# Deprecation method to deprecate Rubygems commands
149-
def rubygems_deprecate_command(version = Gem::Deprecate.next_rubygems_major_version)
150-
class_eval do
151-
define_method "deprecated?" do
152-
true
153-
end
149+
# Deprecation method to deprecate Rubygems commands
150+
def rubygems_deprecate_command(version = Gem::Deprecate.next_rubygems_major_version)
151+
class_eval do
152+
define_method "deprecated?" do
153+
true
154+
end
154155

155-
define_method "deprecation_warning" do
156-
msg = [
157-
"#{command} command is deprecated",
158-
". It will be removed in Rubygems #{version}.\n",
159-
]
156+
define_method "deprecation_warning" do
157+
msg = [
158+
"#{command} command is deprecated",
159+
". It will be removed in Rubygems #{version}.\n",
160+
]
160161

161-
alert_warning msg.join.to_s unless Gem::Deprecate.skip
162+
alert_warning msg.join.to_s unless Gem::Deprecate.skip
163+
end
162164
end
163165
end
164-
end
165166

166-
module_function :rubygems_deprecate, :rubygems_deprecate_command, :skip_during
167+
module_function :rubygems_deprecate, :rubygems_deprecate_command, :skip_during
168+
end
167169
end

lib/rubygems/package.rb

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77

88
# rubocop:enable Style/AsciiComments
99

10-
require_relative "../rubygems"
1110
require_relative "security"
1211
require_relative "user_interaction"
1312

0 commit comments

Comments
 (0)