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
·125 lines (95 loc) · 3.65 KB
/
setup.py
File metadata and controls
executable file
·125 lines (95 loc) · 3.65 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
#!/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__))
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.4.3',
'description': 'Bindings for 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',
'classifiers': classifiers,
'keywords': 'evdev input uinput forcefeedback',
'url': 'https://github.com/gvalkov/python-evdev',
'packages': ['evdev'],
'ext_modules': [input_c, uinput_c, ecodes_c],
'tests_require': ['pytest'],
'zip_safe': True,
'cmdclass': {},
'include_package_data': False,
}
def create_ecodes():
# :todo: expose as a command option
input_header = '/usr/include/linux/input.h'
uinput_header = '/usr/include/linux/uinput.h'
if not all(map(os.path.isfile, (input_header, uinput_header))):
msg = '''\
The linux/input.h and linux/uinput.h header files are
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
headers = (input_header, uinput_header)
print('writing ecodes.c (using %s and %s)' % headers)
cmd = '%s genecodes.py %s > ecodes.c' % (sys.executable, ' '.join(headers))
check_call(cmd, cwd="%s/evdev" % 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)