-
Notifications
You must be signed in to change notification settings - Fork 9
/
setup.py
executable file
·192 lines (171 loc) · 6.76 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
#!/usr/bin/env python
"""
Copyright 2015 Brookhaven Science Assoc.
as operator of Brookhaven National Lab.
"""
import sys
import subprocess as sp
from distutils.core import setup, Distribution, Extension, Command, DistutilsSetupError
from distutils.command import build, build_ext, install
from numpy.distutils.misc_util import get_numpy_include_dirs
if sys.version_info<(3,7):
import warnings
warnings.warn("Python < 3.7 is no longer supported")
class GenProtobuf(Command):
"""Run protoc code generator
"""
user_options = [
('protoc=', 'P', "protobuf compiler"),
('build-lib=', 'b',
"directory for compiled extension modules"),
('build-temp=', 't',
"directory for temporary files (build by-products)"),
('inplace', 'i',
"ignore build-lib and put compiled extensions into the source " +
"directory alongside your pure Python modules"),
]
def initialize_options(self):
self.protoc = 'protoc'
self.proto = None
self.build_temp = None
self.build_lib = None
self.inplace = 0
def finalize_options(self):
self.proto = self.distribution.x_proto or ()
self.set_undefined_options('build',
('build_temp', 'build_temp'),
('build_lib', 'build_lib'),
)
self.set_undefined_options('build_ext',
('inplace','inplace'),
)
from os.path import isfile
if self.protoc and not isfile(self.protoc):
from distutils.spawn import find_executable
self.protoc = find_executable(self.protoc)
if not self.protoc:
raise DistutilsSetupError("Unable to find 'protoc'")
def run(self):
outtemp, outlib = self.build_temp, self.build_lib
if self.inplace:
outtemp, outlib = '.', '.'
else:
self.mkpath(outtemp)
self.mkpath(outlib)
for pbd, opts in self.proto:
if opts.get('py', False):
self.spawn([self.protoc, '--python_out='+outlib, pbd])
if opts.get('cpp', False):
self.spawn([self.protoc, '--cpp_out='+outtemp, pbd])
class BuildExtGen(build_ext.build_ext):
"""Extend -I search path to find generated files
"""
def finalize_options(self):
build_ext.build_ext.finalize_options(self)
# Search for generated headers referenced from top level (eg. carchive/backend/...)
if self.inplace:
self.include_dirs.append('.')
else:
self.include_dirs.append(self.build_temp)
class LinkScripts(Command):
"""Symlink or copy scripts
"""
def initialize_options(self):
self.install_dir = None
def finalize_options(self):
self.set_undefined_options('install',
('install_scripts', 'install_dir'))
self.links = self.distribution.x_link_scripts or ()
def run(self):
from os.path import join
for target, dest in self.links:
self.copy_file(target,
join(self.install_dir, dest),
link='sym')
# Allow setup(x_proto=...)
Distribution.x_proto = None
Distribution.x_link_scripts = None
# Hook into build command early.
build.build.sub_commands.insert(0, ('build_protobuf', lambda cmd:True))
# Hook into install command late
install.install.sub_commands.append(('install_links', lambda cmd:True))
# disable warnings from python 2.x API
extra_cflags=[]
extra_ldflags=[]
import platform
if platform.system() == "Linux":
extra_cflags.append('-Wno-write-strings')
if sp.call('which dpkg-buildflags',
stdout=sp.PIPE,
shell=True)==0:
try:
extra_cflags+=sp.check_output('dpkg-buildflags --get CPPFLAGS', shell=True).decode().split()
extra_cflags+=sp.check_output('dpkg-buildflags --get CFLAGS', shell=True).decode().split()
extra_ldflags=sp.check_output('dpkg-buildflags --get LDFLAGS', shell=True).decode().split()
except:
import traceback
traceback.print_exc()
else:
import os
extra_cflags+=['-D_FORTIFY_SOURCE=2']
extra_cflags+=['-g', '-O2', '-fdebug-prefix-map='+os.getcwd()+'=.', '-fstack-protector-strong', '-Wformat', '-Werror=format-security']
extra_ldflags=['-z', 'relro']
setup(
name = "carchivetools",
version = "3.0",
description = "Tools to query EPICS Channel Archiver and Archiver Appliance and export data",
long_description = """Tools to retrieve data from EPICS data archivers.
Supports Channel Archiver as well as Archiver Appliance.
Exports of data to Archiver Appliance and H5 are supported.
""",
url = "https://github.com/epicsdeb/carchivetools",
download_url = "https://github.com/epicsdeb/carchivetools/releases",
author = "Michael Davidsaver",
author_email = "[email protected]",
license = "BSD",
classifiers = [
'Development Status :: 5 - Production/Stable',
'Programming Language :: Python :: 3',
'Programming Language :: Python :: Implementation :: CPython',
'License :: OSI Approved :: BSD License',
'Intended Audience :: Science/Research',
'Topic :: Scientific/Engineering',
],
python_requires='>=3.7',
packages = ['carchive',
'carchive.a2aproxy',
'carchive.a2aproxy.test',
'carchive.archmiddle',
'carchive.cmd',
'carchive.backend',
'carchive.backend.test',
'carchive.backend.pb',
],
package_data={'carchive.backend.test': ['*.pb']},
py_modules = ['twisted.plugins.a2aproxy', 'twisted.plugins.archmiddle'],
scripts = ['arget','arplothdf5'],
ext_modules=[Extension('carchive.backend.pbdecode',
['carchive/backend/pbdecode.cpp',
'carchive/backend/generated.cpp'],
include_dirs=get_numpy_include_dirs() + [
sys.exec_prefix + '/include'], # To be able to see "google/protobuf/port_def.inc"
libraries=['protobuf'],
extra_compile_args=extra_cflags,
extra_link_args=extra_ldflags,
)],
# local extras and replacements
cmdclass={
'build_protobuf':GenProtobuf,
'build_ext':BuildExtGen,
'install_links':LinkScripts,
},
# local options
x_proto = (
('carchive/backend/EPICSEvent.proto', {'cpp':True, 'py':True}),
),
x_link_scripts = (
('arget', 'arinfo'),
('arget', 'argrep'),
('arget', 'arsnap'),
)
)