Skip to content

Commit 1fad283

Browse files
lib: 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 66c0f04 commit 1fad283

File tree

4 files changed

+24
-4
lines changed

4 files changed

+24
-4
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.version_info[0] >= 3) and (sys.version_info[1] >= 7):
126+
xml_string = xml_string.encode(encoding)
127+
else:
128+
xml_string = xml_string.decode("cp1251").encode(encoding)
125129

126130
# Get the old content
127131
try:

gyp/pylib/gyp/input.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -236,7 +236,10 @@ def LoadOneBuildFile(build_file_path, data, aux_data, includes, is_target, check
236236
# But since node-gyp produces ebcdic files, do not use that mode.
237237
build_file_contents = open(build_file_path, "r").read()
238238
else:
239-
build_file_contents = open(build_file_path, "rU").read()
239+
if (sys.version_info[0] >= 3) and (sys.version_info[1] >= 7):
240+
build_file_contents = open(build_file_path, 'rU', encoding="utf8").read()
241+
else:
242+
build_file_contents = open(build_file_path, 'rU').read()
240243
else:
241244
raise GypError("%s not found (cwd: %s)" % (build_file_path, os.getcwd()))
242245

lib/find-python-script.py

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

lib/find-python.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ function PythonFinder (configPython, callback) {
1616

1717
PythonFinder.prototype = {
1818
log: logWithPrefix(log, 'find Python'),
19-
argsExecutable: ['-c', 'import sys; print(sys.executable);'],
19+
argsExecutable: [path.resolve(__dirname, 'find-python-script.py')],
2020
argsVersion: ['-c', 'import sys; print("%s.%s.%s" % sys.version_info[:3]);'],
2121
semverRange: '2.7.x || >=3.5.0',
2222

@@ -246,7 +246,7 @@ PythonFinder.prototype = {
246246
run: function run (exec, args, shell, callback) {
247247
var env = extend({}, this.env)
248248
env.TERM = 'dumb'
249-
const opts = { env: env, shell: shell }
249+
const opts = { env: env, shell: shell, encoding: 'utf8' }
250250

251251
this.log.silly('execFile: exec = %j', exec)
252252
this.log.silly('execFile: args = %j', args)

0 commit comments

Comments
 (0)