Skip to content

Commit 233d8b3

Browse files
authored
Merge pull request #6097 from Magisus/master
Merge 5.0.x -> master
2 parents 7eb7328 + 2632fb7 commit 233d8b3

File tree

18 files changed

+268
-52
lines changed

18 files changed

+268
-52
lines changed

lib/puppet/face/module/search.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323

2424
when_invoked do |term, options|
2525
Puppet::ModuleTool.set_option_defaults options
26-
Puppet::ModuleTool::Applications::Searcher.new(term, Puppet::Forge.new, options).run
26+
Puppet::ModuleTool::Applications::Searcher.new(term, Puppet::Forge.new(options[:module_repository] || Puppet[:module_repository], options[:strict_semver]), options).run
2727
end
2828

2929
when_rendering :console do |results, term, options|

lib/puppet/forge.rb

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,10 @@ class Puppet::Forge < SemanticPuppet::Dependency::Source
1919

2020
attr_reader :host, :repository
2121

22-
def initialize(host = Puppet[:module_repository])
22+
def initialize(host = Puppet[:module_repository], strict_semver = true)
2323
@host = host
2424
@repository = Puppet::Forge::Repository.new(host, USER_AGENT)
25+
@strict_semver = strict_semver
2526
end
2627

2728
# Return a list of module metadata hashes that match the search query.
@@ -216,7 +217,7 @@ def process(list)
216217
l = list.map do |release|
217218
metadata = release['metadata']
218219
begin
219-
ModuleRelease.new(self, release)
220+
ModuleRelease.new(self, release, @strict_semver)
220221
rescue ArgumentError => e
221222
Puppet.warning _("Cannot consider release %{name}-%{version}: %{error}") % { name: metadata['name'], version: metadata['version'], error: e }
222223
false

lib/puppet/module.rb

Lines changed: 58 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
require 'puppet/util/logging'
22
require 'json'
3+
require 'semantic_puppet/gem_version'
34

45
# Support for modules
56
class Puppet::Module
@@ -52,6 +53,32 @@ def self.is_module_namespaced_name?(name)
5253
return false
5354
end
5455

56+
# @api private
57+
def self.parse_range(range, strict)
58+
@parse_range_method ||= SemanticPuppet::VersionRange.method(:parse)
59+
if @parse_range_method.arity == 1
60+
@semver_gem_version ||= SemanticPuppet::Version.parse(SemanticPuppet::VERSION)
61+
62+
# Give user a heads-up if the desired strict setting cannot be honored
63+
if strict
64+
if @semver_gem_version.major < 1
65+
Puppet.warn_once('strict_version_ranges', 'version_range_cannot_be_strict',
66+
_('VersionRanges will never be strict when using non-vendored SemanticPuppet gem, version %{version}') % { version: @semver_gem_version},
67+
:default, :default, :notice)
68+
end
69+
else
70+
if @semver_gem_version.major >= 1
71+
Puppet.warn_once('strict_version_ranges', 'version_range_always_strict',
72+
_('VersionRanges will always be strict when using non-vendored SemanticPuppet gem, version %{version}') % { version: @semver_gem_version},
73+
:default, :default, :notice)
74+
end
75+
end
76+
@parse_range_method.call(range)
77+
else
78+
@parse_range_method.call(range, strict)
79+
end
80+
end
81+
5582
attr_reader :name, :environment, :path, :metadata
5683
attr_writer :environment
5784

@@ -68,6 +95,17 @@ def initialize(name, path, environment, strict_semver = true)
6895
load_metadata
6996

7097
@absolute_path_to_manifests = Puppet::FileSystem::PathPattern.absolute(manifests)
98+
99+
# i18n initialization for modules
100+
if Puppet::GETTEXT_AVAILABLE
101+
begin
102+
initialize_i18n
103+
rescue Exception => e
104+
Puppet.warning _("GettextSetup initialization for %{module_name} failed with: %{error_message}") % { module_name: name, error_message: e.message }
105+
end
106+
else
107+
Puppet.warning _("GettextSetup is not available, skipping GettextSetup initialization for %{module_name}.") % { module_name: name }
108+
end
71109
end
72110

