mirror of
git://soft.sys114.com/WiringPi2-Python
synced 2026-02-04 15:30:35 +09:00
Use swig if available, but package wiringpi_wrap.c in the source dist.
This commit is contained in:
@@ -4,3 +4,5 @@ include LICENSE.txt
|
||||
include bindings.i
|
||||
include constants.py
|
||||
include wiringpi-class.py
|
||||
include wiringpi.i
|
||||
include wiringpi_wrap.c
|
||||
|
||||
30
setup.py
30
setup.py
@@ -1,12 +1,27 @@
|
||||
#!/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 = glob('WiringPi/devLib/*.c')
|
||||
sources += glob('WiringPi/wiringPi/*.c')
|
||||
sources += ['wiringpi.i']
|
||||
# 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)
|
||||
|
||||
try:
|
||||
sources.remove('WiringPi/devLib/piFaceOld.c')
|
||||
@@ -22,12 +37,19 @@ except ValueError:
|
||||
# https://stackoverflow.com/a/29551581/7938656
|
||||
# and
|
||||
# https://blog.niteoweb.com/setuptools-run-custom-code-in-setup-py/
|
||||
class Build_ext_first(build_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',
|
||||
include_dirs=['WiringPi/wiringPi','WiringPi/devLib'],
|
||||
@@ -37,9 +59,9 @@ _wiringpi = Extension(
|
||||
|
||||
setup(
|
||||
name = 'wiringpi',
|
||||
version = '2.44.3',
|
||||
version = '2.44.4',
|
||||
ext_modules = [ _wiringpi ],
|
||||
py_modules = ["wiringpi"],
|
||||
install_requires=[],
|
||||
cmdclass = {'build_py' : Build_ext_first},
|
||||
cmdclass = {'build_py' : build_py_ext_first, 'sdist' : sdist_ext_first},
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user