source: sasview/src/sas/qtgui/path_prepare.py @ dc3b34e

ESS_GUIESS_GUI_bumps_abstractionESS_GUI_iss1116ESS_GUI_opencl
Last change on this file since dc3b34e was 377ade1, checked in by Piotr Rozyczko <rozyczko@…>, 7 years ago

Fixing unit tests + removal of unnecessary files

  • Property mode set to 100644
File size: 1.6 KB
Line 
1"""
2Prepare python system path to point to right locations
3"""
4import imp
5import os
6import sys
7
8def exe_run():
9    """
10    Check if the process is run as .exe or as .py
11    Primitive extension check of the name of the running process
12    """
13    # Could be checking for .exe, but on mac/linux this wouldn't work well
14    return os.path.splitext(sys.argv[0])[1].lower() != ".py"
15
16def addpath(path):
17    """
18    Add a directory to the python path environment, and to the PYTHONPATH
19    environment variable for subprocesses.
20    """
21    path = os.path.abspath(path)
22    if 'PYTHONPATH' in os.environ:
23        PYTHONPATH = path + os.pathsep + os.environ['PYTHONPATH']
24    else:
25        PYTHONPATH = path
26    os.environ['PYTHONPATH'] = PYTHONPATH
27    sys.path.insert(0, path)
28
29def import_package(modname, path):
30    """Import a package into a particular point in the python namespace"""
31    mod = imp.load_source(modname, os.path.abspath(os.path.join(path,'__init__.py')))
32    sys.modules[modname] = mod
33    mod.__path__ = [os.path.abspath(path)]
34    return mod
35
36root = ""
37if exe_run():
38    root = os.path.abspath(os.path.join(os.path.dirname(__file__), ".."))
39    addpath(os.path.join(root, 'src'))
40    addpath('src')
41else:
42    root = os.path.abspath(os.path.join(os.path.dirname(__file__), "..", "..", ".."))
43    #addpath(os.path.join(root, 'src'))
44    #addpath('src')
45    # Add the local build directory to PYTHONPATH
46    from distutils.util import get_platform
47    platform = '%s-%s'%(get_platform(),sys.version[:3])
48    build_path = os.path.join(root, 'build','lib.'+platform)
49    sys.path.append(build_path)
50
Note: See TracBrowser for help on using the repository browser.