Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/find-python.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ class PythonFinder {
static findPython = (...args) => new PythonFinder(...args).findPython()

log = log.withPrefix('find Python')
argsExecutable = ['-c', 'import sys; print(sys.executable);']
argsExecutable = ['-c', 'import sys; sys.stdout.buffer.write(sys.executable.encode(\'utf-8\'));']
argsVersion = ['-c', 'import sys; print("%s.%s.%s" % sys.version_info[:3]);']
semverRange = '>=3.6.0'

Expand Down
15 changes: 15 additions & 0 deletions test/test-find-python.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ const assert = require('assert')
const PythonFinder = require('../lib/find-python')
const { execFile } = require('../lib/util')
const { poison } = require('./common')
const fs = require('fs')
const path = require('path')
const os = require('os')

class TestPythonFinder extends PythonFinder {
constructor (...args) {
Expand All @@ -32,6 +35,18 @@ describe('find-python', function () {
assert.strictEqual(stderr, '')
})

it('find python - encoding', async function () {
const found = await PythonFinder.findPython(null)
const testFolderPath = fs.mkdtempSync(path.join(os.tmpdir(), 'test-ü-'))
const testFilePath = path.join(testFolderPath, 'python.exe')
fs.copyFileSync(found, testFilePath)

const foundTest = await PythonFinder.findPython(testFilePath)
fs.unlinkSync(testFilePath)
fs.rmdirSync(testFolderPath)
assert.strictEqual(foundTest, testFilePath)
})

it('find python - python', async function () {
const f = new TestPythonFinder('python')
f.execFile = async function (program, args, opts) {
Expand Down