forked from liam2/liam2
-
Notifications
You must be signed in to change notification settings - Fork 1
/
setup.py
200 lines (162 loc) · 5.84 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
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
#! /usr/bin/env python
# -*- coding: utf-8 -*-
from __future__ import print_function
import os
import sys
import fnmatch
from os.path import join
from itertools import chain
from setuptools import setup
from setuptools.extension import Extension
from Cython.Distutils import build_ext
import numpy as np
command = sys.argv[1] if len(sys.argv) > 1 else None
build_exe = command == 'build_exe'
if build_exe:
# when building executables, we need to use "build" so that C extensions are
# built too ("build" does both "build_ext" and "build_exe"). We do not use
# build in all cases because we do not want to change the normal "build"
# behavior when not building executables.
sys.argv[1] = "build"
from cx_Freeze import Executable, setup
# ============= #
# generic tools #
# ============= #
def allfiles(pattern, path='.'):
"""
like glob.glob(pattern) but also include files in subdirectories
"""
return (join(dirpath, f)
for dirpath, dirnames, files in os.walk(path)
for f in fnmatch.filter(files, pattern))
def int_version(release_name):
"""
converts a release name to a version string with only dots and integers
:param release_name: the release name to convert
:return: a release name with prerelease tags (beta, rc, ...) stripped.
unrecognised tags are left intact, even if that means returning an invalid
version string
>>> int_version('0.8')
'0.8'
>>> int_version('0.8.1')
'0.8.1'
>>> int_version('0.8alpha1')
'0.7.99701'
>>> int_version('0.8rc2')
'0.7.99902'
>>> int_version('0.8.1a2')
'0.8.0.99702'
>>> int_version('0.8.1beta3')
'0.8.0.99803'
>>> int_version('0.8.1rc1')
'0.8.0.99901'
"""
if 'pre' in release_name:
raise ValueError("'pre' is not supported anymore, use 'alpha' or "
"'beta' instead")
if '-' in release_name:
raise ValueError("- is not supported anymore")
# 'a' needs to be searched for after 'beta'
tags = [('rc', 9), ('c', 9),
('beta', 8), ('b', 8),
('alpha', 7), ('a', 7)]
for tag, num in tags:
pos = release_name.find(tag)
if pos != -1:
head, tail = release_name[:pos], release_name[pos + len(tag):]
assert tail.isdigit()
patch = '.99' + str(num) + tail.rjust(2, '0')
head, middle = head.rsplit('.', 1)
return head + '.' + str(int(middle) - 1) + patch
return release_name
# ============ #
# main options #
# ============ #
options = {}
extra_kwargs = {}
# ============== #
# cython options #
# ============== #
# Add the output directory of cython build_ext to cxfreeze search path so that
# build_exe finds and copies C extensions
class MyBuildExt(build_ext):
def finalize_options(self):
build_ext.finalize_options(self)
if build_exe:
# need to be done in-place, otherwise build_exe_options['path'] will use
# the unmodified version because it is computed before build_ext is
# called
cxfreeze_searchpath.insert(0, self.build_lib)
ext_modules = [Extension("cpartition", ["liam2/cpartition.pyx"],
include_dirs=[np.get_include()]),
Extension("cutils", ["liam2/cutils.pyx"],
include_dirs=[np.get_include()])]
options["build_ext"] = {}
# ================= #
# cx_freeze options #
# ================= #
if build_exe:
def vitables_data_files():
try:
import vitables
except ImportError:
return []
module_path = os.path.dirname(vitables.__file__)
files = chain(allfiles('*.ui', module_path),
allfiles('*.ini', module_path),
allfiles('*', join(module_path, 'icons')))
return [(fname, join('vitables', fname[len(module_path) + 1:]))
for fname in files]
cxfreeze_searchpath = sys.path + ['liam2']
build_exe_options = {
# path to find Python modules (we could have modified sys.path but this
# is a bit cleaner)
"path": cxfreeze_searchpath,
# compress zip archive
"compressed": True,
# optimize pyc files (strip docstrings and asserts)
"optimize": 2,
# strip paths in __file__ attributes
"replace_paths": [("*", "")],
"includes": ["matplotlib.backends.backend_qt4agg"],
"packages": ["vitables.plugins"],
# matplotlib => calendar, distutils, unicodedata
# matplotlib.backends.backend_tkagg => Tkconstants, Tkinter
# Qt .ui file loading (for PyTables) => logging, xml
# ctypes, io are required now
"excludes": [
# linux-specific modules
"_codecs", "_codecs_cn", "_codecs_hk", "_codecs_iso2022", "_codecs_jp",
"_codecs_kr", "_codecs_tw",
# common modules
"Tkconstants", "Tkinter", "scipy", "tcl"
],
'include_files': vitables_data_files(),
}
options["build_exe"] = build_exe_options
extra_kwargs['executables'] = [Executable("liam2/main.py")]
# ========== #
# main stuff #
# ========== #
execfile('./liam2/version.py')
# now we have a `__version__` variable
setup(
name="liam2",
# cx_freeze wants only ints and dots (full version number)
version=int_version(__version__),
description="LIAM2",
cmdclass={"build_ext": MyBuildExt},
ext_modules=ext_modules,
options=options,
install_requires=[
'numexpr',
'numpy >= 1.8',
'tables >= 3',
],
extras_require=dict(
interpolation=['bcolz'],
plot=['matplotlib'],
view=['vitables'],
),
**extra_kwargs
)