lib/configure.js
function findPython() {
    const SKIP=0, FAIL=1
    const toCheck = [
      {
        before: () => {
          if (!this.configPython) {
            this.addLog(
              'Python is not set from command line or npm configuration')
            return SKIP
          }
          this.addLog('checking Python explicitly set from command line or ' +
            'npm configuration')
          this.addLog('- "--python=" or "npm config get python" is ' +
            `"${this.configPython}"`)
        },
        check: this.checkCommand,
        arg: this.configPython,
      },
      {
        before: () => {
          if (!this.env.PYTHON) {
            this.addLog('Python is not set from environment variable PYTHON')
            return SKIP
          }
          this.addLog(
            'checking Python explicitly set from environment variable PYTHON')
          this.addLog(`- process.env.PYTHON is "${this.env.PYTHON}"`)
        },
        check: this.checkCommand,
        arg: this.env.PYTHON,
      },
      {
        before: () => { this.addLog('checking if "python2" can be used') },
        check: this.checkCommand,
        arg: 'python2',
      },
      {
        before: () => { this.addLog('checking if "python" can be used') },
        check: this.checkCommand,
        arg: 'python',
      },
      {
        before: () => {
          if (!this.win) {
            // Everything after this is Windows specific
            return FAIL
          }
          this.addLog(
            'checking if the py launcher can be used to find Python 2')
        },
        check: this.checkPyLauncher,
      },
      {
        before: () => {
          this.addLog(
            'checking if Python 2 is installed in the default location')
        },
        check: this.checkExecPath,
        arg: this.defaultLocation,
      },
    ]

    function runChecks(err) {
      this.log.silly('runChecks: err = %j', err && err.stack || err)

      const check = toCheck.shift()
      if (!check) {
        return this.fail()
      }

      const before = check.before.apply(this)
      if (before === SKIP) {
        return runChecks.apply(this)
      }
      if (before === FAIL) {
        return this.fail()
      }

      const args = [ runChecks.bind(this) ]
      if (check.arg) {
        args.unshift(check.arg)
      }
      check.check.apply(this, args)
    }

    runChecks.apply(this)
  }
function findPython() {
    const SKIP=0, FAIL=1
    const toCheck = [
      {
        before: () => {
          if (!this.configPython) {
            this.addLog(
              'Python is not set from command line or npm configuration')
            return SKIP
          }
          this.addLog('checking Python explicitly set from command line or ' +
            'npm configuration')
          this.addLog('- "--python=" or "npm config get python" is ' +
            `"${this.configPython}"`)
        },
        check: this.checkCommand,
        arg: this.configPython,
      },
      {
        before: () => {
          if (!this.env.PYTHON) {
            this.addLog('Python is not set from environment variable PYTHON')
            return SKIP
          }
          this.addLog(
            'checking Python explicitly set from environment variable PYTHON')
          this.addLog(`- process.env.PYTHON is "${this.env.PYTHON}"`)
        },
        check: this.checkCommand,
        arg: this.env.PYTHON,
      },
      {
        before: () => { this.addLog('checking if "python2" can be used') },
        check: this.checkCommand,
        arg: 'python2',
      },
      {
        before: () => { this.addLog('checking if "python" can be used') },
        check: this.checkCommand,
        arg: 'python',
      },
      {
        before: () => {
          if (!this.win) {
            // Everything after this is Windows specific
            return FAIL
          }
          this.addLog(
            'checking if the py launcher can be used to find Python 2')
        },
        check: this.checkPyLauncher,
      },
      {
        before: () => {
          this.addLog(
            'checking if Python 2 is installed in the default location')
        },
        check: this.checkExecPath,
        arg: this.defaultLocation,
      },
    ]

    function runChecks(err) {
      this.log.silly('runChecks: err = %j', err && err.stack || err)

      const check = toCheck.shift()
      if (!check) {
        return this.fail()
      }

      const before = check.before.apply(this)
      if (before === SKIP) {
        return runChecks.apply(this)
      }
      if (before === FAIL) {
        return this.fail()
      }

      const args = [ runChecks.bind(this) ]
      if (check.arg) {
        args.unshift(check.arg)
      }
      check.check.apply(this, args)
    }

    runChecks.apply(this)
  }
function findPython ( ) { const SKIP = 0 , FAIL = 1 const toCheck = [ { before : ( ) => { if ( ! this . configPython ) { this . addLog ( 'Python is not set from command line or npm configuration' ) return SKIP } this . addLog ( 'checking Python explicitly set from command line or ' + 'npm configuration' ) this . addLog ( '- "--python=" or "npm config get python" is ' + ` ${ this . configPython } ` ) } , check : this . checkCommand , arg : this . configPython , } , { before : ( ) => { if ( ! this . env . PYTHON ) { this . addLog ( 'Python is not set from environment variable PYTHON' ) return SKIP } this . addLog ( 'checking Python explicitly set from environment variable PYTHON' ) this . addLog ( ` ${ this . env . PYTHON } ` ) } , check : this . checkCommand , arg : this . env . PYTHON , } , { before : ( ) => { this . addLog ( 'checking if "python2" can be used' ) } , check : this . checkCommand , arg : 'python2' , } , { before : ( ) => { this . addLog ( 'checking if "python" can be used' ) } , check : this . checkCommand , arg : 'python' , } , { before : ( ) => { if ( ! this . win ) { // Everything after this is Windows specific return FAIL } this . addLog ( 'checking if the py launcher can be used to find Python 2' ) } , check : this . checkPyLauncher , } , { before : ( ) => { this . addLog ( 'checking if Python 2 is installed in the default location' ) } , check : this . checkExecPath , arg : this . defaultLocation , } , ] function runChecks ( err ) { this . log . silly ( 'runChecks: err = %j' , err && err . stack || err ) const check = toCheck . shift ( ) if ( ! check ) { return this . fail ( ) } const before = check . before . apply ( this ) if ( before === SKIP ) { return runChecks . apply ( this ) } if ( before === FAIL ) { return this . fail ( ) } const args = [ runChecks . bind ( this ) ] if ( check . arg ) { args . unshift ( check . arg ) } check . check . apply ( this , args ) } runChecks . apply ( this ) }
Find Python by trying a sequence of possibilities. Ignore errors, keep trying until Python is found.
Find Python by trying a sequence of possibilities . Ignore errors keep trying until Python is found .