<commit_before>require "pathname"
require "tempfile"
require "protobuf_descriptor"

module Apiculture
  class Input
    attr_accessor :manifest

    def initialize(manifest)
      @manifest = manifest
    end

    def proto_files
      return Dir.glob("#{manifest.descriptor_path}/**/*.proto")
    end

    def descriptor
      @descriptor ||= load_descriptor
    end

    # output_type is one of [:java, :python, :cpp, :descriptor]
    def invoke_protoc(output_type, output_path)
      # Load the file that the apiculture extensions are defined in.
      require "apiculture_extensions.pb.rb"

      extension_import_path = File.realpath(File.join(File.dirname(__FILE__), "..", "..", "protos"))

      command = ["protoc", "-I.", "-I#{extension_import_path}"]
      if output_type == :descriptor
        command += ["--include_source_info", "--descriptor_set_out=#{output_path}"]
      else
        command << "--#{output_type}_out=#{output_path}"
      end

      command += proto_files.map { |path|
        Pathname.new(path).relative_path_from(Pathname.new(manifest.descriptor_path)).to_s
      }

      Dir.chdir(manifest.descriptor_path) do
        system(*command)<commit_msg>Reformat+use File.join consistently with file paths<commit_after>require "pathname"
require "tempfile"
require "protobuf_descriptor"

module Apiculture
  class Input
    attr_accessor :manifest

    def initialize(manifest)
      @manifest = manifest
    end

    def proto_files
      return Dir.glob(File.join(
          manifest.descriptor_path, "**", "*.proto"))
    end

    def descriptor
      @descriptor ||= load_descriptor
    end

    # output_type is one of [:java, :python, :cpp, :descriptor]
    def invoke_protoc(output_type, output_path)
      # Load the file that the apiculture extensions are defined in.
      require "apiculture_extensions.pb.rb"

      extension_import_path = File.realpath(File.join(
          File.dirname(__FILE__), "..", "..", "protos"))

      command = ["protoc", "-I.", "-I#{extension_import_path}"]
      if output_type == :descriptor
        command += ["--include_source_info", "--descriptor_set_out=#{output_path}"]
      else
        command << "--#{output_type}_out=#{output_path}"
      end

      command += proto_files.map { |path|
        Pathname.new(path).relative_path_from(Pathname.new(manifest.descriptor_path)).to_s
      }

      Dir.chdir(manifest.descriptor_path) do
        system(*command)
{'fraction_non_alphanumeric': 0.12469237079573421, 'fraction_numerical': 0.0, 'mean_word_length': 3.1907216494845363, 'pattern_counts': {'":': 0, '<': 7, '<?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': '3271744', 'n_tokens_mistral': 745, 'n_tokens_neox': 716, 'n_words': 155}