forked from bumps/bumps
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrun.py
More file actions
executable file
·69 lines (55 loc) · 1.78 KB
/
run.py
File metadata and controls
executable file
·69 lines (55 loc) · 1.78 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
#!/usr/bin/env python
"""
Build and run bumps.
Usage:
./run.py [bumps cli args]
"""
import os, sys
def addpath(path):
"""
Add a directory to the python path environment, and to the PYTHONPATH
environment variable for subprocesses.
"""
path = os.path.abspath(path)
if 'PYTHONPATH' in os.environ:
PYTHONPATH = path + os.pathsep + os.environ['PYTHONPATH']
else:
PYTHONPATH = path
os.environ['PYTHONPATH'] = PYTHONPATH
sys.path.insert(0, path)
from contextlib import contextmanager
@contextmanager
def cd(path):
old_dir = os.getcwd()
os.chdir(path)
yield
os.chdir(old_dir)
def prepare():
# Make sure that we have a private version of mplconfig
mplconfig = os.path.join(os.getcwd(), '.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)
from distutils.util import get_platform
platform = '.%s-%s'%(get_platform(),sys.version[:3])
sys.dont_write_bytecode = True
#import numpy; numpy.seterr(all='raise')
root = os.path.abspath(os.path.dirname(__file__))
# Force a rebuild
import subprocess
with cd(root), open(os.devnull, 'w') as devnull:
subprocess.call((sys.executable, "setup.py", "build"), shell=False, stdout=devnull)
# Add the build dir to the system path
build_path = os.path.join(root, 'build','lib'+platform)
addpath(build_path)
# Make sample data and models available
os.environ['BUMPS_DATA'] = os.path.join(root,'bumps','gui','resources')
if __name__ == "__main__":
import multiprocessing
multiprocessing.freeze_support()
prepare()
import bumps.cli
bumps.cli.main()