aws-lambda/python-s3-thumbnail/node_modules/serverless-python-requirements/index.js
/**
   * pip install the requirements to the .requirements directory
   * @return {Promise}
   */
pip install the requirements to the .requirements directory
@return {Promise}
pip install the requirements to the . requirements directory @return { Promise }
installRequirements() {
    if (!fse.existsSync(path.join(this.serverless.config.servicePath,
                                  'requirements.txt'))) {
      return BbPromise.resolve();
    }
    const runtime = this.serverless.service.provider.runtime;
    this.serverless.cli.log(
      `Installing required Python packages for runtime ${runtime}...`);
    return new BbPromise((resolve, reject) => {
      let cmd;
      let options;
      const pipCmd = [
        runtime, '-m', 'pip', '--isolated', 'install',
        '-t', '.requirements', '-r', 'requirements.txt',
      ];
      if (!this.custom().dockerizePip) {
        const pipTestRes = spawnSync(runtime, ['-m', 'pip', 'help', 'install']);
        if (pipTestRes.stdout.toString().indexOf('--system') >= 0)
          pipCmd.push('--system');
      }
      if (this.custom().dockerizePip) {
        cmd = 'docker';
        options = [
          'run', '--rm',
          '-u', process.getuid() + ':' + process.getgid(),
          '-v', `${this.serverless.config.servicePath}:/var/task:z`,
          `lambci/lambda:build-${runtime}`,
        ];
        options.push(...pipCmd);
      } else {
        cmd = pipCmd[0];
        options = pipCmd.slice(1);
      }
      const res = spawnSync(cmd, options);
      if (res.error) {
        return reject(res.error);
      }
      if (res.status != 0) {
        return reject(res.stderr);
      }
      resolve();
    });
  }
installRequirements ( ) { if ( ! fse . existsSync ( path . join ( this . serverless . config . servicePath , 'requirements.txt' ) ) ) { return BbPromise . resolve ( ) ; } const runtime = this . serverless . service . provider . runtime ; this . serverless . cli . log ( ` ${ runtime } ` ) ; return new BbPromise ( ( resolve , reject ) => { let cmd ; let options ; const pipCmd = [ runtime , '-m' , 'pip' , '--isolated' , 'install' , '-t' , '.requirements' , '-r' , 'requirements.txt' , ] ; if ( ! this . custom ( ) . dockerizePip ) { const pipTestRes = spawnSync ( runtime , [ '-m' , 'pip' , 'help' , 'install' ] ) ; if ( pipTestRes . stdout . toString ( ) . indexOf ( '--system' ) >= 0 ) pipCmd . push ( '--system' ) ; } if ( this . custom ( ) . dockerizePip ) { cmd = 'docker' ; options = [ 'run' , '--rm' , '-u' , process . getuid ( ) + ':' + process . getgid ( ) , '-v' , ` ${ this . serverless . config . servicePath } ` , ` ${ runtime } ` , ] ; options . push ( ... pipCmd ) ; } else { cmd = pipCmd [ 0 ] ; options = pipCmd . slice ( 1 ) ; } const res = spawnSync ( cmd , options ) ; if ( res . error ) { return reject ( res . error ) ; } if ( res . status != 0 ) { return reject ( res . stderr ) ; } resolve ( ) ; } ) ; }
pip install the requirements to the .requirements directory
 @return {Promise}
pip install the requirements to the . requirements directory @return { Promise }