forked from gvalkov/python-evdev
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsetup.py
executable file
·131 lines (96 loc) · 3.65 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
#!/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.build import build
from setuptools.command.develop import develop
from setuptools.command.bdist_egg import bdist_egg
from setuptools import setup, Extension, Command
here = abspath(dirname(__file__))
requires = ()
test_requires = ('pytest',)
classifiers = (
'Development Status :: 4 - Beta',
# 'Development Status :: 5 - Production/Stable',
'Programming Language :: Python :: 2.7',
'Programming Language :: Python :: 3',
'Programming Language :: Python :: 3.2',
'Programming Language :: Python :: 3.3',
'Operating System :: POSIX :: Linux',
'Intended Audience :: Developers',
'Topic :: Software Development :: Libraries',
'License :: OSI Approved :: BSD License',
'Programming Language :: Python :: Implementation :: CPython',
)
input_c = Extension('evdev._input', sources=['evdev/input.c'], ) # extra_compile_args=['-O0'])
uinput_c = Extension('evdev._uinput', sources=['evdev/uinput.c'], ) # extra_compile_args=['-O0'])
ecodes_c = Extension('evdev._ecodes', sources=['evdev/ecodes.c'], ) # extra_compile_args=['-O0'])
kw = {
'name' : 'evdev',
'version' : '0.3.3',
'description' : 'bindings for the linux input handling subsystem',
'long_description' : open(pjoin(here, 'README.rst')).read(),
'author' : 'Georgi Valkov',
'author_email' : '[email protected]',
'license' : 'New BSD License',
'keywords' : 'evdev input uinput',
'classifiers' : classifiers,
'url' : 'https://github.com/gvalkov/python-evdev',
'packages' : ['evdev'],
'ext_modules' : [input_c, uinput_c, ecodes_c],
'install_requires' : requires,
'tests_require' : test_requires,
'include_package_data' : False,
'zip_safe' : True,
'cmdclass' : {},
}
def create_ecodes():
# :todo: expose as a command option
header = '/usr/include/linux/input.h'
if not os.path.isfile(header):
msg = '''\
The linux/input.h header file is missing. You will have to
install the headers for your kernel in order to continue:
yum install kernel-headers-$(uname -r)
apt-get intall linux-headers-$(uname -r)
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 {})'.format(header))
check_call('bash ./ecodes.sh {} > ecodes.c'.format(header),
cwd='{}/evdev'.format(here),
shell=True)
# :todo: figure out a smarter way to do this
# :note: subclassing build_ext doesn't really cut it
class BuildCommand(build):
def run(self):
create_ecodes()
build.run(self)
class DevelopCommand(develop):
def run(self):
create_ecodes()
develop.run(self)
class BdistEggCommand(bdist_egg):
def run(self):
create_ecodes()
bdist_egg.run(self)
class PyTest(Command):
''' setup.py test -> py.test tests '''
user_options = []
def initialize_options(self):
pass
def finalize_options(self):
pass
def run(self):
from subprocess import call
errno = call(('py.test', 'tests'))
raise SystemExit(errno)
kw['cmdclass']['test'] = PyTest
kw['cmdclass']['build'] = BuildCommand
kw['cmdclass']['develop'] = DevelopCommand
kw['cmdclass']['bdist_egg'] = BdistEggCommand
if __name__ == '__main__':
setup(**kw)