<commit_before>var spawn = require('child_process').spawn;
var _ = require('underscore');
var when = require('when');

var SDK_PATH = __dirname + '/addon-sdk';
var CFX_PATH = SDK_PATH + '/bin/cfx';
var ENV = {
  PYTHONPATH: SDK_PATH + '/python-lib/',
  CUDDLEFISH_ROOT: SDK_PATH,
  PATH: process.env.PATH
};

var DEFAULTS = {
  pkgdir: SDK_PATH
};

process.chdir(ENV.CUDDLEFISH_ROOT);

var ARG_MAP = {
  // cfx run 
  'binary': '--binary',
  'extras': '--extra-packages',
  'config': '--use-config',
  'profile': '--profiledir',
  'pkgdir': '--pkgdir',
  'static': '--static-args',
  'app': '--app',
  // cfx test
  'filter': '--filter',
  'repeat': '--times',
  // cfx xpi
  'updateUrl': '--update-url',
  'updateLink': '--update-link'
}

exports.docs = execute.bind(null, 'docs');
exports.init = execute.bind(null, 'init');
exports.run = execute.bind(null, 'run');
exports.testall = execute.bind(null, 'testall');
exports.test = execute.bind(null, 'test');

function execute (command, options) {
  options = options || {};
  var dir = options.dir || __dirname;
  var env = _.extend({}, ENV, options.env || {});
  var args = optionsToArgs(options);
  return spawn('python', [CFX_PATH].concat(command).concat(args), {
    cwd: dir,
    env: env
  });
}

function optionsToArgs (options) {
  return _.reduce(_.extend({}, DEFAULTS, options), function (mem, val, key) {
    if (key !== 'dir' && key !== 'env')
      mem.push(ARG_MAP[key] + '=' + val);
    return mem;
  }, []);
}
<commit_msg>removed unused dep 'when'<commit_after>var spawn = require('child_process').spawn;
var _ = require('underscore');

var SDK_PATH = __dirname + '/addon-sdk';
var CFX_PATH = SDK_PATH + '/bin/cfx';
var ENV = {
  PYTHONPATH: SDK_PATH + '/python-lib/',
  CUDDLEFISH_ROOT: SDK_PATH,
  PATH: process.env.PATH
};

var DEFAULTS = {
  pkgdir: SDK_PATH
};

process.chdir(ENV.CUDDLEFISH_ROOT);

var ARG_MAP = {
  // cfx run 
  'binary': '--binary',
  'extras': '--extra-packages',
  'config': '--use-config',
  'profile': '--profiledir',
  'pkgdir': '--pkgdir',
  'static': '--static-args',
  'app': '--app',
  // cfx test
  'filter': '--filter',
  'repeat': '--times',
  // cfx xpi
  'updateUrl': '--update-url',
  'updateLink': '--update-link'
}

exports.docs = execute.bind(null, 'docs');
exports.init = execute.bind(null, 'init');
exports.run = execute.bind(null, 'run');
exports.testall = execute.bind(null, 'testall');
exports.test = execute.bind(null, 'test');

function execute (command, options) {
  options = options || {};
  var dir = options.dir || __dirname;
  var env = _.extend({}, ENV, options.env || {});
  var args = optionsToArgs(options);
  return spawn('python', [CFX_PATH].concat(command).concat(args), {
    cwd: dir,
    env: env
  });
}

function optionsToArgs (options) {
  return _.reduce(_.extend({}, DEFAULTS, options), function (mem, val, key) {
    if (key !== 'dir' && key !== 'env')
      mem.push(ARG_MAP[key] + '=' + val);
    return mem;
  }, []);
}

{'fraction_non_alphanumeric': 0.21066846725185687, 'fraction_numerical': 0.0, 'mean_word_length': 3.7031746031746033, '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': '3149464', 'n_tokens_mistral': 1118, 'n_tokens_neox': 1104, 'n_words': 240}