13
13
sip API incompatibility issue in spyderlib's non-gui modules)
16
from __future__ import print_function
16
18
import os.path as osp
21
23
from spyderlib import __version__
24
from spyderlib.py3compat import (is_unicode, TEXT_TYPES, INT_TYPES, PY3,
25
to_text_string, is_text_string)
28
#==============================================================================
29
# Only for development
30
#==============================================================================
31
# To activate/deactivate certain things for development
32
# SPYDER_DEV is (and *only* has to be) set in bootstrap.py
33
DEV = os.environ.get('SPYDER_DEV')
35
# For testing purposes
36
# SPYDER_TEST can be set using the --test option of bootstrap.py
37
TEST = os.environ.get('SPYDER_TEST')
24
40
#==============================================================================
26
42
#==============================================================================
27
43
STDOUT = sys.stdout
28
44
STDERR = sys.stderr
29
DEBUG = bool(os.environ.get('SPYDER_DEBUG', ''))
46
debug_env = os.environ.get('SPYDER_DEBUG', '')
47
if not debug_env.isdigit():
48
debug_env = bool(debug_env)
50
DEBUG = _get_debug_env()
52
def debug_print(message):
53
"""Output debug messages to stdout"""
56
print(message, file=ss)
32
58
#==============================================================================
33
59
# Configuration paths
34
60
#==============================================================================
35
SUBFOLDER = '.spyder%s' % __version__.split('.')[0]
63
SUBFOLDER = '.spyder%s' % __version__.split('.')[0]
65
SUBFOLDER = 'spyder_test'
68
# We can't have PY2 and PY3 settings in the same dir because:
69
# 1. This leads to ugly crashes and freezes (e.g. by trying to
70
# embed a PY2 interpreter in PY3)
71
# 2. We need to save the list of installed modules (for code
72
# completion) separately for each version
74
SUBFOLDER = SUBFOLDER + '-py3'
37
76
def get_conf_path(filename=None):
38
77
"""Return absolute path for configuration file with specified filename"""
39
from spyderlib import userconfig
40
conf_dir = osp.join(userconfig.get_home_dir(), SUBFOLDER)
79
from spyderlib import userconfig
80
conf_dir = osp.join(userconfig.get_home_dir(), SUBFOLDER)
83
conf_dir = osp.join(tempfile.gettempdir(), SUBFOLDER)
41
84
if not osp.isdir(conf_dir):
43
86
if filename is None:
152
195
_trans = gettext.translation(modname, locale_path, codeset="utf-8")
153
196
lgettext = _trans.lgettext
154
197
def translate_gettext(x):
155
if isinstance(x, unicode):
198
if not PY3 and is_unicode(x):
156
199
x = x.encode("utf-8")
157
return unicode(lgettext(x), "utf-8")
201
if is_text_string(y) and PY3:
204
return to_text_string(y, "utf-8")
158
205
return translate_gettext
159
except IOError, _e: # analysis:ignore
206
except IOError as _e: # analysis:ignore
160
207
#print "Not using translations (%s)" % _e
161
208
def translate_dumb(x):
162
if not isinstance(x, unicode):
163
return unicode(x, "utf-8")
209
if not is_unicode(x):
210
return to_text_string(x, "utf-8")
165
212
return translate_dumb
173
220
#==============================================================================
175
222
def get_supported_types():
176
"""Return a dictionnary containing types lists supported by the
224
Return a dictionnary containing types lists supported by the
177
225
namespace browser:
178
226
dict(picklable=picklable_types, editable=editables_types)
181
229
get_remote_data function in spyderlib/widgets/externalshell/monitor.py
182
get_internal_shell_filter method in namespacebrowser.py"""
230
get_internal_shell_filter method in namespacebrowser.py
233
If you update this list, don't forget to update doc/variablexplorer.rst
183
235
from datetime import date
184
editable_types = [int, long, float, list, dict, tuple, str, unicode, date]
236
editable_types = [int, float, complex, list, dict, tuple, date
237
] + list(TEXT_TYPES) + list(INT_TYPES)
186
from numpy import ndarray, matrix
187
editable_types += [ndarray, matrix]
239
from numpy import ndarray, matrix, generic
240
editable_types += [ndarray, matrix, generic]
188
241
except ImportError:
190
243
picklable_types = editable_types[:]
203
256
EXCLUDED_NAMES = ['nan', 'inf', 'infty', 'little_endian', 'colorbar_doc',
204
257
'typecodes', '__builtins__', '__main__', '__doc__', 'NaN',
205
'Inf', 'Infinity', 'sctypes']
b'\\ No newline at end of file'
258
'Inf', 'Infinity', 'sctypes', 'rcParams', 'rcParamsDefault',
259
'sctypeNA', 'typeNA', 'False_', 'True_',]