forked from pypilot/pypilot
-
Notifications
You must be signed in to change notification settings - Fork 0
/
setup.py
152 lines (128 loc) · 5.35 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
#!/usr/bin/env python
#
# Copyright (C) 2021 Sean D'Epagnier
#
# This Program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public
# License as published by the Free Software Foundation; either
# version 3 of the License, or (at your option) any later version.
import sys, time
import os, os.path
if sys.version_info[0] < 3:
print('pypilot requires python version 3. python version is', sys.version)
exit(1)
if os.system('which apt'):
print('system does not support apt, you can try running dependencies script and/or manually install needed packages')
else:
if not os.path.exists('deps'):
import dependencies
try:
from setuptools import setup, Extension
except ImportError:
print('ERROR, requires python setuptools package!')
exit(0)
#from distutils.core import setup, Extension
# because basically, a bug in swig extensions this is a workaround to ensure the python scripts
# are generated before they are scanned
from setuptools.command.install import install
class build_ext_first(install):
def run(self):
self.run_command('build_ext')
return install.run(self)
linebuffer_module = Extension('pypilot/linebuffer/_linebuffer',
sources=['pypilot/linebuffer/linebuffer.cpp', 'pypilot/linebuffer/linebuffer.i'],
extra_compile_args=['-Wno-unused-result'],
swig_opts=['-c++']
)
arduino_servo_module = Extension('pypilot/arduino_servo/_arduino_servo',
sources=['pypilot/arduino_servo/arduino_servo.cpp', 'pypilot/arduino_servo/arduino_servo_eeprom.cpp', 'pypilot/arduino_servo/arduino_servo.i'],
extra_compile_args=['-Wno-unused-result'],
swig_opts=['-c++']
)
ugfx_defs = ['-DWIRINGPI']
try:
import RPi.GPIO
ugfx_libraries=['wiringPi']
except:
try:
import OPi.GPIO
ugfx_libraries=['wiringPi']
except:
print('no RPi.GPIO library for ugfx')
ugfx_libraries=[]
ugfx_defs = []
ugfx_module = Extension('pypilot/hat/ugfx/_ugfx',
sources=['hat/ugfx/ugfx.cpp',
'hat/ugfx/ugfx.i'],
extra_compile_args=['-Wno-unused-result'] + ugfx_defs,
libraries=ugfx_libraries,
swig_opts=['-c++'] + ugfx_defs)
if ugfx_libraries:
spireader_module = Extension('pypilot/hat/spireader/_spireader',
sources=['hat/spireader/spireader.cpp',
'hat/spireader/spireader.i'],
extra_compile_args=['-Wno-unused-result'],
libraries=ugfx_libraries,
swig_opts=['-c++'])
else:
spireader_module = None
os.system('cd hat/locale;./translate.sh')
os.system('cd hat; pybabel compile -d translations')
os.system('cd pypilot/locale;./translate.sh')
os.system('cd web; pybabel compile -d translations')
def find_locales(name, dir = 'locale'):
locale_files = []
for walk in os.walk('./' + name + '/' + dir):
path, dirs, files = walk
path = path[len(name) + 3:]
for file in files:
if file[-3:] == '.mo':
locale_files.append(os.path.join(path, file))
return locale_files
from pypilot import version
packages = ['pypilot', 'pypilot/pilots', 'pypilot/arduino_servo', 'ui', 'hat', 'web', 'pypilot/linebuffer', 'hat/ugfx', 'hat/spireader']
try:
from setuptools import find_packages
packages = find_packages()
except:
pass
# ensure all packages are under pypilot
package_dirs = {}
for package in list(packages):
if not package.startswith('pypilot'):
packages.remove(package)
packages.append('pypilot.'+package)
package_dirs['pypilot.'+package] = package.replace('.', '/')
package_data = {'pypilot': find_locales('pypilot'),
'pypilot.hat': ['font.ttf', 'static/*', 'templates/*'] + find_locales('hat') + find_locales('hat', 'translations'),
'pypilot.ui': ['*.png', '*.mtl', '*.obj'],
'pypilot.web': ['static/*', 'templates/*'] + ['pypilot_web.pot'] + find_locales('web', 'translations')}
ext_modules = [arduino_servo_module, linebuffer_module, ugfx_module]
if spireader_module:
ext_modules.append(spireader_module)
setup (name = 'pypilot',
version = version.strversion,
description = 'pypilot sailboat autopilot',
license = 'GPLv3',
author="Sean D'Epagnier",
url='http://pypilot.org/',
packages=packages,
package_dir=package_dirs,
ext_modules = ext_modules,
package_data=package_data,
cmdclass={'install': build_ext_first},
entry_points={
'console_scripts': [
'pypilot=pypilot.autopilot:main',
'pypilot_boatimu=pypilot.boatimu:main',
'pypilot_servo=pypilot.servo:main',
'pypilot_web=pypilot.web.web:main',
'pypilot_hat=pypilot.hat.hat:main',
'pypilot_control=pypilot.ui.autopilot_control:main',
'pypilot_calibration=pypilot.ui.autopilot_calibration:main',
'pypilot_client=pypilot.client:main',
'pypilot_scope=pypilot.ui.scope_wx:main',
'pypilot_client_wx=pypilot.ui.client_wx:main'
]
}
)