source: sasview/installers/sasview.py @ c71b20a

Last change on this file since c71b20a was 3244b548, checked in by Piotr Rozyczko <rozyczko@…>, 7 years ago

Added missing file required in the build process

  • Property mode set to 100644
File size: 3.2 KB
Line 
1# -*- coding: utf-8 -*-
2#!/usr/bin/env python
3
4"""
5Run sasview in place.  This allows sasview to use the python
6files in the source tree without having to call setup.py install
7first.  A rebuild is still necessary when working on sas models
8or c modules.
9
10Usage:
11
12./run.py [(module|script) args...]
13
14Without arguments run.py runs sasview.  With arguments, run.py will run
15the given module or script.
16"""
17
18import imp
19import os
20import sys
21from contextlib import contextmanager
22from os.path import join as joinpath
23from os.path import abspath, dirname, realpath
24
25
26def addpath(path):
27    """
28    Add a directory to the python path environment, and to the PYTHONPATH
29    environment variable for subprocesses.
30    """
31    path = abspath(path)
32    if 'PYTHONPATH' in os.environ:
33        PYTHONPATH = path + os.pathsep + os.environ['PYTHONPATH']
34    else:
35        PYTHONPATH = path
36    os.environ['PYTHONPATH'] = PYTHONPATH
37    sys.path.insert(0, path)
38
39
40@contextmanager
41def cd(path):
42    """
43    Change directory for duration of "with" context.
44    """
45    old_dir = os.getcwd()
46    os.chdir(path)
47    yield
48    os.chdir(old_dir)
49
50
51def import_package(modname, path):
52    """Import a package into a particular point in the python namespace"""
53    #logger.debug("Dynamicly importing: %s", path)
54    mod = imp.load_source(modname, abspath(joinpath(path, '__init__.py')))
55    sys.modules[modname] = mod
56    mod.__path__ = [abspath(path)]
57    return mod
58
59
60def import_dll(modname, build_path):
61    """Import a DLL from the build directory"""
62    import sysconfig
63    ext = sysconfig.get_config_var('SO')
64    # build_path comes from context
65    path = joinpath(build_path, *modname.split('.')) + ext
66    return imp.load_dynamic(modname, path)
67
68
69def prepare():
70    # Don't create *.pyc files
71    sys.dont_write_bytecode = True
72
73    # find the directories for the source and build
74    from distutils.util import get_platform
75    root = joinpath(abspath(dirname(sys.argv[0])), '..')
76
77    platform = '%s-%s' % (get_platform(), sys.version[:3])
78    build_path = joinpath(root, 'build', 'lib.' + platform)
79
80    # Notify the help menu that the Sphinx documentation is in a different
81    # place than it otherwise would be.
82    os.environ['SASVIEW_DOC_PATH'] = joinpath(build_path, "doc")
83
84    # add periodictable to the path
85    try:
86        import periodictable
87    except:
88        addpath(joinpath(root, '..', 'periodictable'))
89
90    try:
91        import bumps
92    except:
93        addpath(joinpath(root, '..', 'bumps'))
94
95    # Put the source trees on the path
96    addpath(joinpath(root, 'src'))
97
98    # sasmodels on the path
99    addpath(joinpath(root, '../sasmodels/'))
100
101    from sas.sascalc.dataloader.readers import (
102        abs_reader, anton_paar_saxs_reader, ascii_reader, cansas_reader_HDF5,
103        cansas_reader, danse_reader, red2d_reader, sesans_reader, tiff_reader,
104        xml_reader,
105    )
106
107    sys.path.append(build_path)
108
109if __name__ == "__main__":
110    # Need to add absolute path before actual prepare call,
111    # so logging can be done during initialization process too
112    root = abspath(dirname(realpath(sys.argv[0])))
113    addpath(joinpath(root, '..', 'src','sas'))
114
115    prepare()
116    from sas.qtgui.MainWindow.MainWindow import run_sasview
117    run_sasview()
118
Note: See TracBrowser for help on using the repository browser.