73111
# @deprecated The puppetversion module metadata field is no longer used.
@@ -328,7 +366,7 @@ def unmet_dependencies
328366

329367
if version_string
330368
begin
331-
required_version_semver_range = SemanticPuppet::VersionRange.parse(version_string, @strict_semver)
369+
required_version_semver_range = self.class.parse_range(version_string, @strict_semver)
332370
actual_version_semver = SemanticPuppet::Version.parse(dep_mod.version)
333371
rescue ArgumentError
334372
error_details[:reason] = :non_semantic_version
@@ -358,8 +396,27 @@ def strict_semver?
358396
@strict_semver
359397
end
360398

399+
def initialize_i18n
400+
module_name = @forge_name.gsub("/","-") if @forge_name
401+
return if module_name.nil? || i18n_initialized?(module_name)
402+
403+
locales_path = File.absolute_path('locales', path)
404+
405+
begin
406+
GettextSetup.initialize(locales_path)
407+
Puppet.debug "#{module_name} initialized for i18n: #{GettextSetup.translation_repositories[module_name]}"
408+
rescue
409+
config_path = File.absolute_path('config.yaml', locales_path)
410+
Puppet.debug "Could not find locales configuration file for #{module_name} at #{config_path}. Skipping i18n initialization."
411+
end
412+
end
413+
361414
private
362415

416+
def i18n_initialized?(module_name)
417+
GettextSetup.translation_repositories.has_key? module_name
418+
end
419+
363420
def wanted_manifests_from(pattern)
364421
begin
365422
extended = File.extname(pattern).empty? ? "#{pattern}.pp" : pattern

lib/puppet/module_tool.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ def self.set_option_defaults(options)
132132
options[:target_dir] = face_environment.full_modulepath.first
133133

134134
# Default false to retain backward compatibility with SemanticPuppet 0.1.4
135-
options[:strict_semver] = false
135+
options[:strict_semver] = false unless options.include?(:strict_semver)
136136
end
137137

138138
# Given a hash of options, we should discover or create a
@@ -174,7 +174,7 @@ def self.parse_module_dependency(where, dep, strict_semver = true)
174174
range = dep['version_requirement'] || '>= 0.0.0'
175175

176176
begin
177-
parsed_range = SemanticPuppet::VersionRange.parse(range, strict_semver)
177+
parsed_range = Module.parse_range(range, strict_semver)
178178
rescue ArgumentError => e
179179
Puppet.debug "Error in #{where} parsing dependency #{dep_name} (#{e.message}); using empty range."
180180
parsed_range = SemanticPuppet::VersionRange::EMPTY_RANGE

lib/puppet/module_tool/applications/installer.rb

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ def run
6060
begin
6161
if installed_module = installed_modules[name]
6262
unless forced?
63-
if SemanticPuppet::VersionRange.parse(version, @strict_semver).include? installed_module.version
63+
if Puppet::Module.parse_range(version, @strict_semver).include? installed_module.version
6464
results[:result] = :noop
6565
results[:version] = installed_module.version
6666
return results
@@ -104,15 +104,15 @@ def run
104104
# locking it to upgrades within the same major version.
105105
installed_range = ">=#{version} #{version.major}.x"
106106
graph.add_constraint('installed', mod, installed_range) do |node|
107-
SemanticPuppet::VersionRange.parse(installed_range, @strict_semver).include? node.version
107+
Puppet::Module.parse_range(installed_range, @strict_semver).include? node.version
108108
end
109109

110110
release.mod.dependencies.each do |dep|
111111
dep_name = dep['name'].tr('/', '-')
112112

