-
Notifications
You must be signed in to change notification settings - Fork 3
/
setup.py.in
267 lines (234 loc) · 8.56 KB
/
setup.py.in
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
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
from distutils import log
from distutils.ccompiler import CCompiler, compiler_class, new_compiler
from distutils.command.build import build
from distutils.command.install import install
from distutils.core import Command
import os
import pathlib
import stat
from setuptools import (
Distribution as SetuptoolsDistribution, Extension, find_packages, setup,
)
from setuptools.command.develop import develop as old_develop
class Executable(Extension):
pass
class Distribution(SetuptoolsDistribution):
def __init__(self, attrs=None):
self.executables = attrs.pop('executables', [])
super().__init__(attrs)
# noinspection PyPep8Naming
class build_exe(Command):
description = "build native executables"
user_options = [
('build-temp=', 't',
"directory for temporary files (build by-products)"),
('build-dir=', 'd', "directory for build artificats"),
('force', 'f', "forcibly build everything (ignore file timestamps)"),
('compiler=', 'c', "specify the compiler type"),
]
boolean_options = ['force']
# noinspection PyAttributeOutsideInit
def initialize_options(self):
self.build_temp = None
self.build_dir = None
self.compiler = None
self.force = None
def finalize_options(self):
self.set_undefined_options(
'build',
('build_temp', 'build_temp'),
('build_platlib', 'build_dir'),
('force', 'force'),
('compiler', 'compiler'),
)
def run(self):
comp = new_compiler(
compiler=self.compiler,
verbose=self.verbose,
dry_run=self.dry_run,
force=self.force,
)
extra_preargs = ["-std=c11", "-pipe", "-Wall", "-Wextra", "-Werror"]
cppflags = os.environ.get('CPPFLAGS', '').split()
for flag in cppflags:
if flag.startswith('-D'):
name, _, value = flag[2:].partition('=')
comp.define_macro(name, value if value else None)
else:
extra_preargs.append(flag)
cflags = os.environ.get('CFLAGS', '').split()
extra_preargs.extend(cflags)
comp.define_macro('_XOPEN_SOURCE', '700')
comp.define_macro("_GNU_SOURCE", None)
objs = comp.compile(
["src/hades/bin/hades-dhcp-script.c"],
output_dir=self.build_temp, extra_preargs=extra_preargs,
)
ldflags = os.environ.get('LDFLAGS', '').split()
comp.link_executable(objs, os.path.join(self.build_dir, "hades-dhcp-script"), extra_preargs=ldflags)
build.sub_commands.append(("build_exe", lambda _: True))
# noinspection PyPep8Naming
class install_exe(Command):
description = "install executables"
user_options = [
('install-dir=', 'd', "directory to install executables to"),
('build-dir=', 'b', "build directory (where to install from)"),
('force', 'f', "force installation (overwrite existing files)"),
('skip-build', None, "skip the build steps"),
]
boolean_options = ['force', 'skip-build']
executables = [
'hades-dhcp-script',
]
# noinspection PyAttributeOutsideInit
def initialize_options(self):
self.install_dir = None
self.force = 0
self.build_dir = None
self.skip_build = None
def finalize_options(self):
self.set_undefined_options('build', ('build_platlib', 'build_dir'))
self.set_undefined_options(
'install',
('install_scripts', 'install_dir'),
('force', 'force'),
('skip_build', 'skip_build'),
)
def run(self):
self.mkpath(self.install_dir)
if not self.skip_build:
self.run_command('build_exe')
for executable in self.distribution.executables:
self.copy_file(
os.path.join(self.build_dir, executable.name),
os.path.join(self.install_dir, executable.name),
)
if os.name == 'posix':
# Set the executable bits (owner, group, and world) on
# all the executables we just installed.
for executable in self.distribution.executables:
dest = os.path.join(self.install_dir, executable.name)
if self.dry_run:
log.info("changing mode of %s", dest)
else:
mode = ((os.stat(dest)[stat.ST_MODE]) | 0o555) & 0o7777
log.info("changing mode of %s to %o", dest, mode)
os.chmod(dest, mode)
install.sub_commands.append(("install_exe", lambda _: True))
# noinspection PyPep8Naming
class develop(old_develop):
__doc__ = old_develop.__doc__
# noinspection PyAttributeOutsideInit
def initialize_options(self):
super().initialize_options()
self.build_dir = None
def finalize_options(self):
super().finalize_options()
self.set_undefined_options(
'build',
('build_platlib', 'build_dir'),
)
def install_for_development(self):
# Make sure executables have been built.
self.run_command('build_exe')
super().install_for_development()
for executable in self.distribution.executables:
src = pathlib.PosixPath(self.build_dir, executable.name)
dest = pathlib.PosixPath(self.install_dir, executable.name)
if dest.is_symlink() and dest.readlink() == src:
continue
elif dest.exists():
log.info("Unlinking %s", dest)
if not self.dry_run:
dest.unlink()
self.copy_file(src, dest, link='sym')
setup(name='@PACKAGE_NAME@',
version='@PACKAGE_VERSION@',
author='@PACKAGE_AUTHOR@',
author_email='@PACKAGE_AUTHOR_EMAIL@',
url='@PACKAGE_URL@',
license='@PACKAGE_LICENSE@',
description='@PACKAGE_DESCRIPTION@',
packages=find_packages('src', exclude=["*.tests"]),
package_dir={'': 'src'},
include_package_data=True,
distclass=Distribution,
cmdclass={
'build_exe': build_exe,
'develop': develop,
'install_exe': install_exe,
},
executables=[
Executable(
"hades-dhcp-script",
["src/hades/bin/hades-dhcp-script.c"],
define_macros=[
('_XOPEN_SOURCE', '700'),
("_GNU_SOURCE", None),
],
),
],
zip_safe=False,
python_requires=">=3.9",
install_requires=[
"arpreq",
"Babel",
"celery",
"Flask",
"Flask-Babel",
"Jinja2",
'kombu',
"netaddr",
"psycopg2",
"pydbus",
'PyGObject',
'PyNaCl',
"pyrad",
"pyroute2",
"pysnmp",
"SQLAlchemy",
"systemd-python",
],
extras_require={
'docs': [
'docutils',
'sphinx',
'sphinx_autodoc_typehints',
'sphinxarg.ext',
],
},
tests_require=[
"pytest",
],
entry_points={
'console_scripts': [
'hades-agent = hades.bin.agent:main',
'hades-check-database = hades.bin.check_database:main',
'hades-deputy = hades.bin.deputy:main',
'hades-dhcp-script-standalone = hades.bin.dhcp_script:main',
'hades-export-options = hades.bin.export_options:main',
'hades-generate-config = hades.bin.generate_config:main',
'hades-lease-server = hades.bin.lease_server:main',
'hades-portal = hades.bin.portal:main',
'hades-vrrp-notify = hades.bin.vrrp_notify:main',
],
},
classifiers=[
'Development Status :: 5 - Production/Stable',
'License :: OSI Approved :: MIT License',
'Environment :: No Input/Output (Daemon)',
'Environment :: Web Environment',
'Intended Audience :: System Administrators',
'Intended Audience :: Telecommunications Industry',
'Operating System :: POSIX :: Linux',
'Programming Language :: C'
'Programming Language :: Python :: 3 :: Only',
'Programming Language :: Python :: 3.9',
'Programming Language :: Python :: 3.10',
'Programming Language :: Python :: 3.11',
'Programming Language :: SQL',
'Programming Language :: Unix Shell',
'Topic :: Internet :: WWW/HTTP :: WSGI :: Application',
'Topic :: System :: Networking',
],
)