Skip to content

Commit da5db40

Browse files
hashseedrvagg
authored andcommitted
configure: use sys.version_info to get python version
This is cleaner than filtering additional strings from platform.python_version(). PR-URL: #1504 Reviewed-By: Anna Henningsen <[email protected]> Reviewed-By: Richard Lau <[email protected]> Reviewed-By: Jon Moss <[email protected]> Reviewed-By: Rod Vagg <[email protected]>
1 parent 25208f1 commit da5db40

File tree

2 files changed

+11
-19
lines changed

2 files changed

+11
-19
lines changed

lib/configure.js

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -437,7 +437,7 @@ PythonFinder.prototype = {
437437
},
438438

439439
checkPythonVersion: function checkPythonVersion () {
440-
var args = ['-c', 'import platform; print(platform.python_version());']
440+
var args = ['-c', 'import sys; print "%s.%s.%s" % sys.version_info[:3];']
441441
var env = extend({}, this.env)
442442
env.TERM = 'dumb'
443443

@@ -449,14 +449,6 @@ PythonFinder.prototype = {
449449
'`%s -c "' + args[1] + '"` returned: %j',
450450
this.python, stdout)
451451
var version = stdout.trim()
452-
if (~version.indexOf('+')) {
453-
this.log.silly('stripping "+" sign(s) from version')
454-
version = version.replace(/\+/g, '')
455-
}
456-
if (~version.indexOf('rc')) {
457-
this.log.silly('stripping "rc" identifier from version')
458-
version = version.replace(/rc(.*)$/ig, '')
459-
}
460452
var range = semver.Range('>=2.5.0 <3.0.0')
461453
var valid = false
462454
try {

test/test-find-python.js

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ test('find python - python', function (t) {
6262
}
6363
f.execFile = function(program, args, opts, cb) {
6464
t.strictEqual(program, 'python')
65-
t.ok(/import platform/.test(args[1]))
65+
t.ok(/import sys/.test(args[1]))
6666
cb(null, '2.7.0')
6767
}
6868
f.checkPython()
@@ -83,7 +83,7 @@ test('find python - python too old', function (t) {
8383
}
8484
f.execFile = function(program, args, opts, cb) {
8585
t.strictEqual(program, 'python')
86-
t.ok(/import platform/.test(args[1]))
86+
t.ok(/import sys/.test(args[1]))
8787
cb(null, '2.3.4')
8888
}
8989
f.checkPython()
@@ -103,7 +103,7 @@ test('find python - python too new', function (t) {
103103
}
104104
f.execFile = function(program, args, opts, cb) {
105105
t.strictEqual(program, 'python')
106-
t.ok(/import platform/.test(args[1]))
106+
t.ok(/import sys/.test(args[1]))
107107
cb(null, '3.0.0')
108108
}
109109
f.checkPython()
@@ -142,7 +142,7 @@ test('find python - no python2', function (t) {
142142
}
143143
f.execFile = function(program, args, opts, cb) {
144144
t.strictEqual(program, 'python')
145-
t.ok(/import platform/.test(args[1]))
145+
t.ok(/import sys/.test(args[1]))
146146
cb(null, '2.7.0')
147147
}
148148
f.checkPython()
@@ -189,7 +189,7 @@ test('find python - no python, use python launcher', function (t) {
189189
f.execFile = function(program, args, opts, cb) {
190190
f.execFile = function(program, args, opts, cb) {
191191
t.strictEqual(program, 'Z:\\snake.exe')
192-
t.ok(/import platform/.test(args[1]))
192+
t.ok(/import sys/.test(args[1]))
193193
cb(null, '2.7.0')
194194
}
195195
t.strictEqual(program, 'py.exe')
@@ -220,7 +220,7 @@ test('find python - python 3, use python launcher', function (t) {
220220
f.execFile = function(program, args, opts, cb) {
221221
f.execFile = function(program, args, opts, cb) {
222222
t.strictEqual(program, 'Z:\\snake.exe')
223-
t.ok(/import platform/.test(args[1]))
223+
t.ok(/import sys/.test(args[1]))
224224
cb(null, '2.7.0')
225225
}
226226
t.strictEqual(program, 'py.exe')
@@ -229,7 +229,7 @@ test('find python - python 3, use python launcher', function (t) {
229229
cb(null, 'Z:\\snake.exe')
230230
}
231231
t.strictEqual(program, 'python')
232-
t.ok(/import platform/.test(args[1]))
232+
t.ok(/import sys/.test(args[1]))
233233
cb(null, '3.0.0')
234234
}
235235
f.checkPython()
@@ -257,7 +257,7 @@ test('find python - python 3, use python launcher, python 2 too old',
257257
f.execFile = function(program, args, opts, cb) {
258258
f.execFile = function(program, args, opts, cb) {
259259
t.strictEqual(program, 'Z:\\snake.exe')
260-
t.ok(/import platform/.test(args[1]))
260+
t.ok(/import sys/.test(args[1]))
261261
cb(null, '2.3.4')
262262
}
263263
t.strictEqual(program, 'py.exe')
@@ -266,7 +266,7 @@ test('find python - python 3, use python launcher, python 2 too old',
266266
cb(null, 'Z:\\snake.exe')
267267
}
268268
t.strictEqual(program, 'python')
269-
t.ok(/import platform/.test(args[1]))
269+
t.ok(/import sys/.test(args[1]))
270270
cb(null, '3.0.0')
271271
}
272272
f.checkPython()
@@ -291,7 +291,7 @@ test('find python - no python, no python launcher, good guess', function (t) {
291291
f.execFile = function(program, args, opts, cb) {
292292
f.execFile = function(program, args, opts, cb) {
293293
t.ok(re.test(program))
294-
t.ok(/import platform/.test(args[1]))
294+
t.ok(/import sys/.test(args[1]))
295295
cb(null, '2.7.0')
296296
}
297297
t.strictEqual(program, 'py.exe')

0 commit comments

Comments
 (0)