113113
range = dep['version_requirement']
114114
graph.add_constraint("#{mod} constraint", dep_name, range) do |node|
115-
SemanticPuppet::VersionRange.parse(range, @strict_semver).include? node.version
115+
Puppet::Module.parse_range(range, @strict_semver).include? node.version
116116
end
117117
end
118118
end
@@ -186,7 +186,7 @@ def run
186186
private
187187

188188
def module_repository
189-
@repo ||= Puppet::Forge.new
189+
@repo ||= Puppet::Forge.new(Puppet[:module_repository], @strict_semver)
190190
end
191191

192192
def local_tarball_source
@@ -206,7 +206,7 @@ def installed_modules
206206
end
207207

208208
def build_single_module_graph(name, version)
209-
range = SemanticPuppet::VersionRange.parse(version, @strict_semver)
209+
range = Puppet::Module.parse_range(version, @strict_semver)
210210
graph = SemanticPuppet::Dependency::Graph.new(name => range)
211211
releases = SemanticPuppet::Dependency.fetch_releases(name)
212212
releases.each { |release| release.dependencies.clear }

lib/puppet/module_tool/applications/uninstaller.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ def find_installed_module
5858
:path => mod.modulepath,
5959
}
6060
if @options[:version] && mod.version
61-
next unless SemanticPuppet::VersionRange.parse(@options[:version], @strict_semver).include?(SemanticPuppet::Version.parse(mod.version))
61+
next unless Puppet::Module.parse_range(@options[:version], @strict_semver).include?(SemanticPuppet::Version.parse(mod.version))
6262
end
6363
@installed << mod
6464
elsif mod_name =~ /#{@name}/

lib/puppet/module_tool/applications/upgrader.rb

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ def installed_release.priority
9191
if available_versions.empty?
9292
raise NoCandidateReleasesError, results.merge(:module_name => name, :source => module_repository.host)
9393
elsif results[:requested_version] != :latest
94-
requested = SemanticPuppet::VersionRange.parse(results[:requested_version], @strict_semver)
94+
requested = Puppet::Module.parse_range(results[:requested_version], @strict_semver)
9595
unless available_versions.any? {|m| requested.include? m.version}
9696
raise NoCandidateReleasesError, results.merge(:module_name => name, :source => module_repository.host)
9797
end
@@ -120,15 +120,15 @@ def installed_release.priority
120120
# module, locking it to upgrades within the same major version.
121121
installed_range = ">=#{version} #{version.major}.x"
122122
graph.add_constraint('installed', installed_module, installed_range) do |node|
123-
SemanticPuppet::VersionRange.parse(installed_range, @strict_semver).include? node.version
123+
Puppet::Module.parse_range(installed_range, @strict_semver).include? node.version
124124
end
125125

126126
release.mod.dependencies.each do |dep|
127127
dep_name = dep['name'].tr('/', '-')
128128

129129
range = dep['version_requirement']
130130
graph.add_constraint("#{installed_module} constraint", dep_name, range) do |node|
131-
SemanticPuppet::VersionRange.parse(range, @strict_semver).include? node.version
131+
Puppet::Module.parse_range(range, @strict_semver).include? node.version
132132
end
133133
end
134134
end
@@ -216,7 +216,7 @@ def installed_release.priority
216216

217217
private
218218
def module_repository
219-
@repo ||= Puppet::Forge.new
219+
@repo ||= Puppet::Forge.new(Puppet[:module_repository], @strict_semver)
220220
end
221221

222222
def installed_modules_source
@@ -228,7 +228,7 @@ def installed_modules
228228
end
229229

230230
def build_single_module_graph(name, version)
231-
range = SemanticPuppet::VersionRange.parse(version, @strict_semver)
231+
range = Puppet::Module.parse_range(version, @strict_semver)
232232
graph = SemanticPuppet::Dependency::Graph.new(name => range)
233233
releases = SemanticPuppet::Dependency.fetch_releases(name)
234234
releases.each { |release| release.dependencies.clear }

