<commit_before>require 'find'
require 'digest'
require 'uri'
require 'thread/pool'

Thread.abort_on_exception = true
Thread::Pool.abort_on_exception = true

module Percy
  class Cli
    module Snapshot
      # Static resource types that an HTML file might load and that we want to upload for rendering.
      STATIC_RESOURCE_EXTENSIONS = [
        '.css', '.jpg', '.jpeg', '.gif', '.ico', '.png', '.bmp', '.pict', '.tif', '.tiff', '.ttf',
        '.eot', '.woff', '.otf', '.svg', '.svgz', '.webp', '.ps',
      ].freeze

      DEFAULT_SNAPSHOTS_REGEX = /\.(html|htm)$/

      def run_snapshot(root_dir, options = {})
        repo = options[:repo] || Percy.config.repo
        strip_prefix = File.absolute_path(options[:strip_prefix] || root_dir)
        num_threads = options[:threads] || 10
        snapshot_limit = options[:snapshot_limit]
        baseurl = options[:baseurl] || '/'
        enable_javascript = !!options[:enable_javascript]
        widths = options[:widths].map { |w| Integer(w) }
        raise ArgumentError.new('baseurl must start with /') if baseurl[0] != '/'

        base_resource_options = {strip_prefix: strip_prefix, baseurl: baseurl}

        # Find all the static files in the given root directory.
        root_paths = find_root_paths(root_dir, snapshots_regex: options[:snapshots_regex])
        resource_paths = find_resource_paths(root_dir)
        root_resources = build_resources(root_paths, base_resource_options.merge(is_root: true))
        related_resources = build_resources(resource_paths, base_resource_options)
        all_resources = root_resources + related_resources

        if root_resources.empty?
          say "No root resource files found. Are there HTML files in the given directory?"
          exit(-1)
        end

        build = rescue_connection_failures do
          say 'Creating build...'
          build = Percy.create_build(repo, resources: related_resources)

          say 'Uploading build resources...'
          upload_missing_resources(build, build, all_resources, {num_threads: num_threads})

          build
        end
        return if failed?
<commit_msg>Add debug logging for build resources.<commit_after>require 'find'
require 'digest'
require 'uri'
require 'thread/pool'

Thread.abort_on_exception = true
Thread::Pool.abort_on_exception = true

module Percy
  class Cli
    module Snapshot
      # Static resource types that an HTML file might load and that we want to upload for rendering.
      STATIC_RESOURCE_EXTENSIONS = [
        '.css', '.jpg', '.jpeg', '.gif', '.ico', '.png', '.bmp', '.pict', '.tif', '.tiff', '.ttf',
        '.eot', '.woff', '.otf', '.svg', '.svgz', '.webp', '.ps',
      ].freeze

      DEFAULT_SNAPSHOTS_REGEX = /\.(html|htm)$/

      def run_snapshot(root_dir, options = {})
        repo = options[:repo] || Percy.config.repo
        strip_prefix = File.absolute_path(options[:strip_prefix] || root_dir)
        num_threads = options[:threads] || 10
        snapshot_limit = options[:snapshot_limit]
        baseurl = options[:baseurl] || '/'
        enable_javascript = !!options[:enable_javascript]
        widths = options[:widths].map { |w| Integer(w) }
        raise ArgumentError.new('baseurl must start with /') if baseurl[0] != '/'

        base_resource_options = {strip_prefix: strip_prefix, baseurl: baseurl}

        # Find all the static files in the given root directory.
        root_paths = find_root_paths(root_dir, snapshots_regex: options[:snapshots_regex])
        resource_paths = find_resource_paths(root_dir)
        root_resources = build_resources(root_paths, base_resource_options.merge(is_root: true))
        related_resources = build_resources(resource_paths, base_resource_options)
        all_resources = root_resources + related_resources

        if root_resources.empty?
          say "No root resource files found. Are there HTML files in the given directory?"
          exit(-1)
        end

        related_resources.each do |resource|
          Percy.logger.debug { "Found build resource: #{resource.resource_url}" }
        end

        build = rescue_connection_failures do
          say 'Creating build...'
          build = Percy.create_build(repo, resources: related_resources)

          say 'Uploading build resources...'
          upload_missing_resources(build, build, all_resources, {num_threads: num_threads})

          build
        end
        return if failed?

{'fraction_non_alphanumeric': 0.1142275503279801, 'fraction_numerical': 0.0018095453517303778, 'mean_word_length': 2.965919282511211, 'pattern_counts': {'":': 0, '<': 3, '<?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': '325595', 'n_tokens_mistral': 1283, 'n_tokens_neox': 1255, 'n_words': 332}