forked from WiringPi/WiringPi-Python
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsetup.py
More file actions
executable file
·60 lines (49 loc) · 1.69 KB
/
Copy pathsetup.py
File metadata and controls
executable file
·60 lines (49 loc) · 1.69 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
#!/usr/bin/env python
import os
import sys
from setuptools import setup, Extension
from setuptools.command.build_py import build_py
from setuptools.command.sdist import sdist
from distutils.spawn import find_executable
from glob import glob
sources = []
# If we have swig, use it. Otherwise, use the pre-generated
# wrapper from the source distribution.
if find_executable('swig'):
sources += ['wiringpi.i']
elif os.path.exists('wiringpi_wrap.c'):
sources += ['wiringpi_wrap.c']
else:
print("Error: Building this module requires either that swig is installed\n"
" (e.g., 'sudo apt install swig') or that wiringpi_wrap.c from the\n"
" source distribution (on pypi) is available.")
sys.exit(1)
# Fix so that build_ext runs before build_py
# Without this, wiringpi.py is generated too late and doesn't
# end up in the distribution when running setup.py bdist or bdist_wheel.
# Based on:
# https://stackoverflow.com/a/29551581/7938656
# and
# https://blog.niteoweb.com/setuptools-run-custom-code-in-setup-py/
class build_py_ext_first(build_py):
def run(self):
self.run_command("build_ext")
return build_py.run(self)
# Make sure wiringpi_wrap.c is available for the source dist, also.
class sdist_ext_first(sdist):
def run(self):
self.run_command("build_ext")
return sdist.run(self)
_wiringpi = Extension(
'_wiringpi',
sources=sources,
libraries=['crypt', 'rt', 'wiringPi', 'wiringPiDev']
)
setup(
name = 'wiringpi',
version = '2.44.4',
ext_modules = [ _wiringpi ],
py_modules = ["wiringpi"],
install_requires=[],
cmdclass = {'build_py' : build_py_ext_first, 'sdist' : sdist_ext_first},
)