<commit_before>require 'digest/sha1'
require 'fileutils'
require 'rubysh'

class Thrifty::ThriftFile
  include Chalk::Log

  DUMMY_DIRECTORY = File.expand_path('../dummy', __FILE__)

  attr_reader :relative_path, :options

  def initialize(manager, relative_path, options={})
    @manager = manager
    @relative_path = relative_path
    @options = options
  end

  def validate_existence
    raise "No such Thrift file #{path.inspect}" unless File.exists?(path)
  end

  def path
    expand_relative_path(@relative_path)
  end

  def defines?(generated_file)
    compile_once
    File.exists?(File.join(build_directory, generated_file + '.rb'))
  end

  def require(generated_file)
    compile_once

    # This is a bit dicey, as a generated thrift <file> will also
    # include <file>_types and <file>_constants as well as
    # 'thrift'. We need to make sure we can handle file names that may
    # have already been required -- this path munging should
    # successfully do so.

    super('thrift')

    orig_load_path = $:.dup

    begin
      $:[0..-1] = @manager.require_path + [DUMMY_DIRECTORY]
      log.info('Requiring', file: generated_file, idl: path, build_directory: build_directory)
      # Global require
      super(generated_file)
    ensure
      $:[0..-1] = orig_load_path<commit_msg>Get rid of thrift chunder<commit_after>require 'digest/sha1'
require 'fileutils'
require 'rubysh'

class Thrifty::ThriftFile
  include Chalk::Log

  DUMMY_DIRECTORY = File.expand_path('../dummy', __FILE__)

  attr_reader :relative_path, :options

  def initialize(manager, relative_path, options={})
    @manager = manager
    @relative_path = relative_path
    @options = options
  end

  def validate_existence
    raise "No such Thrift file #{path.inspect}" unless File.exists?(path)
  end

  def path
    expand_relative_path(@relative_path)
  end

  def defines?(generated_file)
    compile_once
    File.exists?(File.join(build_directory, generated_file + '.rb'))
  end

  def require(generated_file)
    compile_once

    # This is a bit dicey, as a generated thrift <file> will also
    # include <file>_types and <file>_constants as well as
    # 'thrift'. We need to make sure we can handle file names that may
    # have already been required -- this path munging should
    # successfully do so.

    super('thrift')

    orig_load_path = $:.dup

    begin
      $:[0..-1] = @manager.require_path + [DUMMY_DIRECTORY]
      log.debug('Requiring', file: generated_file, idl: path, build_directory: build_directory)
      # Global require
      super(generated_file)
    ensure
      $:[0..-1] = orig_load_path
{'fraction_non_alphanumeric': 0.0998095238095238, 'fraction_numerical': 0.0038095238095238095, 'mean_word_length': 3.535405872193437, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 9, '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': '5971688', 'n_tokens_mistral': 839, 'n_tokens_neox': 820, 'n_words': 233}