Skip to content

Commit 4f4fd9b

Browse files
doutriaux1Sam Fries
authored andcommitted
need to pass -b to build cdat_info out of source (#2051)
* need to pass -b to build cdat_info out of source * Added cdat_info to list of pkg to build * works better with files...
1 parent 23b0f76 commit 4f4fd9b

File tree

4 files changed

+260
-1
lines changed

4 files changed

+260
-1
lines changed

CMake/cdat_modules_extra/install_cdat_from_conda.bash.in

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,13 @@
33
@CONDA@ create -y -n @CONDA_ENVIRONMENT_NAME@ -c @CONDA_CHANNEL_UVCDAT@ hdf5 libnetcdf lapack clapack ossuuid libcf esmf jasper g2clib yasm x264 ffmpeg cmor proj4>=4.9.2 vtk libcdms cdat_info flake8 requests numpy==1.11.1 cycler matplotlib --show-channel-urls --copy
44

55
source @ACTIVATE@ @CONDA_ENVIRONMENT_NAME@
6-
for pkg in testing cdtime regrid2 cdms2 esg DV3D vcs vcsaddons cdutil unidata xmgrace genutil Thermo WK distarray; do
6+
for pkg in cdat_info testing cdtime regrid2 cdms2 esg DV3D vcs vcsaddons cdutil unidata xmgrace genutil Thermo WK distarray; do
77
cd @cdat_SOURCE_DIR@/Packages/${pkg}
88
rm -rf build
99
if [ ${pkg} == "vcs" ]; then
1010
python setup.py install --old-and-unmanageable
11+
elif [ ${pkg} == "cdat_info" ]; then
12+
python setup.py build -b build install
1113
else
1214
python setup.py install
1315
fi

Packages/cdat_info/Lib/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
from cdat_info import * # noqa

Packages/cdat_info/cdat_info.py.in

Lines changed: 222 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,222 @@
1+
Version = 'GIT_DESCRIBE'
2+
ping_checked = False
3+
check_in_progress = False
4+
5+
6+
def version():
7+
sp = Version.split("-")
8+
vnm = "-".join(sp[:-2])
9+
vlist = vnm.split(".") + sp[-2:]
10+
return vlist
11+
12+
13+
def get_drs_dirs():
14+
return [os.path.join(sys.prefix, "lib")]
15+
16+
17+
def get_drs_libs():
18+
return ['drsfortran', 'gfortran']
19+
20+
21+
sleep = 60 # minutes (int required)
22+
23+
actions_sent = {}
24+
25+
SOURCE = 'CDAT'
26+
27+
28+
def get_version():
29+
return Version
30+
31+
32+
def get_prefix():
33+
import sys
34+
return sys.prefix
35+
36+
37+
def get_sampledata_path():
38+
import os
39+
try:
40+
return os.path.join(os.environ["UVCDAT_SETUP_PATH"],
41+
"share", "uvcdat", "sample_data")
42+
except KeyError:
43+
raise RuntimeError(
44+
"UVCDAT environment not configured. Please source the setup_runtime script.")
45+
46+
47+
def runCheck():
48+
import cdat_info
49+
import os
50+
if cdat_info.ping_checked is False:
51+
check_in_progress = True
52+
val = None
53+
envanom = os.environ.get("UVCDAT_ANONYMOUS_LOG", None)
54+
if envanom is not None:
55+
if envanom.lower() in ['true', 'yes', 'y', 'ok']:
56+
val = True
57+
elif envanom.lower() in ['false', 'no', 'n', 'not']:
58+
val = False
59+
else:
60+
import warnings
61+
warnings.warn(
62+
"UVCDAT logging environment variable UVCDAT_ANONYMOUS_LOG should be set to 'True' or 'False', you have it set to '%s', will be ignored" %
63+
envanom)
64+
if val is None: # No env variable looking in .uvcdat
65+
fanom = os.path.join(
66+
os.path.expanduser("~"),
67+
".uvcdat",
68+
".anonymouslog")
69+
if os.path.exists(fanom):
70+
f = open(fanom)
71+
for l in f.readlines():
72+
sp = l.strip().split("UVCDAT_ANONYMOUS_LOG:")
73+
if len(sp) > 1:
74+
try:
75+
val = eval(sp[1])
76+
except:
77+
pass
78+
f.close()
79+
80+
reload(cdat_info)
81+
return val
82+
83+
84+
def askAnonymous(val):
85+
import cdat_info
86+
import os
87+
while cdat_info.ping_checked is False and not val in [
88+
True, False]: # couldn't get a valid value from env or file
89+
val2 = raw_input(
90+
"Allow anonymous logging usage to help improve UV-CDAT? (you can also set the environment variable UVCDAT_ANONYMOUS_LOG to yes or no) [yes/no]")
91+
if val2.lower() in ['y', 'yes', 'ok']:
92+
val = True
93+
elif val2.lower() in ['n', 'no', 'not']:
94+
val = False
95+
if val in [True, False]: # store result for next time
96+
try:
97+
fanom = os.path.join(
98+
os.path.expanduser("~"), ".uvcdat", ".anonymouslog")
99+
if not os.path.exists(os.path.join(
100+
os.path.expanduser("~"), ".uvcdat")):
101+
os.makedirs(
102+
os.path.join(
103+
os.path.expanduser("~"),
104+
".uvcdat"))
105+
f = open(fanom, "w")
106+
print >>f, "#Store information about allowing UVCDAT anonymous logging"
107+
print >>f, "# Need sto be True or False"
108+
print >>f, "UVCDAT_ANONYMOUS_LOG: %s" % val
109+
f.close()
110+
except Exception as err:
111+
pass
112+
else:
113+
if cdat_info.ping_checked:
114+
val = cdat_info.ping
115+
cdat_info.ping = val
116+
cdat_info.ping_checked = True
117+
check_in_progress = False
118+
119+
120+
def pingPCMDIdb(*args, **kargs):
121+
import cdat_info
122+
import os
123+
while cdat_info.check_in_progress:
124+
reload(cdat_info)
125+
val = cdat_info.runCheck()
126+
if val is False:
127+
cdat_info.ping_checked = True
128+
cdat_info.ping = False
129+
return
130+
try:
131+
if not cdat_info.ping:
132+
return
133+
except:
134+
pass
135+
cdat_info.askAnonymous(val)
136+
import threading
137+
kargs['target'] = pingPCMDIdbThread
138+
kargs['args'] = args
139+
t = threading.Thread(**kargs)
140+
t.start()
141+
142+
143+
def pingPCMDIdbThread(*args, **kargs):
144+
import threading
145+
kargs['target'] = submitPing
146+
kargs['args'] = args
147+
t = threading.Thread(**kargs)
148+
t.start()
149+
import time
150+
time.sleep(5) # Lets wait 5 seconds top for this ping to work
151+
if t.isAlive():
152+
try:
153+
t._Thread__stop()
154+
except:
155+
pass
156+
157+
158+
def submitPing(source, action, source_version=None):
159+
try:
160+
import urllib2
161+
import sys
162+
import os
163+
import cdat_info
164+
import hashlib
165+
import urllib
166+
if source in ['cdat', 'auto', None]:
167+
source = cdat_info.SOURCE
168+
if cdat_info.ping:
169+
if not source in actions_sent.keys():
170+
actions_sent[source] = []
171+
elif action in actions_sent[source]:
172+
return
173+
else:
174+
actions_sent[source].append(action)
175+
data = {}
176+
uname = os.uname()
177+
data['platform'] = uname[0]
178+
data['platform_version'] = uname[2]
179+
data['hashed_hostname'] = hashlib.sha1(uname[1]).hexdigest()
180+
data['source'] = source
181+
if source_version is None:
182+
data['source_version'] = cdat_info.get_version()
183+
else:
184+
data['source_version'] = source_version
185+
data['action'] = action
186+
data['sleep'] = cdat_info.sleep
187+
data['hashed_username'] = hashlib.sha1(os.getlogin()).hexdigest()
188+
urllib2.urlopen(
189+
'http://uv-cdat.llnl.gov/UVCDATUsage/log/add/',
190+
urllib.urlencode(data))
191+
except Exception as err:
192+
pass
193+
194+
import os
195+
import sys
196+
os.environ["UVCDAT_SETUP_PATH"] = sys.prefix
197+
CDMS_INCLUDE_DAP = 'yes'
198+
CDMS_DAP_DIR = '.'
199+
CDMS_HDF_DIR = '.'
200+
CDMS_GRIB2LIB_DIR = sys.prefix
201+
CDMS_INCLUDE_GRIB2LIB = 'yes'
202+
CDMS_INCLUDE_DRS = 'no'
203+
CDMS_INCLUDE_HDF = 'no'
204+
CDMS_INCLUDE_PP = 'yes'
205+
CDMS_INCLUDE_QL = 'no'
206+
drs_file = os.path.join(sys.prefix, 'lib', 'libdrs.a')
207+
netcdf_directory = sys.prefix
208+
netcdf_include_directory = sys.prefix + '/include'
209+
cdunif_include_directories = [
210+
sys.prefix + '/include/cdms'] + [
211+
sys.prefix + '/include',
212+
sys.prefix + '/lib/libffi-3.1/include',
213+
'/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.11.sdk/usr/include',
214+
'/usr/X11R6/include'] + []
215+
cdunif_library_directories = [sys.prefix + '/lib'] + get_drs_dirs(
216+
) + [sys.prefix + '/lib'] + ["/usr/X11/lib", "/usr/X11R6/lib"]
217+
cdunif_libraries = ['cdms', 'netcdf'] + ['netcdf'] + \
218+
get_drs_libs() + [] + ['grib2c', 'png', 'jasper']
219+
x11include = ['/usr/X11R6/include', '/usr/include', '/opt/include']
220+
x11libdir = ['/usr/X11R6/lib', '/usr/lib', '/opt/lib']
221+
mathlibs = ['m']
222+
externals = sys.prefix

Packages/cdat_info/setup.py

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
#!/usr/bin/env python
2+
from distutils.core import setup
3+
import subprocess
4+
import os
5+
import tempfile
6+
import shutil
7+
import sys
8+
9+
src_dir = os.path.dirname(os.path.realpath(__file__))
10+
11+
os.chdir(src_dir)
12+
GIT_DESCRIBE = subprocess.Popen(["git","describe","--tag"],stdout=subprocess.PIPE).stdout.read().strip()
13+
14+
tmp_dir = os.path.join(tempfile.gettempdir(),"cdat_info_build")
15+
shutil.rmtree(tmp_dir,ignore_errors=True)
16+
os.makedirs(tmp_dir)
17+
os.chdir(tmp_dir)
18+
lib_dir = os.path.join(tmp_dir,"cdat_info_Lib")
19+
shutil.copytree(os.path.join(src_dir,"Lib"),lib_dir)
20+
21+
22+
23+
f=open(os.path.join(src_dir,"cdat_info.py.in"))
24+
cdat_info = f.read().replace("GIT_DESCRIBE",GIT_DESCRIBE)
25+
f.close()
26+
f=open(os.path.join(lib_dir,"cdat_info.py"),"w")
27+
f.write(cdat_info)
28+
f.close()
29+
30+
setup (name = "cdat_info",
31+
packages = ['cdat_info'],
32+
package_dir = {'cdat_info': lib_dir},
33+
)
34+
shutil.rmtree(lib_dir,ignore_errors=True)

0 commit comments

Comments
 (0)