Skip to content

Pass calling scope to stdlib::ensure_packages from shim #1366

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

Merged
merged 1 commit into from
Jun 15, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -92,11 +92,16 @@ task :regenerate_unamespaced_shims do
Dir['lib/puppet/functions/*.rb'].each do |filename|
content = File.read(filename)

unless content =~ /@summary DEPRECATED. Use the namespaced function/
unless content =~ /@summary DEPRECATED\. Use the namespaced function/
warn("#{filename} does not look like a deprecation shim (skipping)")
next
end

if content =~ /InternalFunction/
warn("#{filename} is a special case. Not regenerating a shim for this file")
next
end

function_name = File.basename(filename, '.rb')

File.write(filename, <<~CODE)
Expand Down
9 changes: 4 additions & 5 deletions lib/puppet/functions/ensure_packages.rb
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
# frozen_string_literal: true

# THIS FILE WAS GENERATED BY `rake regenerate_unamespaced_shims`

# @summary DEPRECATED. Use the namespaced function [`stdlib::ensure_packages`](#stdlibensure_packages) instead.
Copy link
Collaborator

Choose a reason for hiding this comment

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

Hum, maybe also change this line because it is what triggers the rake task that generated this code:
https://github.com/puppetlabs/puppetlabs-stdlib/blob/main/Rakefile#L95

Suggested change
# @summary DEPRECATED. Use the namespaced function [`stdlib::ensure_packages`](#stdlibensure_packages) instead.
# @summary DEPRECATED. Use the scoped and namespaced function [`stdlib::ensure_packages`](#stdlibensure_packages) instead.

Very hackish :-/

Otherwise we can search for Puppet::Functions\.create_function\(.*, Puppet::Functions::InternalFunction\) and generate different code if we find it. Also a bit hackish.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

It's more an internal detail. Not sure we really need to spell it out to users. Just not break things for them! :)

Are we likely to be running the rake task anymore?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

@smortex Now that I've updated the rake task to ignore this file, I've just got what you were getting at!

Puppet::Functions.create_function(:ensure_packages) do
Puppet::Functions.create_function(:ensure_packages, Puppet::Functions::InternalFunction) do
dispatch :deprecation_gen do
scope_param
repeated_param 'Any', :args
end
def deprecation_gen(*args)
def deprecation_gen(scope, *args)
call_function('deprecation', 'ensure_packages', 'This function is deprecated, please use stdlib::ensure_packages instead.')
call_function('stdlib::ensure_packages', *args)
scope.call_function('stdlib::ensure_packages', args)
end
end