<commit_before>Bundler.setup(:default, :spec)

$spec_dir = File.dirname(__FILE__)
require File.join(File.expand_path($spec_dir), '../lib/lypack')
require 'fileutils'

$packages_dir = Lypack.packages_dir
$lilyponds_dir = Lypack.lilyponds_dir

module Lypack
  def self.packages_dir
    $packages_dir
  end
  
  def self.lilyponds_dir
    $lilyponds_dir
  end
  
  def self.settings_file
    "/tmp/#{Lypack::SETTINGS_FILENAME}"
  end
  
  module Lilypond
    def self.get_system_lilyponds_paths
      []
    end

    def self.session_settings_filename
      "/tmp/lypack.session.#{Process.pid}.yml"
    end
  end
end

def with_packages(setup)
  begin
    old_packages_dir = $packages_dir
    $packages_dir = File.expand_path("package_setups/#{setup}", $spec_dir)
    
    # remove settings file
    FileUtils.rm_f(Lypack.settings_file)
    FileUtils.rm_f(Lypack::Lilypond.session_settings_filename)
    
    yield
  ensure
    # remove settings file
    FileUtils.rm_f(Lypack.settings_file)<commit_msg>Show error when a cmd fails<commit_after>Bundler.setup(:default, :spec)

$spec_dir = File.dirname(__FILE__)
require File.join(File.expand_path($spec_dir), '../lib/lypack')
require 'fileutils'
require 'open3'

$packages_dir = Lypack.packages_dir
$lilyponds_dir = Lypack.lilyponds_dir

module Lypack
  def self.packages_dir
    $packages_dir
  end
  
  def self.lilyponds_dir
    $lilyponds_dir
  end
  
  def self.settings_file
    "/tmp/#{Lypack::SETTINGS_FILENAME}"
  end
  
  module Lilypond
    def self.get_system_lilyponds_paths
      []
    end

    def self.session_settings_filename
      "/tmp/lypack.session.#{Process.pid}.yml"
    end
    
    def self.exec(cmd)
      Open3.popen3(cmd) do |_in, _out, _err, wait_thr|
        exit_value = wait_thr.value
        if exit_value != 0
          raise "Error executing cmd #{cmd}: #{_err.read}"
        end
      end
    end
  end
end

def with_packages(setup)
  begin
    old_packages_dir = $packages_dir
    $packages_dir = File.expand_path("package_setups/#{setup}", $spec_dir)
    
    # remove settings file
    FileUtils.rm_f(Lypack.settings_file)
    FileUtils.rm_f(Lypack::Lilypond.session_settings_filename)
    
    yield
  ensure
    # remove settings file
    FileUtils.rm_f(Lypack.settings_file)
{'fraction_non_alphanumeric': 0.09854175872735307, 'fraction_numerical': 0.0017675651789659744, 'mean_word_length': 3.379110251450677, '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': '468374', 'n_tokens_mistral': 827, 'n_tokens_neox': 825, 'n_words': 142}