forked from gvalkov/python-evdev
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsetup.py
More file actions
executable file
·111 lines (89 loc) · 3.88 KB
/
setup.py
File metadata and controls
executable file
·111 lines (89 loc) · 3.88 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
#!/usr/bin/env python
# encoding: utf-8
import os
import sys
import textwrap
from os.path import abspath, dirname, join as pjoin
from distutils.command import build
#-----------------------------------------------------------------------------
try:
from setuptools import setup, Extension
from setuptools.command import bdist_egg, develop
except ImportError:
from distutils.core import setup, Extension
from distutils.command import build
develop, bdist_egg = None, None
#-----------------------------------------------------------------------------
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',
'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)
#-----------------------------------------------------------------------------
kw = {
'name': 'evdev',
'version': '0.6.0',
'description': 'Bindings to the Linux input handling subsystem',
'long_description': open(pjoin(here, 'README.rst')).read(),
'author': 'Georgi Valkov',
'author_email': 'georgi.t.valkov@gmail.com',
'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],
'include_package_data': False,
'zip_safe': True,
'cmdclass': {},
}
#-----------------------------------------------------------------------------
def create_ecodes():
headers = [
'/usr/include/linux/input.h',
'/usr/include/linux/input-event-codes.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 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\n\n'''
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 cmdfactory(cmd):
class cls(cmd):
def run(self):
create_ecodes()
cmd.run(self)
return cls
#-----------------------------------------------------------------------------
kw['cmdclass']['build'] = cmdfactory(build.build)
if develop and bdist_egg:
kw['cmdclass']['develop'] = cmdfactory(develop.develop)
kw['cmdclass']['bdist_egg'] = cmdfactory(bdist_egg.bdist_egg)
#-----------------------------------------------------------------------------
if __name__ == '__main__':
setup(**kw)