Skip to content

Commit

Permalink
lib: add support for non-eanglish letters in pathes
Browse files Browse the repository at this point in the history
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)
  • Loading branch information
owl-from-hogvarts committed Nov 6, 2020
1 parent 66c0f04 commit 1fad283
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 4 deletions.
6 changes: 5 additions & 1 deletion gyp/pylib/gyp/easy_xml.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.

import sys
import re
import os
import locale
Expand Down Expand Up @@ -121,7 +122,10 @@ def WriteXmlIfChanged(content, path, encoding="utf-8", pretty=False, win32=False

default_encoding = locale.getdefaultlocale()[1]
if default_encoding and default_encoding.upper() != encoding.upper():
xml_string = xml_string.encode(encoding)
if (sys.version_info[0] >= 3) and (sys.version_info[1] >= 7):
xml_string = xml_string.encode(encoding)
else:
xml_string = xml_string.decode("cp1251").encode(encoding)

# Get the old content
try:
Expand Down
5 changes: 4 additions & 1 deletion gyp/pylib/gyp/input.py
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,10 @@ def LoadOneBuildFile(build_file_path, data, aux_data, includes, is_target, check
# But since node-gyp produces ebcdic files, do not use that mode.
build_file_contents = open(build_file_path, "r").read()
else:
build_file_contents = open(build_file_path, "rU").read()
if (sys.version_info[0] >= 3) and (sys.version_info[1] >= 7):
build_file_contents = open(build_file_path, 'rU', encoding="utf8").read()
else:
build_file_contents = open(build_file_path, 'rU').read()
else:
raise GypError("%s not found (cwd: %s)" % (build_file_path, os.getcwd()))

Expand Down
13 changes: 13 additions & 0 deletions lib/find-python-script.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import sys, codecs;

if (sys.stdout.encoding != "utf-8"):
if (sys.version_info[0] >= 3) and (sys.version_info[1] >= 7):
sys.stdout.reconfigure(encoding='utf-8')
else:
sys.stdout = codecs.getwriter("utf8")(sys.stdout)


if (sys.version_info[0] >= 3) and (sys.version_info[1] >= 7):
print(sys.executable)
else:
print(sys.executable.decode("cp1251"));
4 changes: 2 additions & 2 deletions lib/find-python.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ function PythonFinder (configPython, callback) {

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

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

this.log.silly('execFile: exec = %j', exec)
this.log.silly('execFile: args = %j', args)
Expand Down

0 comments on commit 1fad283

Please sign in to comment.