Skip to content

Commit 42d1bf2

Browse files
lib, gyp: add support for non-eanglish letters in pathes
On Windows 10 i discovered an issue that if there are non-english letters or symbols in path for python find-python.js script can't find it. This bug is couse by encoding issue which I have (i hope) fixed. At least this bug fix works for me. Have changed: modified: gyp/pylib/gyp/easy_xml.py python 2.7 handle xml_string in wrong way becouse of encoding (line 128) modified: gyp/pylib/gyp/input.py if "encoding:utf8" on line 240 doesn't marked cause to error new file: lib/find-python-script.py i have created this file for convience. Script which can handle non-eanglish letters and symbols cann't °fit one lne becouse it is necessary to specify instarctions for several versions of python modified: lib/find-python.js to make js understand python (line 249)
1 parent cfd12ff commit 42d1bf2

File tree

3 files changed

+19
-3
lines changed

3 files changed

+19
-3
lines changed

gyp/pylib/gyp/easy_xml.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
# Use of this source code is governed by a BSD-style license that can be
33
# found in the LICENSE file.
44

5+
import sys
56
import re
67
import os
78
import locale
@@ -121,7 +122,10 @@ def WriteXmlIfChanged(content, path, encoding="utf-8", pretty=False, win32=False
121122

122123
default_encoding = locale.getdefaultlocale()[1]
123124
if default_encoding and default_encoding.upper() != encoding.upper():
124-
xml_string = xml_string.encode(encoding)
125+
if sys.platform == "win32" and sys.version_info < (3, 7):
126+
xml_string = xml_string.decode("cp1251").encode(encoding)
127+
else:
128+
xml_string = xml_string.encode(encoding)
125129

126130
# Get the old content
127131
try:

lib/find-python-script.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import sys, codecs;
2+
3+
if (sys.stdout.encoding != "utf-8" and sys.platform == "win32"):
4+
if sys.version_info > (3, 7):
5+
sys.stdout.reconfigure(encoding='utf-8')
6+
print(sys.executable)
7+
else:
8+
sys.stdout = codecs.getwriter("utf8")(sys.stdout)
9+
print(sys.executable.decode("cp1251"))
10+
else:
11+
print(sys.executable)

lib/find-python.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
'use strict'
22

3+
const path = require('path')
34
const log = require('npmlog')
45
const semver = require('semver')
56
const cp = require('child_process')
@@ -47,7 +48,7 @@ function PythonFinder (configPython, callback) {
4748

4849
PythonFinder.prototype = {
4950
log: logWithPrefix(log, 'find Python'),
50-
argsExecutable: ['-c', 'import sys; print(sys.executable);'],
51+
argsExecutable: [path.resolve(__dirname, 'find-python-script.py')],
5152
argsVersion: ['-c', 'import sys; print("%s.%s.%s" % sys.version_info[:3]);'],
5253
semverRange: '>=3.6.0',
5354

@@ -274,7 +275,7 @@ PythonFinder.prototype = {
274275
run: function run (exec, args, shell, callback) {
275276
var env = extend({}, this.env)
276277
env.TERM = 'dumb'
277-
const opts = { env: env, shell: shell }
278+
const opts = { env: env, shell: shell, encoding: 'utf8' }
278279

279280
this.log.silly('execFile: exec = %j', exec)
280281
this.log.silly('execFile: args = %j', args)

0 commit comments

Comments
 (0)