source: sasview/run.py @ 64ff687

ESS_GUIESS_GUI_DocsESS_GUI_batch_fittingESS_GUI_bumps_abstractionESS_GUI_iss1116ESS_GUI_iss879ESS_GUI_iss959ESS_GUI_openclESS_GUI_orderingESS_GUI_sync_sascalccostrafo411magnetic_scattrelease-4.2.2ticket-1009ticket-1094-headlessticket-1242-2d-resolutionticket-1243ticket-1249ticket885unittest-saveload
Last change on this file since 64ff687 was 64ff687, checked in by Ricardo Ferraz Leal <ricleal@…>, 7 years ago

Logger import error in run.py

  • Property mode set to 100755
File size: 5.1 KB
Line 
1#!/usr/bin/env python
2"""
3Run sasview in place.  This allows sasview to use the python
4files in the source tree without having to call setup.py install
5first.  A rebuild is still necessary when working on sas models
6or c modules.
7
8Usage:
9
10./run.py [(module|script) args...]
11
12Without arguments run.py runs sasview.  With arguments, run.py will run
13the given module or script.
14"""
15
16import imp
17import logging
18import logging.config
19import os
20import sys
21from contextlib import contextmanager
22from os.path import join as joinpath
23from os.path import abspath, dirname
24
25try:
26    from sasview.logger_config import SetupLogger
27except ImportError:
28    from logger_config import SetupLogger
29
30l = SetupLogger(__name__)
31logger = l.config_development()
32
33def addpath(path):
34    """
35    Add a directory to the python path environment, and to the PYTHONPATH
36    environment variable for subprocesses.
37    """
38    path = abspath(path)
39    if 'PYTHONPATH' in os.environ:
40        PYTHONPATH = path + os.pathsep + os.environ['PYTHONPATH']
41    else:
42        PYTHONPATH = path
43    os.environ['PYTHONPATH'] = PYTHONPATH
44    sys.path.insert(0, path)
45
46@contextmanager
47def cd(path):
48    """
49    Change directory for duration of "with" context.
50    """
51    old_dir = os.getcwd()
52    os.chdir(path)
53    yield
54    os.chdir(old_dir)
55
56def import_package(modname, path):
57    """Import a package into a particular point in the python namespace"""
58    mod = imp.load_source(modname, abspath(joinpath(path,'__init__.py')))
59    sys.modules[modname] = mod
60    mod.__path__ = [abspath(path)]
61    return mod
62
63def import_dll(modname, build_path):
64    """Import a DLL from the build directory"""
65    import sysconfig
66    ext = sysconfig.get_config_var('SO')
67    # build_path comes from context
68    path = joinpath(build_path, *modname.split('.'))+ext
69    #print "importing", modname, "from", path
70    return imp.load_dynamic(modname, path)
71
72def prepare():
73    # Don't create *.pyc files
74    sys.dont_write_bytecode = True
75
76    # Debug numpy warnings
77    #import numpy; numpy.seterr(all='raise')
78
79    # find the directories for the source and build
80    from distutils.util import get_platform
81    root = abspath(dirname(__file__))
82    platform = '%s-%s'%(get_platform(),sys.version[:3])
83    build_path = joinpath(root, 'build','lib.'+platform)
84
85    # Notify the help menu that the Sphinx documentation is in a different
86    # place than it otherwise would be.
87    os.environ['SASVIEW_DOC_PATH'] = joinpath(build_path, "doc")
88
89    # Make sure that we have a private version of mplconfig
90    #mplconfig = joinpath(abspath(dirname(__file__)), '.mplconfig')
91    #os.environ['MPLCONFIGDIR'] = mplconfig
92    #if not os.path.exists(mplconfig): os.mkdir(mplconfig)
93    #import matplotlib
94    #matplotlib.use('Agg')
95    #print matplotlib.__file__
96    #import pylab; pylab.hold(False)
97    # add periodictable to the path
98    try: import periodictable
99    except: addpath(joinpath(root, '..','periodictable'))
100
101    try: import bumps
102    except: addpath(joinpath(root, '..','bumps'))
103
104    # select wx version
105    #addpath(os.path.join(root, '..','wxPython-src-3.0.0.0','wxPython'))
106
107    # Build project if the build directory does not already exist.
108    if not os.path.exists(build_path):
109        import subprocess
110        with cd(root):
111            subprocess.call((sys.executable, "setup.py", "build"), shell=False)
112
113    # Put the source trees on the path
114    addpath(joinpath(root, 'src'))
115
116    # sasmodels on the path
117    addpath(joinpath(root, '../sasmodels/'))
118
119    # Import the sasview package from root/sasview as sas.sasview.  It would
120    # be better to just store the package in src/sas/sasview.
121    import sas
122    sas.sasview = import_package('sas.sasview', joinpath(root,'sasview'))
123
124    # The sas.models package Compiled Model files should be pulled in from the build directory even though
125    # the source is stored in src/sas/models.
126
127    # Compiled modules need to be pulled from the build directory.
128    # Some packages are not where they are needed, so load them explicitly.
129    import sas.sascalc.pr
130    sas.sascalc.pr.core = import_package('sas.sascalc.pr.core',
131                                  joinpath(build_path, 'sas', 'sascalc', 'pr', 'core'))
132
133    # Compiled modules need to be pulled from the build directory.
134    # Some packages are not where they are needed, so load them explicitly.
135    import sas.sascalc.file_converter
136    sas.sascalc.file_converter.core = import_package('sas.sascalc.file_converter.core',
137                                  joinpath(build_path, 'sas', 'sascalc', 'file_converter', 'core'))                   
138
139    # Compiled modules need to be pulled from the build directory.
140    # Some packages are not where they are needed, so load them explicitly.
141    import sas.sascalc.calculator
142    sas.sascalc.calculator.core = import_package('sas.sascalc.calculator.core',
143                                  joinpath(build_path, 'sas', 'sascalc', 'calculator', 'core'))
144
145    sys.path.append(build_path)
146
147    #print "\n".join(sys.path)
148
149if __name__ == "__main__":
150    logger.debug("Starting SASVIEW in debug mode.")
151    prepare()
152    from sas.sasview.sasview import run
153    run()
154    logger.debug("Ending SASVIEW in debug mode.")
Note: See TracBrowser for help on using the repository browser.