Repository navigation
Expand file tree
/
Copy pathsetup.py
More file actions
executable file
·220 lines (170 loc) · 7.45 KB
/
Copy pathsetup.py
File metadata and controls
executable file
·220 lines (170 loc) · 7.45 KB
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
#!/usr/bin/env python
# encoding: utf-8
import os
import sys
import textwrap
from os.path import abspath, dirname, join as pjoin
#-----------------------------------------------------------------------------
try:
from setuptools import setup, Extension, Command
from setuptools.command import build_ext as _build_ext
except ImportError:
from distutils.core import setup, Extension, Command
from distutils.command import build_ext as _build_ext
#-----------------------------------------------------------------------------
here = abspath(dirname(__file__))
#-----------------------------------------------------------------------------
classifiers = [
'Development Status :: 5 - Production/Stable',
'Programming Language :: Python :: 2.7',
'Programming Language :: Python :: 3',
'Programming Language :: Python :: 3.3',
'Programming Language :: Python :: 3.4',
'Programming Language :: Python :: 3.5',
'Programming Language :: Python :: 3.6',
'Operating System :: POSIX :: Linux',
'Intended Audience :: Developers',
'Topic :: Software Development :: Libraries',
'License :: OSI Approved :: BSD License',
'Programming Language :: Python :: Implementation :: CPython',
]
#-----------------------------------------------------------------------------
cflags = ['-std=c99', '-Wno-error=declaration-after-statement']
input_c = Extension('evdev._input', sources=['evdev/input.c'], extra_compile_args=cflags)
uinput_c = Extension('evdev._uinput', sources=['evdev/uinput.c'], extra_compile_args=cflags)
ecodes_c = Extension('evdev._ecodes', sources=['evdev/ecodes.c'], extra_compile_args=cflags)
iprops_c = Extension('evdev.iprops', sources=['evdev/iprops.c'], extra_compile_args=cflags)
#-----------------------------------------------------------------------------
kw = {
'name': 'evdev',
'version': '1.2.0',
'description': 'Bindings to the Linux input handling subsystem',
'long_description': open(pjoin(here, 'README.rst')).read(),
'author': 'Georgi Valkov',
'author_email': '[email protected]',
'license': 'Revised BSD License',
'keywords': 'evdev input uinput',
'url': 'https://github.com/gvalkov/python-evdev',
'classifiers': classifiers,
'packages': ['evdev'],
'ext_modules': [input_c, uinput_c, ecodes_c, iprops_c],
'include_package_data': False,
'zip_safe': True,
'cmdclass': {},
}
#-----------------------------------------------------------------------------
def create_ecodes(headers=None):
if not headers:
headers = [
'/usr/include/linux/input.h',
'/usr/include/linux/input-event-codes.h',
'/usr/include/linux/uinput.h',
]
headers = [header for header in headers if os.path.isfile(header)]
if not headers:
msg = '''\
The 'linux/input.h' and 'linux/input-event-codes.h' include files
are missing. You will have to install the kernel header files in
order to continue:
yum install kernel-headers-$(uname -r)
apt-get install linux-headers-$(uname -r)
emerge sys-kernel/linux-headers
pacman -S kernel-headers
In case they are installed in a non-standard location, you may use
the '--evdev-headers' option to specify one or more colon-separated
paths. For example:
python setup.py \\
build \\
build_ecodes --evdev-headers path/input.h:path/input-event-codes.h \\
build_ext --include-dirs path/ \\
install
'''
sys.stderr.write(textwrap.dedent(msg))
sys.exit(1)
from subprocess import check_call
print('writing ecodes.c (using %s)' % ' '.join(headers))
cmd = '%s genecodes.py %s > ecodes.c' % (sys.executable, ' '.join(headers))
check_call(cmd, cwd="%s/evdev" % here, shell=True)
#-----------------------------------------------------------------------------
def create_iprops(headers=None):
if not headers:
headers = [
'/usr/include/linux/input.h',
'/usr/include/linux/input-event-codes.h',
'/usr/include/linux/uinput.h',
]
headers = [header for header in headers if os.path.isfile(header)]
if not headers:
msg = '''\
The 'linux/input.h' and 'linux/input-event-codes.h' include files
are missing. You will have to install the kernel header files in
order to continue:
yum install kernel-headers-$(uname -r)
apt-get install linux-headers-$(uname -r)
emerge sys-kernel/linux-headers
pacman -S kernel-headers
In case they are installed in a non-standard location, you may use
the '--evdev-headers' option to specify one or more colon-separated
paths. For example:
python setup.py \\
build \\
build_iprops --evdev-headers path/input.h:path/input-event-codes.h \\
build_ext --include-dirs path/ \\
install
'''
sys.stderr.write(textwrap.dedent(msg))
sys.exit(1)
from subprocess import check_call
print('writing iprops.c (using %s)' % ' '.join(headers))
cmd = '%s geniprops.py %s > iprops.c' % (sys.executable, ' '.join(headers))
check_call(cmd, cwd="%s/evdev" % here, shell=True)
#-----------------------------------------------------------------------------
class build_ecodes(Command):
description = 'generate ecodes.c'
user_options = [
('evdev-headers=', None, 'colon-separated paths to input subsystem headers'),
]
def initialize_options(self):
self.evdev_headers = None
def finalize_options(self):
if self.evdev_headers:
self.evdev_headers = self.evdev_headers.split(':')
def run(self):
create_ecodes(self.evdev_headers)
class build_iprops(Command):
description = 'generate iprops.c'
user_options = [
('evdev-headers=', None, 'colon-separated paths to input subsystem headers'),
]
def initialize_options(self):
self.evdev_headers = None
def finalize_options(self):
if self.evdev_headers:
self.evdev_headers = self.evdev_headers.split(':')
def run(self):
create_iprops(self.evdev_headers)
class build_ext(_build_ext.build_ext):
def has_ecodes(self):
ecodes_path = os.path.join(here, 'evdev/ecodes.c')
res = os.path.exists(ecodes_path)
if res:
print('ecodes.c already exists ... skipping build_ecodes')
return not res
def has_iprops(self):
iprops_path = os.path.join(here, 'evdev/iprops.c')
res = os.path.exists(iprops_path)
if res:
print('iprops.c already exists ... skipping build_iprops')
return not res
def run(self):
for cmd_name in self.get_sub_commands():
self.run_command(cmd_name)
_build_ext.build_ext.run(self)
sub_commands = [('build_ecodes', has_ecodes), ('build_iprops', has_iprops)] + _build_ext.build_ext.sub_commands
#-----------------------------------------------------------------------------
kw['cmdclass']['build_ext'] = build_ext
kw['cmdclass']['build_ecodes'] = build_ecodes
kw['cmdclass']['build_iprops'] = build_iprops
#-----------------------------------------------------------------------------
if __name__ == '__main__':
setup(**kw)