Skip to content

Commit 13bc64a

Browse files
committed
Add Unicode support
1 parent e788db8 commit 13bc64a

File tree

3 files changed

+17
-3
lines changed

3 files changed

+17
-3
lines changed

pypredef_generator.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
# -*- coding: utf-8 -*-
2+
13
"""
24
This module defines functions to generate predefined completions for PyDev by
35
introspection of module objects.
@@ -6,6 +8,7 @@
68
from __future__ import absolute_import, print_function, division, unicode_literals
79

810
import inspect
11+
import io
912
import os
1013

1114
import ast
@@ -19,6 +22,8 @@
1922
PYPREDEF_FILES_DIRNAME = "pypredefs"
2023
PYPREDEF_FILES_DIR = os.path.join(PLUGIN_DIR, PYPREDEF_FILES_DIRNAME)
2124

25+
TEXT_FILE_ENCODING = "utf-8"
26+
2227
#===============================================================================
2328

2429

@@ -32,8 +37,9 @@ def generate_predefined_completions(module):
3237

3338

3439
def write_pypredef_file(module_name, node_module):
35-
with open(_get_pypredef_file_path(module_name), "w") as pypredef_file:
36-
pypredef_file.write(astor.to_source(node_module))
40+
pypredef_file_path = _get_pypredef_file_path(module_name)
41+
with io.open(pypredef_file_path, "w", encoding=TEXT_FILE_ENCODING) as pypredef_file:
42+
pypredef_file.write(astor.to_source(node_module).decode(TEXT_FILE_ENCODING))
3743

3844

3945
def _get_pypredef_file_path(module_name):

pypredef_generator_pdb.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
# -*- coding: utf-8 -*-
2+
13
"""
24
This module is responsible for generating predefined completions for the GIMP
35
procedural database (PDB).
@@ -152,6 +154,8 @@ def _get_ast_docstring_for_pdb_function(pdb_function):
152154
docstring += "\n"
153155
docstring += _get_pdb_docstring_param_info(pdb_function)
154156

157+
docstring = docstring.encode(pypredef_generator.TEXT_FILE_ENCODING)
158+
155159
return ast.Expr(value=ast.Str(s=docstring))
156160

157161

pypredef_generator_plugin.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,13 @@
1+
# -*- coding: utf-8 -*-
2+
13
"""
24
This module defines a GIMP plug-in to generate predefined completions for PyDev
35
(Eclipse IDE plug-in) for GIMP modules.
46
"""
57

68
from __future__ import absolute_import, print_function, division, unicode_literals
79

10+
import io
811
import os
912

1013
import importlib
@@ -43,7 +46,8 @@ def generate_predefined_completions_for_pydev(generate_from_modules, generate_fr
4346

4447
def _get_module_names(modules_file_path):
4548
if os.path.isfile(modules_file_path):
46-
with open(modules_file_path, "r") as modules_file:
49+
with io.open(
50+
modules_file_path, "r", encoding=pypredef_generator.TEXT_FILE_ENCODING) as modules_file:
4751
return [line.strip() for line in modules_file.readlines()]
4852
else:
4953
return []

0 commit comments

Comments
 (0)