<commit_before>module PoolParty
  module Pool
    
    def pool(name, &block)
      pools[name] ||= Pool.new(name, &block)
    end
    
    def pools
      $pools ||= {}
    end
    
    def with_pool(pl, opts={}, &block)
      raise CloudNotFoundException.new("Pool not found") unless pl
      pl.dsl_options.merge!(opts) if pl.dsl_options
      pl.run_in_context &block if block
    end
    
    def set_pool_specfile(filename)
      $pool_specfile = filename unless $pool_specfile
    end
    
    def pool_specfile
      $pool_specfile
    end
    
    def reset!
      $pools = $clouds = $plugins = @describe_instances = nil
    end

    class Pool < PoolParty::PoolPartyBaseClass
      include PrettyPrinter
      include CloudResourcer
      include Remote
      
      def initialize(name,&block)
        @pool_name = name
        @pool_name.freeze
        
        ::PoolParty.context_stack.clear
        
        set_pool_specfile get_latest_caller
        setup_defaults

        super(&block)
      end
      
      
      def self.load_from_file(filename=nil)
        # a = new ::File.basename(filename, ::File.extname(filename))
        #TODO: load any user defined monitors plugins verifiers before the cloud spec is evaled
        #%w(monitors plugins verifiers).each do |lib|
        #  Dir[File.join(::File.dirname(::File.basename(filename)), lib, '*')].each{|f| require f }
        # end
        call_before_all_loaded(pool_specfile || filename)
        o = File.open(filename, 'r') do |f|
          instance_eval f.read, (pool_specfile || filename)
        end
        o.call_after_all_loaded if o.respond_to?(:call_after_all_loaded)
        o
      end
      
      # callbacks
      def self.call_before_all_loaded(filepath)
        # Load the plugins
        $:.unshift(::File.dirname(filepath))
        Dir["#{::File.dirname(filepath)}/plugins/*"].each do |plugin|
          $:.unshift(plugin)
        end
      end
      
      def after_all_loaded(&block)
        @after_all_loaded ||= block
      end
      
      def call_after_all_loaded
        after_all_loaded.call if after_all_loaded
      end
      
      def name(*args)
        @pool_name ||= @pool_name ? @pool_name : (args.empty? ? :default_pool : args.first)
      end

      def parent;nil;end
      
      def setup_defaults
      end
      
      def pool_clouds
        returning Array.new do |arr|
          clouds.each do |name, cl|
            arr << cl if cl.parent.name == self.name
          end<commit_msg>unshifted plugin paths<commit_after>module PoolParty
  module Pool
    
    def pool(name, &block)
      pools[name] ||= Pool.new(name, &block)
    end
    
    def pools
      $pools ||= {}
    end
    
    def with_pool(pl, opts={}, &block)
      raise CloudNotFoundException.new("Pool not found") unless pl
      pl.dsl_options.merge!(opts) if pl.dsl_options
      pl.run_in_context &block if block
    end
    
    def set_pool_specfile(filename)
      $pool_specfile = filename unless $pool_specfile
    end
    
    def pool_specfile
      $pool_specfile
    end
    
    def reset!
      $pools = $clouds = $plugins = @describe_instances = nil
    end

    class Pool < PoolParty::PoolPartyBaseClass
      include PrettyPrinter
      include CloudResourcer
      include Remote
      
      def initialize(name,&block)
        @pool_name = name
        @pool_name.freeze
        
        ::PoolParty.context_stack.clear
        
        set_pool_specfile get_latest_caller
        setup_defaults

        super(&block)
      end
      
      
      def self.load_from_file(filename=nil)
        # a = new ::File.basename(filename, ::File.extname(filename))
        #TODO: load any user defined monitors plugins verifiers before the cloud spec is evaled
        #%w(monitors plugins verifiers).each do |lib|
        #  Dir[File.join(::File.dirname(::File.basename(filename)), lib, '*')].each{|f| require f }
        # end
        call_before_all_loaded(pool_specfile || filename)
        o = File.open(filename, 'r') do |f|
          instance_eval f.read, (pool_specfile || filename)
        end
        o.call_after_all_loaded if o.respond_to?(:call_after_all_loaded)
        o
      end
      
      # callbacks
      def self.call_before_all_loaded(filepath)
        # Load the plugins
        $:.unshift(::File.dirname(filepath))
        Dir["#{::File.dirname(filepath)}/plugins/*"].each do |plugin_path|
          $:.unshift(plugin_path)
        end
      end
      
      def after_all_loaded(&block)
        @after_all_loaded ||= block
      end
      
      def call_after_all_loaded
        after_all_loaded.call if after_all_loaded
      end
      
      def name(*args)
        @pool_name ||= @pool_name ? @pool_name : (args.empty? ? :default_pool : args.first)
      end

      def parent;nil;end
      
      def setup_defaults
      end
      
      def pool_clouds
        returning Array.new do |arr|
          clouds.each do |name, cl|
            arr << cl if cl.parent.name == self.name
          end
{'fraction_non_alphanumeric': 0.09381832637646591, 'fraction_numerical': 0.0, 'mean_word_length': 2.0664229128580134, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5193307', 'n_tokens_mistral': 1575, 'n_tokens_neox': 1552, 'n_words': 349}