~ubuntu-branches/debian/experimental/spyder/experimental

« back to all changes in this revision

Viewing changes to spyderlib/baseconfig.py

  • Committer: Package Import Robot
  • Author(s): Picca Frédéric-Emmanuel
  • Date: 2014-05-29 09:06:26 UTC
  • mfrom: (1.1.21) (18.1.6 sid)
  • Revision ID: package-import@ubuntu.com-20140529090626-f58t82g0n5iewaxu
Tags: 2.3.0~rc+dfsg-1~experimental2
* Add spyder-common binary package for all the python2,3 common files
* debian/path
  - 0001-fix-documentation-installation.patch (deleted)
  + 0001-fix-spyderlib-path.patch (new)

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
# -*- coding: utf-8 -*-
2
2
#
3
 
# Copyright © 2011 Pierre Raybaut
 
3
# Copyright © 2011-2013 Pierre Raybaut
4
4
# Licensed under the terms of the MIT License
5
5
# (see spyderlib/__init__.py for details)
6
6
 
13
13
sip API incompatibility issue in spyderlib's non-gui modules)
14
14
"""
15
15
 
 
16
from __future__ import print_function
 
17
 
16
18
import os.path as osp
17
19
import os
18
20
import sys
19
21
 
20
22
# Local imports
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)
 
26
 
 
27
 
 
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')
 
34
 
 
35
# For testing purposes
 
36
# SPYDER_TEST can be set using the --test option of bootstrap.py
 
37
TEST = os.environ.get('SPYDER_TEST')
22
38
 
23
39
 
24
40
#==============================================================================
26
42
#==============================================================================
27
43
STDOUT = sys.stdout
28
44
STDERR = sys.stderr
29
 
DEBUG = bool(os.environ.get('SPYDER_DEBUG', ''))
 
45
def _get_debug_env():
 
46
    debug_env = os.environ.get('SPYDER_DEBUG', '')
 
47
    if not debug_env.isdigit():
 
48
        debug_env = bool(debug_env)
 
49
    return int(debug_env)    
 
50
DEBUG = _get_debug_env()
30
51
 
 
52
def debug_print(message):
 
53
    """Output debug messages to stdout"""
 
54
    if DEBUG:
 
55
        ss = STDOUT
 
56
        print(message, file=ss)
31
57
 
32
58
#==============================================================================
33
59
# Configuration paths
34
60
#==============================================================================
35
 
SUBFOLDER = '.spyder%s' % __version__.split('.')[0]
 
61
# Spyder settings dir
 
62
if TEST is None:
 
63
    SUBFOLDER = '.spyder%s' % __version__.split('.')[0]
 
64
else:
 
65
    SUBFOLDER = 'spyder_test'
 
66
 
 
67
 
 
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
 
73
if PY3:
 
74
    SUBFOLDER = SUBFOLDER + '-py3'
36
75
 
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)
 
78
    if TEST is None:
 
79
        from spyderlib import userconfig
 
80
        conf_dir = osp.join(userconfig.get_home_dir(), SUBFOLDER)
 
81
    else:
 
82
         import tempfile
 
83
         conf_dir = osp.join(tempfile.gettempdir(), SUBFOLDER)
41
84
    if not osp.isdir(conf_dir):
42
85
        os.mkdir(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")
 
200
            y = lgettext(x)
 
201
            if is_text_string(y) and PY3:
 
202
                return y
 
203
            else:
 
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")
164
211
            return x
165
212
        return translate_dumb
166
213
 
173
220
#==============================================================================
174
221
 
175
222
def get_supported_types():
176
 
    """Return a dictionnary containing types lists supported by the 
 
223
    """
 
224
    Return a dictionnary containing types lists supported by the 
177
225
    namespace browser:
178
226
    dict(picklable=picklable_types, editable=editables_types)
179
227
         
180
228
    See:
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
 
231
    
 
232
    Note:
 
233
    If you update this list, don't forget to update doc/variablexplorer.rst
 
234
    """
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)
185
238
    try:
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:
189
242
        pass
190
243
    picklable_types = editable_types[:]
202
255
 
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_',]