<commit_before>"use strict";

module.exports = exports;

var fs = require('fs');
var path = require('path');
var win = process.platform == 'win32';
var existsSync = fs.existsSync || path.existsSync;
var cp = require('child_process');

// try to build up the complete path to node-gyp
/* priority:
  - node-gyp on NODE_PATH
  - node-gyp inside npm on NODE_PATH
  - node-gyp inside npm beside node exe
*/
function which_node_gyp() {
    try {
        var node_gyp_main = require.resolve('node-gyp');
        var node_gyp_bin = path.join(path.dirname(
                                     path.dirname(node_gyp_main)),
                                     'bin/node-gyp.js');
        if (existsSync(node_gyp_bin)) {
            return node_gyp_bin;
        }
    } catch (err) { }
    try {
        var npm_main = require.resolve('npm');
        var node_gyp_bin2 = path.join(path.dirname(
                                     path.dirname(npm_main)),
                                     'node_modules/node-gyp/bin/node-gyp.js');
        if (existsSync(node_gyp_bin2)) {
            return node_gyp_bin2;
        }
    } catch (err) { }
    var npm_base = path.join(path.dirname(
                             path.dirname(process.execPath)),
                             'lib/node_modules/npm/');
    var node_gyp_bin3 = path.join(npm_base,'node_modules/node-gyp/bin/node-gyp.js');
    if (existsSync(node_gyp_bin3)) {
        return node_gyp_bin3;
    }
}

module.exports.run_gyp = function(args,opts,callback) {
    var shell_cmd = '';
    var cmd_args = [];
    if (opts.runtime && opts.runtime == 'node-webkit') {
        shell_cmd = 'nw-gyp';
        if (win) shell_cmd += '.cmd';
    } else {
        var node_gyp_path = which_node_gyp();
        if (node_gyp_path) {
            shell_cmd = process.execPath;
            cmd_args.push(node_gyp_path);
        } else {
            shell_cmd = 'node-gyp';
            if (win) shell_cmd += '.cmd';
        }
    }
    var final_args = cmd_args.concat(args);
    var cmd = cp.spawn(shell_cmd, final_args, {cwd: undefined, env: process.env, stdio: [ 0, 1, 2]});<commit_msg>ignore search 'node-gyp inside npm on NODE_PATH' on iojs<commit_after>"use strict";

module.exports = exports;

var fs = require('fs');
var path = require('path');
var win = process.platform == 'win32';
var existsSync = fs.existsSync || path.existsSync;
var cp = require('child_process');

// try to build up the complete path to node-gyp
/* priority:
  - node-gyp on NODE_PATH
  - node-gyp inside npm on NODE_PATH (ignore on iojs)
  - node-gyp inside npm beside node exe
*/
function which_node_gyp() {
    try {
        var node_gyp_main = require.resolve('node-gyp');
        var node_gyp_bin = path.join(path.dirname(
                                     path.dirname(node_gyp_main)),
                                     'bin/node-gyp.js');
        if (existsSync(node_gyp_bin)) {
            return node_gyp_bin;
        }
    } catch (err) { }
    if (process.execPath.indexOf('iojs') === -1) {
        try {
            var npm_main = require.resolve('npm');
            var node_gyp_bin2 = path.join(path.dirname(
                                         path.dirname(npm_main)),
                                         'node_modules/node-gyp/bin/node-gyp.js');
            if (existsSync(node_gyp_bin2)) {
                return node_gyp_bin2;
            }
        } catch (err) { }
    }
    var npm_base = path.join(path.dirname(
                             path.dirname(process.execPath)),
                             'lib/node_modules/npm/');
    var node_gyp_bin3 = path.join(npm_base,'node_modules/node-gyp/bin/node-gyp.js');
    if (existsSync(node_gyp_bin3)) {
        return node_gyp_bin3;
    }
}

module.exports.run_gyp = function(args,opts,callback) {
    var shell_cmd = '';
    var cmd_args = [];
    if (opts.runtime && opts.runtime == 'node-webkit') {
        shell_cmd = 'nw-gyp';
        if (win) shell_cmd += '.cmd';
    } else {
        var node_gyp_path = which_node_gyp();
        if (node_gyp_path) {
            shell_cmd = process.execPath;
            cmd_args.push(node_gyp_path);
        } else {
            shell_cmd = 'node-gyp';
            if (win) shell_cmd += '.cmd';
        }
    }
    var final_args = cmd_args.concat(args);
    var cmd = cp.spawn(shell_cmd, final_args, {cwd: undefined, env: process.env, stdio: [ 0, 1, 2]});
{'fraction_non_alphanumeric': 0.12837991365598728, 'fraction_numerical': 0.005226084980686207, 'mean_word_length': 1.903693931398417, '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': 10, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6231444', 'n_tokens_mistral': 1470, 'n_tokens_neox': 1433, 'n_words': 285}