<commit_before>module PkgForge
  ##
  # Helper functions for building packages
  module Helpers
    include Contracts::Core
    include Contracts::Builtin

    Contract String => String
    def dep(package)
      tmpdir(package.to_sym)
    end

    Contract Or[String, Array], Or[Hash[String => String], {}, nil] => nil
    def run(cmd, env = {})
      Dir.chdir(tmpdir(:build)) do
        run_local(cmd, env)
      end
      nil
    end

    private

    Contract Symbol => String
    def tmpdir(id)
      @tmpdirs ||= {}
      @tmpdirs[id] ||= Dir.mktmpdir(id.to_s)
    end

    Contract Symbol => String
    def tmpfile(id)
      @tmpfiles ||= {}
      @tmpfiles[id] ||= Tempfile.create(id.to_s).path
    end

    Contract Or[String, Array], Or[Hash[String => String], {}, nil] => nil
    def run_local(cmd, env = {})
      puts "Running command in #{Dir.pwd}: #{cmd}"
      puts "Using env: #{env}" unless env.empty?
      res = system env, cmd
      raise('Command failed!') unless res
      nil
    end<commit_msg>fix command expansion<commit_after>module PkgForge
  ##
  # Helper functions for building packages
  module Helpers
    include Contracts::Core
    include Contracts::Builtin

    Contract String => String
    def dep(package)
      tmpdir(package.to_sym)
    end

    Contract Or[String, Array], Or[Hash[String => String], {}, nil] => nil
    def run(cmd, env = {})
      Dir.chdir(tmpdir(:build)) do
        run_local(cmd, env)
      end
      nil
    end

    private

    Contract Symbol => String
    def tmpdir(id)
      @tmpdirs ||= {}
      @tmpdirs[id] ||= Dir.mktmpdir(id.to_s)
    end

    Contract Symbol => String
    def tmpfile(id)
      @tmpfiles ||= {}
      @tmpfiles[id] ||= Tempfile.create(id.to_s).path
    end

    Contract Or[String, Array], Or[Hash[String => String], {}, nil] => nil
    def run_local(cmd, env = {})
      puts "Running command in #{Dir.pwd}: #{cmd}"
      puts "Using env: #{env}" unless env.empty?
      res = system env, *cmd
      raise('Command failed!') unless res
      nil
    end
{'fraction_non_alphanumeric': 0.13323572474377746, 'fraction_numerical': 0.0, 'mean_word_length': 2.540587219343696, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 17, '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': '625936', 'n_tokens_mistral': 666, 'n_tokens_neox': 661, 'n_words': 177}