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EAEA,WAAW,UAAU,yBAA2B,SAAkC,GAChF,OAAO,GAAG,WAAW,KAAK,KACxB,KAAK,2BAA2B,GAChC,iBAEJ,EAEA,WAAW,UAAU,+BAAiC,SAAwC,GAC5F,OAAO,KAAK,SAAS,oBAAsB,CAC7C,EAEA,OAAO,QAAU,SAAoB,EAAa,GAChD,OAAO,IAAI,WAAW,EAAa,EACrC","file":"/npm/virtualenv@0.3.1/lib/virtualenv.js","sourceRoot":"","sourcesContent":["/**\n * Minified by jsDelivr using Terser v5.39.0.\n * Original file: /npm/virtualenv@0.3.1/lib/virtualenv.js\n *\n * Do NOT use SRI with dynamically generated files! More information: https://www.jsdelivr.com/using-sri-with-dynamic-files\n */\n","var fs = require(\"fs\");\nvar path = require(\"path\");\nvar childProcess = require(\"child_process\");\nvar crypto = require(\"crypto\");\nvar tar = require(\"tar\");\nvar zlib = require(\"zlib\");\nvar glob = require(\"glob\");\nvar rimraf = require(\"rimraf\");\nvar request = require(\"request\");\nvar semver = require(\"semver\");\nvar pypi = require(\"./pypi\");\n\nvar VERSION = require(\"../package.json\").version;\n\nfunction VirtualEnv(packagePath) {\n\n  // Details come directly from the given package.json\n  // TODO: autodetect packagePath (when null) based on previous stack frame\n  var package = require(packagePath);\n  package.virtualenv = package.virtualenv || {};\n  this._version = package.virtualenv.version || \"*\";\n  this._createFlags = package.virtualenv.flags || [];\n  this._python = package.virtualenv.python || \"python\";\n\n  // Read requirements from requirements.txt if it exists.\n  this._requirements = path.join(path.dirname(packagePath), \"requirements.txt\");\n  if (!fs.existsSync(this._requirements)) {\n    throw new Error(\"missing requirements.txt in \" + path.dirname(packagePath));\n  }\n\n  // Figure out our paths.\n  this._virtualenvHome = path.join(path.dirname(packagePath), \".node-virtualenv\");\n  this._virtualenvMetaHome = path.join(this._virtualenvHome, \".node-virtualenv.json\");\n  this._virtualenvSourcesHome = path.join(this._virtualenvHome, \".node-virtualenv-sources\");\n\n  // Hash the current virtualenv state to determine if a reinstall is actually\n  // Reinstallation should happen only when one of the following changes:\n  // 1. Version changes in node-virtualenv (VERSION)\n  // 2. Virtualenv config changes (package.virtualenv)\n  // 3. Postinstall script changes (package.scripts.postinstall)\n  // 4. Dependencies change (requirements.txt)\n  // Therefore the hash contains all three of these factors.\n  // TODO: intelligently pip install -U when only the pip dependencies changed\n  var md5 = crypto.createHash(\"md5\");\n  md5.update([\n    VERSION,\n    JSON.stringify(package.virtualenv),\n    JSON.stringify(package.scripts ? package.scripts.postinstall : \"\"),\n    fs.readFileSync(this._requirements)\n    ].join(\"\"));\n  this._expectedHash = md5.digest(\"hex\");\n\n  // Allow installation progress to be logged on alternative\n  // streams, but default to to stdout and stderr.\n  this._stdout = process.stdout;\n  this._stderr = process.stderr;\n\n}\n\nVirtualEnv.prototype.install = function install(callback) {\n\n  // Helper for starting the installation from the pip step.\n  function continueFromPip(version) {\n    this._pip(function(err) {\n      if (err) return callback(err);\n\n      // Write the current hash from the package since this installation\n      // was successful.\n      this._setMeta(\"currentHash\", this._expectedHash);\n      this._setMeta(\"currentVersion\", version);\n      callback();\n\n    }.bind(this));\n  }\n\n  continueFromPip = continueFromPip.bind(this);\n\n  // Skip install if it isn't necessary.\n  if (this._virtualenvIsUnchanged()) {\n    return continueFromPip(this._getMeta(\"currentVersion\"))\n  }\n\n  // Find the correct download URL on pypi.\n  this._find(function(err, version, url) {\n    if (err) return callback(err);\n\n    // Create helpers that allow us to pick up the installation process\n    // at any stage.\n    function continueFromCreate() {\n      this._create(version, function(err) {\n        if (err) return callback(err);\n        continueFromPip(version);\n      }.bind(this));\n    }\n\n    continueFromCreate = continueFromCreate.bind(this);\n\n    // Skip download and virtualenv creation if all we need are pip updates.\n    if (this._virtualenvOnlyNeedsPipUpdates(version)) {\n      continueFromPip(version);\n\n    // Skip download if we already have the correct virtualenv source.\n    } else if (this._virtualenvSourceIsReady(version)) {\n      continueFromCreate();\n\n    // Otherwise do the download first.\n    } else {\n      this._download(url, function(err) {\n        if (err) return callback(err);\n        continueFromCreate();\n      }.bind(this));\n    }\n\n  }.bind(this));\n\n}\n\nVirtualEnv.prototype.spawn = function spawn(command, args, options) {\n  var pathToVirtualenvCommand = path.join(this._virtualenvHome, \"bin\", command);\n  return childProcess.spawn(pathToVirtualenvCommand, args, options);\n}\n\nVirtualEnv.prototype.spawnPython = function spawnPython(args, options) {\n  var pathToPython = path.join(this._virtualenvHome, \"bin\", \"python\");\n  return childProcess.spawn(pathToPython, args, options);\n}\n\nVirtualEnv.prototype.spawn32bitOSXPython = function spawn32bitOSXPython(args, options) {\n  var pathToPython = path.join(this._virtualenvHome, \"bin\", \"python\");\n  return childProcess.spawn(\"arch\", [\"-i386\"].concat([pathToPython]).concat(args), options);\n}\n\nVirtualEnv.prototype._reportProgress = function _reportProgress(action, target) {\n  this._stdout.write(action + \" \" + target + \"\\n\");\n}\n\nVirtualEnv.prototype._find = function _find(callback) {\n\n  // Find the available versions of virtualenv.\n  var targetVersion = this._version;\n  var client = new pypi.Client();\n  this._reportProgress(\"Finding\", \"virtualenv \" + targetVersion);\n\n  client.getPackageReleases(\"virtualenv\", function(versions) {\n    if (!versions || !versions.length) return callback(new Error(\"virtualenv not found on pypi\"));\n\n    // Find the latest valid version.\n    var latestValidVersion;\n    versions.sort(function(a, b) {\n      return semver.lt(a, b);\n    }).some(function(version) {\n      if (semver.satisfies(version, targetVersion)) {\n        latestValidVersion = version;\n        return true;\n      }\n    });\n    if (!latestValidVersion) return callback(new Error(\"virtualenv \" + targetVersion + \" not found\"));\n\n    // Figure out the tarball URL for this version.\n    client.getReleaseUrls(\"virtualenv\", latestValidVersion, function(urls) {\n      if (!urls || !urls.length) return callback(new Error(\"unable to find URL for virtualenv \" + latestValidVersion));\n      var tarballUrl;\n      urls.some(function(url) {\n        if (/\\.tar\\.gz$/.test(url.url)) {\n          tarballUrl = url.url;\n          return true;\n        }\n      });\n      if (!tarballUrl) return callback(new Error(\"unable to find a tarball for virtualenv \" + latestValidVersion));\n      callback(null, latestValidVersion, tarballUrl);\n\n    // Propagate pypi error callback.\n    }, function(err) {\n      callback(new Error(\"unable to retrieve release URLs for virtualenv \" + latestValidVersion));\n    });\n\n  // Propagate pypi error callback.\n  }, function(err) {\n    callback(new Error(\"unable to retrieve version information for virtualenv\"));\n  });\n\n}\n\nVirtualEnv.prototype._download = function _download(url, callback) {\n\n  // Remove the previous copy of our virtualenv download if there was one.\n  try {\n    rimraf.sync(this._virtualenvSourcesHome);\n  } catch(err) {\n    return callback(err);\n  }\n\n  // Stream the download through unzipping to the final destination.\n  var downloadStream = request(url);\n  var gunzipStream = zlib.createGunzip();\n  var untarStream = tar.Extract({path: this._virtualenvSourcesHome});\n  var finalStream = downloadStream.pipe(gunzipStream).pipe(untarStream);\n\n  // Call the callback with either error or success when this is finished.\n  finalStream.on(\"error\", function(err) {\n    if (callback) callback(err);\n    callback = null;\n  });\n  finalStream.on(\"end\", function() {\n    if (callback) callback();\n    callback = null;\n  });\n\n  // Emit helpful events to track progress.\n  this._reportProgress(\"Downloading\", url);\n  downloadStream.on(\"end\", function() {\n    this._reportProgress(\"Unzipping\", url);\n  }.bind(this));\n\n}\n\nVirtualEnv.prototype._create = function _create(version, callback) {\n\n  // Remove the old virtualenv if necessary. Always leave the sources\n  // directory intact though, so additional downloading can be avoided.\n  this._reportProgress(\"Creating\", this._virtualenvHome);\n  try {\n    var oldFiles = glob.sync(path.join(this._virtualenvHome, \"*\"), {dot: true});\n    oldFiles.forEach(function(file) {\n      if (file !== this._virtualenvSourcesHome) {\n        this._reportProgress(\"Cleaning\", file);\n        rimraf.sync(file);\n      }\n    }.bind(this));\n  } catch(err) {\n    return callback(err);\n  }\n\n  // Create new virtualenv in \".node-virtualenv\"\n  var sourcePath = this._getPathToSourceForVersion(version);\n  var createProc = childProcess.spawn(this._python,\n    [\"virtualenv.py\"].concat(this._createFlags).concat([this._virtualenvHome]),\n    {cwd: sourcePath}\n  );\n  createProc.stderr.pipe(this._stderr);\n  createProc.stdout.pipe(this._stdout);\n  createProc.on(\"exit\", function(code) {\n    if (code) return callback(new Error(\"Error while creating virtualenv: exit \" + code));\n    callback();\n  }.bind(this));\n\n}\n\nVirtualEnv.prototype._pip = function _pip(callback) {\n\n  // Install Python dependencies into the virtualenv created in the create step.\n  this._reportProgress(\"Installing\", this._virtualenvHome);\n  var pipProc = childProcess.spawn(\"bin/pip\",\n    [\"install\", \"-r\", this._requirements],\n    {cwd: this._virtualenvHome}\n  );\n  pipProc.stderr.pipe(this._stderr);\n  pipProc.stdout.pipe(this._stdout);\n  pipProc.on(\"exit\", function(code) {\n    if (code) return callback(new Error(\"Error while installing dependencies in virtualenv: exit \" + code));\n    callback();\n  }.bind(this));\n\n}\n\nVirtualEnv.prototype._getMeta = function _getMeta(key, defaultValue) {\n\n  try {\n    return JSON.parse(fs.readFileSync(this._virtualenvMetaHome))[key];\n  } catch(err) {\n    return defaultValue;\n  }\n\n}\n\nVirtualEnv.prototype._setMeta = function _setMeta(key, value) {\n\n  var meta = {};\n  try {\n    meta = JSON.parse(fs.readFileSync(this._virtualenvMetaHome));\n  } catch(err) {\n    meta = {};\n  }\n\n  meta[key] = value;\n  fs.writeFileSync(this._virtualenvMetaHome, JSON.stringify(meta));\n\n}\n\nVirtualEnv.prototype._getPathToSourceForVersion = function _getPathToSourceForVersion(version) {\n  return path.join(this._virtualenvSourcesHome, \"virtualenv-\" + version)\n}\n\nVirtualEnv.prototype._virtualenvIsUnchanged = function _virtualenvIsUnchanged() {\n  return this._getMeta(\"currentHash\") === this._expectedHash;\n}\n\nVirtualEnv.prototype._virtualenvSourceIsReady = function _virtualenvSourceIsReady(version) {\n  return fs.existsSync(path.join(\n    this._getPathToSourceForVersion(version),\n    \"virtualenv.py\"\n  ));\n}\n\nVirtualEnv.prototype._virtualenvOnlyNeedsPipUpdates = function _virtualenvOnlyNeedsPipUpdates(version) {\n  return this._getMeta(\"currentVersion\") === version;\n}\n\nmodule.exports = function virtualenv(packagePath, options) {\n  return new VirtualEnv(packagePath, options);\n}\n"]}