From d0b4001221896f24e883207d9a888280ac68a9a3 Mon Sep 17 00:00:00 2001 From: Ewoud Kohl van Wijngaarden Date: Tue, 24 Jan 2023 16:54:18 +0100 Subject: [PATCH] Lazy load required classes This allows requiring puppet-syntax without loading all of Puppet, which helps speed up other rake commands. --- lib/puppet-syntax.rb | 8 ++++---- lib/puppet-syntax/manifests.rb | 1 + lib/puppet-syntax/templates.rb | 2 +- 3 files changed, 6 insertions(+), 5 deletions(-) diff --git a/lib/puppet-syntax.rb b/lib/puppet-syntax.rb index 9894654..03a0540 100644 --- a/lib/puppet-syntax.rb +++ b/lib/puppet-syntax.rb @@ -1,10 +1,10 @@ require "puppet-syntax/version" -require "puppet-syntax/manifests" -require "puppet-syntax/templates" -require "puppet-syntax/hiera" -require "puppet/version" module PuppetSyntax + autoload :Hiera, 'puppet-syntax/hiera' + autoload :Manifests, 'puppet-syntax/manifests' + autoload :Templates, 'puppet-syntax/templates' + @exclude_paths = [] @hieradata_paths = [ "**/data/**/*.*{yaml,yml}", diff --git a/lib/puppet-syntax/manifests.rb b/lib/puppet-syntax/manifests.rb index 58fe8a7..2dcf3e6 100644 --- a/lib/puppet-syntax/manifests.rb +++ b/lib/puppet-syntax/manifests.rb @@ -3,6 +3,7 @@ class Manifests def check(filelist) raise "Expected an array of files" unless filelist.is_a?(Array) require 'puppet' + require 'puppet/version' require 'puppet/face' require 'puppet/test/test_helper' diff --git a/lib/puppet-syntax/templates.rb b/lib/puppet-syntax/templates.rb index eb63f20..38c47df 100644 --- a/lib/puppet-syntax/templates.rb +++ b/lib/puppet-syntax/templates.rb @@ -1,5 +1,4 @@ require 'erb' -require 'puppet' require 'stringio' module PuppetSyntax @@ -30,6 +29,7 @@ def check(filelist) end def validate_epp(filename) + require 'puppet/error' require 'puppet/pops' result = { warnings: [], errors: [] } formatter = Puppet::Pops::Validation::DiagnosticFormatterPuppetStyle.new