forked from yt-project/yt
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsetupext.py
161 lines (132 loc) · 4.62 KB
/
setupext.py
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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
import os
from pkg_resources import resource_filename
import shutil
from subprocess import Popen, PIPE
import sys
import tempfile
def check_for_openmp():
"""Returns True if local setup supports OpenMP, False otherwise"""
# See https://bugs.python.org/issue25150
if sys.version_info[:3] == (3, 5, 0) or os.name == 'nt':
return False
# Create a temporary directory
tmpdir = tempfile.mkdtemp()
curdir = os.getcwd()
exit_code = 1
try:
os.chdir(tmpdir)
# Get compiler invocation
compiler = os.getenv('CC', 'cc')
compiler = compiler.split(' ')
# Attempt to compile a test script.
# See http://openmp.org/wp/openmp-compilers/
filename = r'test.c'
file = open(filename, 'wt', 1)
file.write(
"#include <omp.h>\n"
"#include <stdio.h>\n"
"int main() {\n"
"#pragma omp parallel\n"
"printf(\"Hello from thread %d, nthreads %d\\n\", omp_get_thread_num(), omp_get_num_threads());\n"
"}"
)
file.flush()
p = Popen(compiler + ['-fopenmp', filename],
stdin=PIPE, stdout=PIPE, stderr=PIPE)
output, err = p.communicate()
exit_code = p.returncode
if exit_code != 0:
print("Compilation of OpenMP test code failed with the error: ")
print(err.decode('utf8'))
print("Disabling OpenMP support. ")
# Clean up
file.close()
except OSError:
print("check_for_openmp() could not find your C compiler. "
"Attempted to use '%s'. " % compiler)
return False
finally:
os.chdir(curdir)
shutil.rmtree(tmpdir)
return exit_code == 0
def check_for_pyembree():
try:
fn = resource_filename("pyembree", "rtcore.pxd")
except ImportError:
return None
return os.path.dirname(fn)
def in_conda_env():
return any(s in sys.version for s in ("Anaconda", "Continuum"))
def read_embree_location():
'''
Attempts to locate the embree installation. First, we check for an
EMBREE_DIR environment variable. If one is not defined, we look for
an embree.cfg file in the root yt source directory. Finally, if that
is not present, we default to /usr/local. If embree is installed in a
non-standard location and none of the above are set, the compile will
not succeed. This only gets called if check_for_pyembree() returns
something other than None.
'''
rd = os.environ.get('EMBREE_DIR')
if rd is None:
try:
rd = open("embree.cfg").read().strip()
except IOError:
rd = '/usr/local'
fail_msg = ("I attempted to find Embree headers in %s. \n"
"If this is not correct, please set your correct embree location \n"
"using EMBREE_DIR environment variable or your embree.cfg file. \n"
"Please see http://yt-project.org/docs/dev/visualizing/unstructured_mesh_rendering.html "
"for more information. \n" % rd)
# Create a temporary directory
tmpdir = tempfile.mkdtemp()
curdir = os.getcwd()
try:
os.chdir(tmpdir)
# Get compiler invocation
compiler = os.getenv('CXX', 'c++')
compiler = compiler.split(' ')
# Attempt to compile a test script.
filename = r'test.cpp'
file = open(filename, 'wt', 1)
file.write(
'#include "embree2/rtcore.h"\n'
'int main() {\n'
'return 0;\n'
'}'
)
file.flush()
p = Popen(compiler + ['-I%s/include/' % rd, filename],
stdin=PIPE, stdout=PIPE, stderr=PIPE)
output, err = p.communicate()
exit_code = p.returncode
if exit_code != 0:
print("Pyembree is installed, but I could not compile Embree test code.")
print("The error message was: ")
print(err)
print(fail_msg)
# Clean up
file.close()
except OSError:
print("read_embree_location() could not find your C compiler. "
"Attempted to use '%s'. " % compiler)
return False
finally:
os.chdir(curdir)
shutil.rmtree(tmpdir)
return rd
def get_mercurial_changeset_id(target_dir):
'''
Returns changeset and branch using hglib
'''
try:
import hglib
except ImportError:
return None
try:
with hglib.open(target_dir) as repo:
changeset = repo.identify(
id=True, branch=True).strip().decode('utf8')
except hglib.error.ServerError:
return None
return changeset