/usr/share/pyshared/spyderlib/baseconfig.py is in python-spyderlib 2.1.9-1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 | # -*- coding: utf-8 -*-
#
# Copyright © 2011 Pierre Raybaut
# Licensed under the terms of the MIT License
# (see spyderlib/__init__.py for details)
"""
Spyder base configuration management
As opposed to spyderlib/config.py, this configuration script deals
exclusively with non-GUI features configuration only
(in other words, we won't import any PyQt object here, avoiding any
sip API incompatibility issue in spyderlib's non-gui modules)
"""
import os.path as osp
import os
import sys
# Local imports
from spyderlib import __version__
#==============================================================================
# Debug helpers
#==============================================================================
STDOUT = sys.stdout
STDERR = sys.stderr
DEBUG = bool(os.environ.get('SPYDER_DEBUG', ''))
#==============================================================================
# Configuration paths
#==============================================================================
SUBFOLDER = '.spyder%s' % __version__.split('.')[0]
def get_conf_path(filename=None):
"""Return absolute path for configuration file with specified filename"""
from spyderlib import userconfig
conf_dir = osp.join(userconfig.get_home_dir(), SUBFOLDER)
if not osp.isdir(conf_dir):
os.mkdir(conf_dir)
if filename is None:
return conf_dir
else:
return osp.join(conf_dir, filename)
def get_module_path(modname):
"""Return module *modname* base path"""
return osp.abspath(osp.dirname(sys.modules[modname].__file__))
def get_module_data_path(modname, relpath=None, attr_name='DATAPATH'):
"""Return module *modname* data path
Note: relpath is ignored if module has an attribute named *attr_name*
Handles py2exe/cx_Freeze distributions"""
datapath = getattr(sys.modules[modname], attr_name, '')
if datapath:
return datapath
else:
datapath = get_module_path(modname)
parentdir = osp.join(datapath, osp.pardir)
if osp.isfile(parentdir):
# Parent directory is not a directory but the 'library.zip' file:
# this is either a py2exe or a cx_Freeze distribution
datapath = osp.abspath(osp.join(osp.join(parentdir, osp.pardir),
modname))
if relpath is not None:
datapath = osp.abspath(osp.join(datapath, relpath))
return datapath
def get_module_source_path(modname, basename=None):
"""Return module *modname* source path
If *basename* is specified, return *modname.basename* path where
*modname* is a package containing the module *basename*
*basename* is a filename (not a module name), so it must include the
file extension: .py or .pyw
Handles py2exe/cx_Freeze distributions"""
srcpath = get_module_path(modname)
parentdir = osp.join(srcpath, osp.pardir)
if osp.isfile(parentdir):
# Parent directory is not a directory but the 'library.zip' file:
# this is either a py2exe or a cx_Freeze distribution
srcpath = osp.abspath(osp.join(osp.join(parentdir, osp.pardir),
modname))
if basename is not None:
srcpath = osp.abspath(osp.join(srcpath, basename))
return srcpath
def is_py2exe_or_cx_Freeze():
"""Return True if this is a py2exe/cx_Freeze distribution of Spyder"""
return osp.isfile(osp.join(get_module_path('spyderlib'), osp.pardir))
SCIENTIFIC_STARTUP = get_module_source_path('spyderlib',
'scientific_startup.py')
#==============================================================================
# Translations
#==============================================================================
def get_translation(modname, dirname=None):
"""Return translation callback for module *modname*"""
if dirname is None:
dirname = modname
locale_path = get_module_data_path(dirname, relpath="locale",
attr_name='LOCALEPATH')
# fixup environment var LANG in case it's unknown
if "LANG" not in os.environ:
import locale
lang = locale.getdefaultlocale()[0]
if lang is not None:
os.environ["LANG"] = lang
import gettext
try:
_trans = gettext.translation(modname, locale_path, codeset="utf-8")
lgettext = _trans.lgettext
def translate_gettext(x):
if isinstance(x, unicode):
x = x.encode("utf-8")
return unicode(lgettext(x), "utf-8")
return translate_gettext
except IOError, _e: # analysis:ignore
#print "Not using translations (%s)" % _e
def translate_dumb(x):
if not isinstance(x, unicode):
return unicode(x, "utf-8")
return x
return translate_dumb
# Translation callback
_ = get_translation("spyderlib")
#==============================================================================
# Namespace Browser (Variable Explorer) configuration management
#==============================================================================
def get_supported_types():
"""Return a dictionnary containing types lists supported by the
namespace browser:
dict(picklable=picklable_types, editable=editables_types)
See:
get_remote_data function in spyderlib/widgets/externalshell/monitor.py
get_internal_shell_filter method in namespacebrowser.py"""
from datetime import date
editable_types = [int, long, float, list, dict, tuple, str, unicode, date]
try:
from numpy import ndarray, matrix
editable_types += [ndarray, matrix]
except ImportError:
pass
picklable_types = editable_types[:]
try:
from spyderlib.pil_patch import Image
editable_types.append(Image.Image)
except ImportError:
pass
return dict(picklable=picklable_types, editable=editable_types)
# Variable explorer display / check all elements data types for sequences:
# (when saving the variable explorer contents, check_all is True,
# see widgets/externalshell/namespacebrowser.py:NamespaceBrowser.save_data)
CHECK_ALL = False #XXX: If True, this should take too much to compute...
EXCLUDED_NAMES = ['nan', 'inf', 'infty', 'little_endian', 'colorbar_doc',
'typecodes', '__builtins__', '__main__', '__doc__', 'NaN',
'Inf', 'Infinity', 'sctypes']
|