Skip to content

Commit

Permalink
(maint) Clean up pdk/module requires
Browse files Browse the repository at this point in the history
  • Loading branch information
rodjek committed Sep 30, 2019
1 parent 5342fe9 commit 54ba34d
Show file tree
Hide file tree
Showing 10 changed files with 23 additions and 10 deletions.
1 change: 1 addition & 0 deletions lib/pdk/cli/build.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ module PDK::CLI

run do |opts, _args, _cmd|
require 'pdk/module/build'
require 'pdk/module/metadata'

# Make sure build is being run in a valid module directory with a metadata.json
PDK::CLI::Util.ensure_in_module!(
Expand Down
2 changes: 0 additions & 2 deletions lib/pdk/generate.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@
require 'pdk/generate/puppet_class'
require 'pdk/generate/task'
require 'pdk/generate/transport'
require 'pdk/module/metadata'
require 'pdk/module/templatedir'

module PDK
module Generate
Expand Down
6 changes: 4 additions & 2 deletions lib/pdk/generate/module.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@

require 'pdk'
require 'pdk/logger'
require 'pdk/module/metadata'
require 'pdk/module/templatedir'
require 'pdk/cli/util'
require 'pdk/cli/util/interview'
require 'pdk/cli/util/option_validator'
Expand All @@ -32,6 +30,8 @@ def self.validate_options(opts)
end

def self.invoke(opts = {})
require 'pdk/module/templatedir'

validate_options(opts) unless opts[:module_name].nil?

metadata = prepare_metadata(opts)
Expand Down Expand Up @@ -119,6 +119,8 @@ def self.username_from_login

def self.prepare_metadata(opts = {})
require 'pdk/answer_file'
require 'pdk/module/metadata'

opts[:username] = (opts[:username] || PDK.answers['forge_username'] || username_from_login).downcase

defaults = PDK::Module::Metadata::DEFAULTS.dup
Expand Down
4 changes: 2 additions & 2 deletions lib/pdk/generate/puppet_object.rb
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
require 'fileutils'

require 'pdk/logger'
require 'pdk/module/metadata'
require 'pdk/module/templatedir'
require 'pdk/template_file'
require 'pdk/util/filesystem'

Expand Down Expand Up @@ -258,6 +256,8 @@ def write_file(dest_path)
#
# @api private
def with_templates
require 'pdk/module/templatedir'

templates.each do |template|
if template[:uri].nil?
PDK.logger.debug(_('No %{dir_type} template found; trying next template directory.') % { dir_type: template[:type] })
Expand Down
5 changes: 4 additions & 1 deletion lib/pdk/module/build.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
require 'zlib'
require 'pathspec'
require 'find'
require 'pdk/module'
require 'pdk/tests/unit'

module PDK
Expand All @@ -26,6 +25,8 @@ def initialize(options = {})
#
# @return [Hash{String => Object}] The hash of metadata values.
def metadata
require 'pdk/module/metadata'

@metadata ||= PDK::Module::Metadata.from_file(File.join(module_dir, 'metadata.json')).data
end

Expand Down Expand Up @@ -268,6 +269,8 @@ def ignore_file
#
# @return [PathSpec] The populated ignore path matcher.
def ignored_files
require 'pdk/module'

@ignored_files ||=
begin
ignored = if ignore_file.nil?
Expand Down
8 changes: 6 additions & 2 deletions lib/pdk/module/convert.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
require 'pdk/generate/module'
require 'pdk/module/update_manager'
require 'pdk/util'
require 'pdk/report'

Expand Down Expand Up @@ -107,6 +105,8 @@ def needs_bundle_update?
end

def stage_changes!
require 'pdk/module/templatedir'

metadata_path = 'metadata.json'

PDK::Module::TemplateDir.new(template_uri, nil, true) do |templates|
Expand Down Expand Up @@ -145,6 +145,8 @@ def stage_changes!
end

def update_manager
require 'pdk/module/update_manager'

@update_manager ||= PDK::Module::UpdateManager.new
end

Expand All @@ -153,6 +155,8 @@ def template_uri
end

def update_metadata(metadata_path, template_metadata)
require 'pdk/generate/module'

if PDK::Util::Filesystem.file?(metadata_path)
unless PDK::Util::Filesystem.readable?(metadata_path)
raise PDK::CLI::ExitWithError, _('Unable to update module metadata; %{path} exists but it is not readable.') % {
Expand Down
2 changes: 2 additions & 0 deletions lib/pdk/util.rb
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,8 @@ def targets_relative_to_pwd(targets)

# TO-DO: Refactor replacement of lib/pdk/module/build.rb:metadata to use this function instead
def module_metadata
require 'pdk/module/metadata'

PDK::Module::Metadata.from_file(File.join(module_root, 'metadata.json')).data
end
module_function :module_metadata
Expand Down
3 changes: 2 additions & 1 deletion lib/pdk/validate/base_validator.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
require 'pdk'
require 'pdk/module'

module PDK
module Validate
Expand Down Expand Up @@ -81,6 +80,8 @@ def self.parse_targets(options)
end

def self.ignore_pathspec
require 'pdk/module'

ignore_pathspec = PDK::Module.default_ignored_pathspec(ignore_dotfiles?)

if respond_to?(:pattern_ignore)
Expand Down
1 change: 1 addition & 0 deletions spec/unit/pdk/module/metadata_spec.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
require 'spec_helper'
require 'pdk/module/metadata'

describe PDK::Module::Metadata do
context '.from_file' do
Expand Down
1 change: 1 addition & 0 deletions spec/unit/pdk/module/template_dir_spec.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
require 'spec_helper'
require 'yaml'
require 'pdk/module/templatedir'

describe PDK::Module::TemplateDir do
subject(:template_dir) do
Expand Down

0 comments on commit 54ba34d

Please sign in to comment.