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

Code snippets are loaded twice #644

Closed
ddfreyne opened this Issue Jun 18, 2015 · 0 comments

Comments

Projects
None yet
1 participant
@ddfreyne
Member

ddfreyne commented Jun 18, 2015

First trace:

  /Users/ddfreyne/Documents/Development/nanoc/repos/nanoc/lib/nanoc/base/source_data/code_snippet.rb:35:in `load'
  /Users/ddfreyne/Documents/Development/nanoc/repos/nanoc/lib/nanoc/base/repos/site_loader.rb:45:in `each'
  /Users/ddfreyne/Documents/Development/nanoc/repos/nanoc/lib/nanoc/base/repos/site_loader.rb:45:in `site_from_config'
  /Users/ddfreyne/Documents/Development/nanoc/repos/nanoc/lib/nanoc/base/repos/site_loader.rb:12:in `new_from_cwd'
  /Users/ddfreyne/Documents/Development/nanoc/repos/nanoc/lib/nanoc/cli.rb:120:in `load_custom_commands'
  /Users/ddfreyne/Documents/Development/nanoc/repos/nanoc/lib/nanoc/cli.rb:87:in `setup'
  /Users/ddfreyne/Documents/Development/nanoc/repos/nanoc/lib/nanoc/cli.rb:52:in `block in run'
  /Users/ddfreyne/Documents/Development/nanoc/repos/nanoc/lib/nanoc/cli/error_handler.rb:64:in `handle_while'
  /Users/ddfreyne/Documents/Development/nanoc/repos/nanoc/lib/nanoc/cli/error_handler.rb:22:in `handle_while'
  /Users/ddfreyne/Documents/Development/nanoc/repos/nanoc/lib/nanoc/cli.rb:51:in `run'
  /Users/ddfreyne/Documents/Development/nanoc/repos/nanoc/bin/nanoc:9:in `<top (required)>'
  /usr/local/lib/ruby/gems/2.2.0/bin/nanoc:23:in `load'
  /usr/local/lib/ruby/gems/2.2.0/bin/nanoc:23:in `<main>'

Second trace:

  /Users/ddfreyne/Documents/Development/nanoc/repos/nanoc/lib/nanoc/base/source_data/code_snippet.rb:35:in `load'
  /Users/ddfreyne/Documents/Development/nanoc/repos/nanoc/lib/nanoc/base/repos/site_loader.rb:45:in `each'
  /Users/ddfreyne/Documents/Development/nanoc/repos/nanoc/lib/nanoc/base/repos/site_loader.rb:45:in `site_from_config'
  /Users/ddfreyne/Documents/Development/nanoc/repos/nanoc/lib/nanoc/base/repos/site_loader.rb:12:in `new_from_cwd'
  /Users/ddfreyne/Documents/Development/nanoc/repos/nanoc/lib/nanoc/cli/command_runner.rb:24:in `site'
  /Users/ddfreyne/Documents/Development/nanoc/repos/nanoc/lib/nanoc/cli/command_runner.rb:50:in `require_site'
  /Users/ddfreyne/Documents/Development/nanoc/repos/nanoc/lib/nanoc/cli/command_runner.rb:61:in `load_site'
  /Users/ddfreyne/Documents/Development/nanoc/repos/nanoc/lib/nanoc/cli/commands/compile.rb:372:in `run'
  /Users/ddfreyne/Documents/Development/nanoc/repos/nanoc/lib/nanoc/cli/command_runner.rb:12:in `block in call'
  /Users/ddfreyne/Documents/Development/nanoc/repos/nanoc/lib/nanoc/cli/error_handler.rb:64:in `handle_while'
  /Users/ddfreyne/Documents/Development/nanoc/repos/nanoc/lib/nanoc/cli/error_handler.rb:22:in `handle_while'
  /Users/ddfreyne/Documents/Development/nanoc/repos/nanoc/lib/nanoc/cli/command_runner.rb:11:in `call'
  /usr/local/lib/ruby/gems/2.2.0/gems/cri-2.7.0/lib/cri/command_dsl.rb:233:in `block in runner'
  /usr/local/lib/ruby/gems/2.2.0/gems/cri-2.7.0/lib/cri/command.rb:294:in `call'
  /usr/local/lib/ruby/gems/2.2.0/gems/cri-2.7.0/lib/cri/command.rb:294:in `run_this'
  /usr/local/lib/ruby/gems/2.2.0/gems/cri-2.7.0/lib/cri/command.rb:247:in `run'
  /Users/ddfreyne/Documents/Development/nanoc/repos/nanoc/lib/nanoc/cli/commands/nanoc.rb:37:in `block in define'
  /usr/local/lib/ruby/gems/2.2.0/gems/cri-2.7.0/lib/cri/command.rb:294:in `call'
  /usr/local/lib/ruby/gems/2.2.0/gems/cri-2.7.0/lib/cri/command.rb:294:in `run_this'
  /usr/local/lib/ruby/gems/2.2.0/gems/cri-2.7.0/lib/cri/command.rb:247:in `run'
  /Users/ddfreyne/Documents/Development/nanoc/repos/nanoc/lib/nanoc/cli.rb:53:in `block in run'
  /Users/ddfreyne/Documents/Development/nanoc/repos/nanoc/lib/nanoc/cli/error_handler.rb:64:in `handle_while'
  /Users/ddfreyne/Documents/Development/nanoc/repos/nanoc/lib/nanoc/cli/error_handler.rb:22:in `handle_while'
  /Users/ddfreyne/Documents/Development/nanoc/repos/nanoc/lib/nanoc/cli.rb:51:in `run'
  /Users/ddfreyne/Documents/Development/nanoc/repos/nanoc/bin/nanoc:9:in `<top (required)>'
  /usr/local/lib/ruby/gems/2.2.0/bin/nanoc:23:in `load'
  /usr/local/lib/ruby/gems/2.2.0/bin/nanoc:23:in `<main>'

The second trace is the legit one (the command runner loads the site in order to compile it). The first one happens because the custom command loading:

  def self.load_custom_commands
    if Nanoc::Int::SiteLoader.cwd_is_nanoc_site?
      site = Nanoc::Int::SiteLoader.new.new_from_cwd
      site.config[:commands_dirs].each do |path|
        load_commands_at(path)
      end
    end
  end

This was not an issue before, because sites were loaded lazily.

It probably makes sense to extract the configuration loading into its own system, so that loading custom commands doesn’t mean loading the entire site.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment