<commit_before>require 'kosmos/package_dsl'
require 'kosmos/package'
require 'kosmos/versioner'
require 'kosmos/git_adapter'
require 'kosmos/download_url'
require 'kosmos/util'
require 'kosmos/version'

require 'json'

module Kosmos
  class << self
    def config
      @config ||= Configuration.new
    end

    def configure
      yield(config)
    end

    def save_ksp_path(path)
      write_config(ksp_path: path)
    end

    def load_ksp_path
      read_config[:ksp_path]
    end

    def cache_dir
      read_config[:cache_dir]
    end

    private

    def write_config(opts)
      File.open(config_path, "w+") do |file|
        file.write JSON.pretty_generate(read_config.merge(opts))
      end
    end

    def read_config
      config = File.read(config_path)
      if config.empty?
        {}
      else
        JSON.parse(config, symbolize_names: true)
      end
    end

    def config_path
      File.join(Dir.home, ".kosmos")
    end
  end

  class Configuration
    attr_accessor :verbose, :post_processors

    def initialize
      @verbose = false
      @post_processors = [Kosmos::PostProcessors::ModuleManagerResolver]<commit_msg>Open config file with mode r+.<commit_after>require 'kosmos/package_dsl'
require 'kosmos/package'
require 'kosmos/versioner'
require 'kosmos/git_adapter'
require 'kosmos/download_url'
require 'kosmos/util'
require 'kosmos/version'

require 'json'

module Kosmos
  class << self
    def config
      @config ||= Configuration.new
    end

    def configure
      yield(config)
    end

    def save_ksp_path(path)
      write_config(ksp_path: path)
    end

    def load_ksp_path
      read_config[:ksp_path]
    end

    def cache_dir
      read_config[:cache_dir]
    end

    private

    def write_config(opts)
      File.open(config_path, "r+") do |file|
        file.write JSON.pretty_generate(read_config.merge(opts))
      end
    end

    def read_config
      config = File.read(config_path)
      if config.empty?
        {}
      else
        JSON.parse(config, symbolize_names: true)
      end
    end

    def config_path
      File.join(Dir.home, ".kosmos")
    end
  end

  class Configuration
    attr_accessor :verbose, :post_processors

    def initialize
      @verbose = false
      @post_processors = [Kosmos::PostProcessors::ModuleManagerResolver]
{'fraction_non_alphanumeric': 0.08530805687203792, 'fraction_numerical': 0.0, 'mean_word_length': 2.739130434782609, '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': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2826499', 'n_tokens_mistral': 780, 'n_tokens_neox': 757, 'n_words': 168}