lib/puppet/module_tool/shared_behaviors.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,10 +76,10 @@ def resolve_constraints(dependencies, source = [{:name => :you}], seen = {}, act
7676
}
7777

7878
if forced?
79-
range = SemanticPuppet::VersionRange.parse(@version, @strict_semver) rescue SemanticPuppet::VersionRange.parse('>= 0.0.0', @strict_semver)
79+
range = Puppet::Module.parse_range(@version, @strict_semver) rescue Puppet::Module.parse_range('>= 0.0.0', @strict_semver)
8080
else
8181
range = (@conditions[mod]).map do |r|
82-
SemanticPuppet::VersionRange.parse(r[:dependency], @strict_semver) rescue SemanticPuppet::VersionRange.parse('>= 0.0.0', @strict_semver)
82+
Puppet::Module.parse_range(r[:dependency], @strict_semver) rescue Puppet::Module.parse_range('>= 0.0.0', @strict_semver)
8383
end.inject(&:&)
8484
end
8585

lib/puppet/pops/lookup/lookup_adapter.rb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,8 @@ def lookup(key, lookup_invocation, merge)
6868
end
6969

7070
def lookup_global(key, lookup_invocation, merge_strategy)
71-
terminus = Puppet[:data_binding_terminus]
71+
# hiera_xxx will always use global_provider regardless of data_binding_terminus setting
72+
terminus = lookup_invocation.hiera_xxx_call? ? :hiera : Puppet[:data_binding_terminus]
7273
case terminus
7374
when :hiera, 'hiera'
7475
provider = global_provider(lookup_invocation)

lib/puppet/util/logging.rb

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -155,26 +155,30 @@ def puppet_deprecation_warning(message, options = {})
155155
FILE_AND_LINE = MM::TUPLE
156156
FILE_NO_LINE = MM.new(MM::NOT_NIL, nil).freeze
157157
NO_FILE_LINE = MM.new(nil, MM::NOT_NIL).freeze
158+
SUPPRESS_FILE_LINE = MM.new(:default, :default).freeze
158159

159160
# Logs a (non deprecation) warning once for a given key.
160161
#
161162
# @param kind [String] The kind of warning. The
162163
# kind must be one of the defined kinds for the Puppet[:disable_warnings] setting.
163164
# @param message [String] The message to log (logs via warning)
164165
# @param key [String] Key used to make this warning unique
165-
# @param file [String,nil] the File related to the warning
166-
# @param line [Integer,nil] the Line number related to the warning
166+
# @param file [String,:default,nil] the File related to the warning
167+
# @param line [Integer,:default,nil] the Line number related to the warning
167168
# warning as unique
169+
# @param level [Symbol] log level to use, defaults to :warning
168170
#
169171
# Either :file and :line and/or :key must be passed.
170-
def warn_once(kind, key, message, file = nil, line = nil)
172+
def warn_once(kind, key, message, file = nil, line = nil, level = :warning)
171173
return if Puppet[:disable_warnings].include?(kind)
172174
$unique_warnings ||= {}
173175
if $unique_warnings.length < 100 then
174176
if (! $unique_warnings.has_key?(key)) then
175177
$unique_warnings[key] = message
176178
call_trace =
177179
case MM.new(file, line)
180+
when SUPPRESS_FILE_LINE
181+
''
178182
when FILE_AND_LINE
179183
_("\n (at %{file}:%{line})") % { file: file, line: line }
180184
when FILE_NO_LINE
@@ -184,7 +188,7 @@ def warn_once(kind, key, message, file = nil, line = nil)
184188
else
185189
_("\n (file & line not available)")
186190
end
187-
warning("#{message}#{call_trace}")
191+
send_log(level, "#{message}#{call_trace}")
188192
end
189193
end
190194
end

0 commit comments

Comments
 (0)