From: <ef...@us...> - 2010-06-14 05:31:26
|
Revision: 8434 http://matplotlib.svn.sourceforge.net/matplotlib/?rev=8434&view=rev Author: efiring Date: 2010-06-14 05:31:20 +0000 (Mon, 14 Jun 2010) Log Message: ----------- [2895114] _get_data_path: improve py2exe handling and readability. Also convert some imports to absolute. Modified Paths: -------------- trunk/matplotlib/lib/matplotlib/__init__.py trunk/matplotlib/lib/matplotlib/config/cutils.py Modified: trunk/matplotlib/lib/matplotlib/__init__.py =================================================================== --- trunk/matplotlib/lib/matplotlib/__init__.py 2010-06-14 02:53:59 UTC (rev 8433) +++ trunk/matplotlib/lib/matplotlib/__init__.py 2010-06-14 05:31:20 UTC (rev 8434) @@ -126,8 +126,10 @@ import sys, os, tempfile -from rcsetup import defaultParams, validate_backend, validate_toolbar -from rcsetup import validate_cairo_format +from matplotlib.rcsetup import (defaultParams, + validate_backend, + validate_toolbar, + validate_cairo_format) major, minor1, minor2, s, tmp = sys.version_info _python24 = major>=2 and minor1>=4 @@ -478,28 +480,33 @@ return path path = os.sep.join([os.path.dirname(__file__), 'mpl-data']) - if os.path.isdir(path): return path + if os.path.isdir(path): + return path # setuptools' namespace_packages may highjack this init file # so need to try something known to be in matplotlib, not basemap import matplotlib.afm path = os.sep.join([os.path.dirname(matplotlib.afm.__file__), 'mpl-data']) - if os.path.isdir(path): return path + if os.path.isdir(path): + return path # py2exe zips pure python, so still need special check if getattr(sys,'frozen',None): - path = os.path.join(os.path.split(sys.path[0])[0], 'mpl-data') - if os.path.isdir(path): return path - else: - # Try again assuming we need to step up one more directory - path = os.path.join(os.path.split(os.path.split(sys.path[0])[0])[0], - 'mpl-data') - if os.path.isdir(path): return path - else: - # Try again assuming sys.path[0] is a dir not a exe - path = os.path.join(sys.path[0], 'mpl-data') - if os.path.isdir(path): return path + exe_path = os.path.dirname(sys.executable) + path = os.path.join(exe_path, 'mpl-data') + if os.path.isdir(path): + return path + # Try again assuming we need to step up one more directory + path = os.path.join(os.path.split(exe_path)[0], 'mpl-data') + if os.path.isdir(path): + return path + + # Try again assuming sys.path[0] is a dir not a exe + path = os.path.join(sys.path[0], 'mpl-data') + if os.path.isdir(path): + return path + raise RuntimeError('Could not find the matplotlib data files') def _get_data_path_cached(): @@ -813,11 +820,12 @@ if NEWCONFIG: #print "importing from reorganized config system!" try: - from config import rcParams, rcdefaults, mplConfig, save_config + from matplotlib.config import (rcParams, rcdefaults, + mplConfig, save_config) verbose.set_level(rcParams['verbose.level']) verbose.set_fileo(rcParams['verbose.fileo']) except: - from config import rcParams, rcdefaults + from matplotlib.config import rcParams, rcdefaults _use_error_msg = """ This call to matplotlib.use() has no effect because the the backend has already been chosen; Modified: trunk/matplotlib/lib/matplotlib/config/cutils.py =================================================================== --- trunk/matplotlib/lib/matplotlib/config/cutils.py 2010-06-14 02:53:59 UTC (rev 8433) +++ trunk/matplotlib/lib/matplotlib/config/cutils.py 2010-06-14 05:31:20 UTC (rev 8434) @@ -9,8 +9,8 @@ import warnings # matplotlib imports -from verbose import verbose -from rcsetup import defaultParams +from matplotlib.verbose import verbose +from matplotlib.rcsetup import defaultParams def is_string_like(obj): try: obj + '' @@ -92,6 +92,10 @@ def _get_data_path(): 'get the path to matplotlib data' +## The following is duplicated in matplotlib.__init__ +def _get_data_path(): + 'get the path to matplotlib data' + if 'MATPLOTLIBDATA' in os.environ: path = os.environ['MATPLOTLIBDATA'] if not os.path.isdir(path): @@ -99,30 +103,36 @@ return path path = os.sep.join([os.path.dirname(__file__), 'mpl-data']) - if os.path.isdir(path): return path + if os.path.isdir(path): + return path # setuptools' namespace_packages may highjack this init file # so need to try something known to be in matplotlib, not basemap import matplotlib.afm path = os.sep.join([os.path.dirname(matplotlib.afm.__file__), 'mpl-data']) - if os.path.isdir(path): return path + if os.path.isdir(path): + return path # py2exe zips pure python, so still need special check if getattr(sys,'frozen',None): - path = os.path.join(os.path.split(sys.path[0])[0], 'mpl-data') - if os.path.isdir(path): return path - else: - # Try again assuming we need to step up one more directory - path = os.path.join(os.path.split(os.path.split(sys.path[0])[0])[0], - 'mpl-data') - if os.path.isdir(path): return path - else: - # Try again assuming sys.path[0] is a dir not a exe - path = os.path.join(sys.path[0], 'mpl-data') - if os.path.isdir(path): return path + exe_path = os.path.dirname(sys.executable) + path = os.path.join(exe_path, 'mpl-data') + if os.path.isdir(path): + return path + # Try again assuming we need to step up one more directory + path = os.path.join(os.path.split(exe_path)[0], 'mpl-data') + if os.path.isdir(path): + return path + + # Try again assuming sys.path[0] is a dir not a exe + path = os.path.join(sys.path[0], 'mpl-data') + if os.path.isdir(path): + return path + raise RuntimeError('Could not find the matplotlib data files') + def _get_data_path_cached(): if defaultParams['datapath'][0] is None: defaultParams['datapath'][0] = _get_data_path() This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |