forked from diffpy/diffpy.srreal
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsetup.py
executable file
·166 lines (142 loc) · 5.53 KB
/
setup.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
162
163
164
165
166
#!/usr/bin/env python
# Installation script for diffpy.srreal
"""diffpy.srreal - calculators for PDF, bond valence sum, and other
quantities based on atom pair interaction.
Packages: diffpy.srreal
"""
import os
import glob
from setuptools import setup, find_packages
from setuptools import Extension
from numpy.distutils.misc_util import get_numpy_include_dirs
# define extension arguments here
ext_kws = {
'libraries' : ['diffpy'],
'extra_compile_args' : [],
'extra_link_args' : [],
'include_dirs' : get_numpy_include_dirs(),
}
# Figure out which boost library to use. This doesn't appear to consult
# LD_LIBRARY_PATH.
def get_boost_libraries():
"""Check for installed boost_python shared library.
Returns list of required boost_python shared libraries that are installed
on the system. If required libraries are not found, an Exception will be
thrown.
"""
baselib = "boost_python"
boostlibtags = ['', '-mt']
from ctypes.util import find_library
for tag in boostlibtags:
lib = baselib + tag
found = find_library(lib)
if found: break
# Raise Exception if we don't find anything
if not found:
raise Exception("Cannot find shared boost_library library")
libs = [lib]
return libs
def create_extensions():
"Initialize Extension objects for the setup function."
blibs = [n for n in get_boost_libraries()
if not n in ext_kws['libraries']]
ext_kws['libraries'] += blibs
ext = Extension('diffpy.srreal.srreal_ext',
glob.glob('srrealmodule/*.cpp'),
**ext_kws)
return [ext]
# Use this version when git data are not available, like in git zip archive.
# Update when tagging a new release.
FALLBACK_VERSION = '1.0.post0'
# versioncfgfile holds version data for git commit hash and date.
# It must reside in the same directory as version.py.
MYDIR = os.path.dirname(os.path.abspath(__file__))
versioncfgfile = os.path.join(MYDIR, 'diffpy/srreal/version.cfg')
gitarchivecfgfile = versioncfgfile.replace('version.cfg', 'gitarchive.cfg')
def gitinfo():
from subprocess import Popen, PIPE
kw = dict(stdout=PIPE, cwd=MYDIR)
proc = Popen(['git', 'describe', '--match=v[[:digit:]]*'], **kw)
desc = proc.stdout.read()
proc = Popen(['git', 'log', '-1', '--format=%H %at %ai'], **kw)
glog = proc.stdout.read()
rv = {}
rv['version'] = '.post'.join(desc.strip().split('-')[:2]).lstrip('v')
rv['commit'], rv['timestamp'], rv['date'] = glog.strip().split(None, 2)
return rv
def getversioncfg():
from ConfigParser import RawConfigParser
vd0 = dict(version=FALLBACK_VERSION, commit='', date='', timestamp=0)
# first fetch data from gitarchivecfgfile, ignore if it is unexpanded
g = vd0.copy()
cp0 = RawConfigParser(vd0)
cp0.read(gitarchivecfgfile)
if '$Format:' not in cp0.get('DEFAULT', 'commit'):
g = cp0.defaults()
# then try to obtain version data from git.
gitdir = os.path.join(MYDIR, '.git')
if os.path.isdir(gitdir) or 'GIT_DIR' in os.environ:
try:
g = gitinfo()
except OSError:
pass
# finally, check and update the active version file
cp = RawConfigParser()
cp.read(versioncfgfile)
d = cp.defaults()
rewrite = not d or (g['commit'] and (
g['version'] != d.get('version') or g['commit'] != d.get('commit')))
if rewrite:
cp.set('DEFAULT', 'version', g['version'])
cp.set('DEFAULT', 'commit', g['commit'])
cp.set('DEFAULT', 'date', g['date'])
cp.set('DEFAULT', 'timestamp', g['timestamp'])
cp.write(open(versioncfgfile, 'w'))
return cp
versiondata = getversioncfg()
# define distribution
setup_args = dict(
name = "diffpy.srreal",
version = versiondata.get('DEFAULT', 'version'),
namespace_packages = ['diffpy'],
packages = find_packages(),
test_suite = 'diffpy.srreal.tests',
include_package_data = True,
ext_modules = [],
install_requires = [
'diffpy.Structure',
],
zip_safe = False,
author = "Simon J.L. Billinge group",
author_email = "[email protected]",
maintainer = "Pavol Juhas",
maintainer_email = "[email protected]",
description = ("calculators for PDF, bond valence sum, and other "
"quantities based on atom pair interaction."),
license = 'BSD-style license',
url = "https://github.com/diffpy/diffpy.srreal/",
keywords = "PDF BVS atom overlap calculator real-space",
classifiers = [
# List of possible values at
# http://pypi.python.org/pypi?:action=list_classifiers
'Development Status :: 5 - Production/Stable',
'Environment :: Console',
'Intended Audience :: Developers',
'Intended Audience :: Education',
'Intended Audience :: Science/Research',
'License :: OSI Approved :: BSD License',
'Operating System :: MacOS :: MacOS X',
'Operating System :: POSIX',
'Operating System :: Unix',
'Programming Language :: C++',
'Programming Language :: Python :: 2.6',
'Programming Language :: Python :: 2.7',
'Topic :: Scientific/Engineering :: Chemistry',
'Topic :: Scientific/Engineering :: Physics',
'Topic :: Software Development :: Libraries',
],
)
if __name__ == '__main__':
setup_args['ext_modules'] = create_extensions()
setup(**setup_args)
# End of file