diff --git a/lib/virtualenv.js b/lib/virtualenv.js index 29350dc..cef9c07 100644 --- a/lib/virtualenv.js +++ b/lib/virtualenv.js @@ -9,8 +9,11 @@ var rimraf = require("rimraf"); var request = require("request"); var semver = require("semver"); var pypi = require("./pypi"); +var isWindows = require('is-windows'); var VERSION = require("../package.json").version; +// Known feature of virtualenv +var folderWithExecutables = isWindows() ? "Scripts" : "bin"; function VirtualEnv(packagePath) { @@ -116,17 +119,17 @@ VirtualEnv.prototype.install = function install(callback) { } VirtualEnv.prototype.spawn = function spawn(command, args, options) { - var pathToVirtualenvCommand = path.join(this._virtualenvHome, "bin", command); + var pathToVirtualenvCommand = path.join(this._virtualenvHome, folderWithExecutables, command); return childProcess.spawn(pathToVirtualenvCommand, args, options); } VirtualEnv.prototype.spawnPython = function spawnPython(args, options) { - var pathToPython = path.join(this._virtualenvHome, "bin", "python"); + var pathToPython = path.join(this._virtualenvHome, folderWithExecutables, "python"); return childProcess.spawn(pathToPython, args, options); } VirtualEnv.prototype.spawn32bitOSXPython = function spawn32bitOSXPython(args, options) { - var pathToPython = path.join(this._virtualenvHome, "bin", "python"); + var pathToPython = path.join(this._virtualenvHome, folderWithExecutables, "python"); return childProcess.spawn("arch", ["-i386"].concat([pathToPython]).concat(args), options); } @@ -144,17 +147,22 @@ VirtualEnv.prototype._find = function _find(callback) { client.getPackageReleases("virtualenv", function(versions) { if (!versions || !versions.length) return callback(new Error("virtualenv not found on pypi")); - // Find the latest valid version. - var latestValidVersion; - versions.sort(function(a, b) { - return semver.lt(a, b); - }).some(function(version) { - if (semver.satisfies(version, targetVersion)) { - latestValidVersion = version; - return true; - } - }); - if (!latestValidVersion) return callback(new Error("virtualenv " + targetVersion + " not found")); + // Hardcode the latest valid version to be 16.0.0 as 16.1.0 breaks installation + // IOTSYSTOOL-1266 + var latestValidVersion = "16.0.0"; + + // Find the latest valid version. + // var latestValidVersion; + // versions.sort(function(a, b) { + // return semver.lt(a, b); + // }).some(function(version) { + // if (semver.satisfies(version, targetVersion)) { + // //latestValidVersion = version; + // latestValidVersion = "16.0.0"; + // return true; + // } + // }); + //if (!latestValidVersion) return callback(new Error("virtualenv " + targetVersion + " not found")); // Figure out the tarball URL for this version. client.getReleaseUrls("virtualenv", latestValidVersion, function(urls) { @@ -222,7 +230,7 @@ VirtualEnv.prototype._create = function _create(version, callback) { try { var oldFiles = glob.sync(path.join(this._virtualenvHome, "*"), {dot: true}); oldFiles.forEach(function(file) { - if (file !== this._virtualenvSourcesHome) { + if (path.normalize(file) !== this._virtualenvSourcesHome) { this._reportProgress("Cleaning", file); rimraf.sync(file); } @@ -250,7 +258,8 @@ VirtualEnv.prototype._pip = function _pip(callback) { // Install Python dependencies into the virtualenv created in the create step. this._reportProgress("Installing", this._virtualenvHome); - var pipProc = childProcess.spawn("bin/pip", + var pipFolder = folderWithExecutables; + var pipProc = childProcess.spawn(path.join(pipFolder, "pip"), ["install", "-r", this._requirements], {cwd: this._virtualenvHome} ); diff --git a/package.json b/package.json index f3ea288..2f99315 100644 --- a/package.json +++ b/package.json @@ -1,45 +1,35 @@ { - "name": "virtualenv", "version": "0.3.1", "description": "install and use Python dependencies in node with virtualenv", - "keywords": [ "python", "virtualenv", "rpc" ], - "repository": { - "type": "git", - "url": "https://github.com/mjpizz/node-virtualenv.git" + "type": "git", + "url": "https://github.com/mjpizz/node-virtualenv.git" }, - "main": "./lib/virtualenv.js", "engines": { - "node": ">=0.6" + "node": ">=0.6" }, - "dependencies": { - + "glob": "3.x", + "is-windows": "^1.0.1", "request": "2.x", "rimraf": "2.x", - "glob": "3.x", - "tar": "2.x", "semver": "5.x", + "tar": "2.x", "xmlrpc": "0.8.x" - }, - "bin": { "virtualenv-postinstall": "./bin/postinstall" }, - "license": "MIT", - "author": { "name": "Matt Pizzimenti", "url": "http://mjpizz.com" } - }