Index: run.py
===================================================================
--- run.py	(revision 83eb5208b8acb86b064162274de583670f72da47)
+++ run.py	(revision 83eb5208b8acb86b064162274de583670f72da47)
@@ -1,3 +1,5 @@
+# -*- coding: utf-8 -*-
 #!/usr/bin/env python
+
 """
 Run sasview in place.  This allows sasview to use the python
@@ -14,9 +16,10 @@
 """
 
+import imp
 import os
 import sys
-import imp
 from contextlib import contextmanager
-from os.path import abspath, dirname, join as joinpath
+from os.path import join as joinpath
+from os.path import abspath, dirname
 
 
@@ -34,4 +37,5 @@
     sys.path.insert(0, path)
 
+
 @contextmanager
 def cd(path):
@@ -44,10 +48,13 @@
     os.chdir(old_dir)
 
+
 def import_package(modname, path):
     """Import a package into a particular point in the python namespace"""
-    mod = imp.load_source(modname, abspath(joinpath(path,'__init__.py')))
+    #logger.debug("Dynamicly importing: %s", path)
+    mod = imp.load_source(modname, abspath(joinpath(path, '__init__.py')))
     sys.modules[modname] = mod
     mod.__path__ = [abspath(path)]
     return mod
+
 
 def import_dll(modname, build_path):
@@ -56,6 +63,8 @@
     ext = sysconfig.get_config_var('SO')
     # build_path comes from context
-    path = joinpath(build_path, *modname.split('.'))+ext
+    path = joinpath(build_path, *modname.split('.')) + ext
+    # print "importing", modname, "from", path
     return imp.load_dynamic(modname, path)
+
 
 def prepare():
@@ -69,6 +78,6 @@
     from distutils.util import get_platform
     root = abspath(dirname(__file__))
-    platform = '%s-%s'%(get_platform(),sys.version[:3])
-    build_path = joinpath(root, 'build','lib.'+platform)
+    platform = '%s-%s' % (get_platform(), sys.version[:3])
+    build_path = joinpath(root, 'build', 'lib.' + platform)
 
     # Notify the help menu that the Sphinx documentation is in a different
@@ -76,10 +85,22 @@
     os.environ['SASVIEW_DOC_PATH'] = joinpath(build_path, "doc")
 
+    # Make sure that we have a private version of mplconfig
+    #mplconfig = joinpath(abspath(dirname(__file__)), '.mplconfig')
+    #os.environ['MPLCONFIGDIR'] = mplconfig
+    #if not os.path.exists(mplconfig): os.mkdir(mplconfig)
+    #import matplotlib
+    # matplotlib.use('Agg')
+    # print matplotlib.__file__
+    #import pylab; pylab.hold(False)
     # add periodictable to the path
-    try: import periodictable
-    except: addpath(joinpath(root, '..','periodictable'))
+    try:
+        import periodictable
+    except:
+        addpath(joinpath(root, '..', 'periodictable'))
 
-    try: import bumps
-    except: addpath(joinpath(root, '..','bumps'))
+    try:
+        import bumps
+    except:
+        addpath(joinpath(root, '..', 'bumps'))
 
     # Build project if the build directory does not already exist.
@@ -98,5 +119,5 @@
     # be better to just store the package in src/sas/sasview.
     import sas
-    sas.sasview = import_package('sas.sasview', joinpath(root,'sasview'))
+    sas.sasview = import_package('sas.sasview', joinpath(root, 'sasview'))
 
     # Compiled modules need to be pulled from the build directory.
@@ -104,5 +125,5 @@
     import sas.sascalc.pr
     sas.sascalc.pr.core = import_package('sas.sascalc.pr.core',
-                                  joinpath(build_path, 'sas', 'sascalc', 'pr', 'core'))
+                                         joinpath(build_path, 'sas', 'sascalc', 'pr', 'core'))
 
     # Compiled modules need to be pulled from the build directory.
@@ -110,5 +131,5 @@
     import sas.sascalc.file_converter
     sas.sascalc.file_converter.core = import_package('sas.sascalc.file_converter.core',
-                                  joinpath(build_path, 'sas', 'sascalc', 'file_converter', 'core'))                    
+                                                     joinpath(build_path, 'sas', 'sascalc', 'file_converter', 'core'))
 
     # Compiled modules need to be pulled from the build directory.
@@ -116,10 +137,19 @@
     import sas.sascalc.calculator
     sas.sascalc.calculator.core = import_package('sas.sascalc.calculator.core',
-                                  joinpath(build_path, 'sas', 'sascalc', 'calculator', 'core'))
+                                                 joinpath(build_path, 'sas', 'sascalc', 'calculator', 'core'))
 
     sys.path.append(build_path)
 
 if __name__ == "__main__":
+    # Need to add absolute path before actual prepare call,
+    # so logging can be done during initialization process too
+    root = abspath(dirname(__file__))
+    addpath(joinpath(root, 'sasview'))
+    from logger_config import SetupLogger
+    logger = SetupLogger(__name__).config_development()
+
+    logger.debug("Starting SASVIEW in debug mode.")
     prepare()
     from sas.qtgui.MainWindow.MainWindow import run
     run()
+    logger.debug("Ending SASVIEW in debug mode.")
