<commit_before>
module.exports = exports = configure

/**
 * Module dependencies.
 */

var fs = require('fs')
  , path = require('path')
  , glob = require('glob')
  , which = require('which')
  , semver = require('semver')
  , mkdirp = require('./util/mkdirp')
  , createHook = require('./util/hook')
  , asyncEmit = require('./util/asyncEmit')
  , win = process.platform == 'win32'

exports.usage = 'Generates ' + (win ? 'MSVC project files' : 'a Makefile') + ' for the current module'

function configure (gyp, argv, callback) {

  var python = process.env.PYTHON || gyp.opts.python || 'python'
    , buildDir = path.resolve('build')
    , configPath
    , emitter
    , versionStr
    , version

  // Very first step is to load up the user-defined 'gyp-configure.js' file if it
  // exists. We relay filecycle events using the eventemitter returned from this
  createHook('gyp-configure.js', function (err, _e) {
    if (err) return callback(err)
    emitter = _e
    checkPython()
  })

  // Make sure that Python is in the $PATH
  function checkPython () {
    which(python, function (err, execPath) {
      if (err) {
        if (win) {
          guessPython()
        } else {
          failNoPython()
        }
        return
      }
      gyp.verbose('`which` succeeded for `' + python + '`', execPath)
      getVersion()
    })
  }

  // Called on Windows when "python" isn't available in the current $PATH.
  // We're gonna glob C:\python2*
  function guessPython () {
    gyp.verbose('could not find "' + python + '". guessing location')
    var rootDir = process.env.HOMEDRIVE || process.env.SystemDrive || 'C:\\'
    if (rootDir[rootDir.length - 1] !== '\\') {
      rootDir += '\\'
    }
    var pythonPath = path.resolve(rootDir, 'Python27', 'python.exe')
    gyp.verbose('ensuring that file exists:', pythonPath)
    fs.stat(pythonPath, function (err, stat) {
      if (err) {
        if (err.code == 'ENOENT') {
          failNoPython()
        } else {
          callbackk(err)
        }
        return
      }
      python = pythonPath
      getVersion()
    })
  }

  function failNoPython () {
    callback(new Error('Can\'t find Python, you can set the PYTHON env variable.'))
  }

  function getVersion () {
    if (gyp.opts.target) {
      // if --target was given, then ensure that version is installed
      versionStr = gyp.opts.target
      gyp.verbose('compiling against --target node version', versionStr)
    } else {
      // if no --target was specified then use the current host node version
      versionStr = process.version
      gyp.verbose('no --target version specified, falling back to host node version', versionStr)
    }
    version = semver.parse(versionStr)
    if (!version) {
      return callback(new Error('Invalid version number: ' + versionStr))
    }<commit_msg>configure: getVersion() -> getTargetVersion()<commit_after>
module.exports = exports = configure

/**
 * Module dependencies.
 */

var fs = require('fs')
  , path = require('path')
  , glob = require('glob')
  , which = require('which')
  , semver = require('semver')
  , mkdirp = require('./util/mkdirp')
  , createHook = require('./util/hook')
  , asyncEmit = require('./util/asyncEmit')
  , win = process.platform == 'win32'

exports.usage = 'Generates ' + (win ? 'MSVC project files' : 'a Makefile') + ' for the current module'

function configure (gyp, argv, callback) {

  var python = process.env.PYTHON || gyp.opts.python || 'python'
    , buildDir = path.resolve('build')
    , configPath
    , emitter
    , versionStr
    , version

  // Very first step is to load up the user-defined 'gyp-configure.js' file if it
  // exists. We relay filecycle events using the eventemitter returned from this
  createHook('gyp-configure.js', function (err, _e) {
    if (err) return callback(err)
    emitter = _e
    checkPython()
  })

  // Make sure that Python is in the $PATH
  function checkPython () {
    which(python, function (err, execPath) {
      if (err) {
        if (win) {
          guessPython()
        } else {
          failNoPython()
        }
        return
      }
      gyp.verbose('`which` succeeded for `' + python + '`', execPath)
      getTargetVersion()
    })
  }

  // Called on Windows when "python" isn't available in the current $PATH.
  // We're gonna glob C:\python2*
  function guessPython () {
    gyp.verbose('could not find "' + python + '". guessing location')
    var rootDir = process.env.HOMEDRIVE || process.env.SystemDrive || 'C:\\'
    if (rootDir[rootDir.length - 1] !== '\\') {
      rootDir += '\\'
    }
    var pythonPath = path.resolve(rootDir, 'Python27', 'python.exe')
    gyp.verbose('ensuring that file exists:', pythonPath)
    fs.stat(pythonPath, function (err, stat) {
      if (err) {
        if (err.code == 'ENOENT') {
          failNoPython()
        } else {
          callbackk(err)
        }
        return
      }
      python = pythonPath
      getTargetVersion()
    })
  }

  function failNoPython () {
    callback(new Error('Can\'t find Python, you can set the PYTHON env variable.'))
  }

  function getTargetVersion () {
    if (gyp.opts.target) {
      // if --target was given, then ensure that version is installed
      versionStr = gyp.opts.target
      gyp.verbose('compiling against --target node version', versionStr)
    } else {
      // if no --target was specified then use the current host node version
      versionStr = process.version
      gyp.verbose('no --target version specified, falling back to host node version', versionStr)
    }
    version = semver.parse(versionStr)
    if (!version) {
      return callback(new Error('Invalid version number: ' + versionStr))
    }
{'fraction_non_alphanumeric': 0.13458831808585503, 'fraction_numerical': 0.00211118930330753, 'mean_word_length': 2.577721837633732, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 4, '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': '6564451', 'n_tokens_mistral': 1751, 'n_tokens_neox': 1705, 'n_words': 496}