55import os
66import pathlib
77
8+
89@invoke .task
910def clean (c ):
1011 """ Remove any built objects """
11- for pattern in ["*.o" , "*.so" , "cffi_example* cython_wrapper.cpp" , ]:
12+ for pattern in ["*.o" , "*.so" , "cffi_example* cython_wrapper.cpp" ]:
1213 c .run ("rm -rf {}" .format (pattern ))
1314
15+
1416def print_banner (msg ):
1517 print ("==================================================" )
1618 print ("= {} " .format (msg ))
1719
20+
1821@invoke .task
1922def build_cmult (c ):
2023 """ Build the shared library for the sample C code """
@@ -30,6 +33,7 @@ def test_ctypes(c):
3033 print_banner ("Testing ctypes Module" )
3134 invoke .run ("python3 ctypes_test.py" , pty = True )
3235
36+
3337@invoke .task (build_cmult )
3438def build_cffi (c ):
3539 """ Build the CFFI Python bindings """
@@ -41,7 +45,8 @@ def build_cffi(c):
4145 with open (h_file_name ) as h_file :
4246 ffi .cdef (h_file .read ())
4347
44- ffi .set_source ("cffi_example" ,
48+ ffi .set_source (
49+ "cffi_example" ,
4550 # Since we are calling a fully built library directly no custom source
4651 # is necessary. We need to include the .h files, though, because behind
4752 # the scenes cffi generates a .c file which contains a Python-friendly
@@ -50,13 +55,14 @@ def build_cffi(c):
5055 # The important thing is to include the pre-built lib in the list of
5156 # libraries we are linking against:
5257 libraries = ["cmult" ],
53- library_dirs = [this_dir .as_posix (), ],
54- extra_link_args = [' -Wl,-rpath,.' ],
58+ library_dirs = [this_dir .as_posix ()],
59+ extra_link_args = [" -Wl,-rpath,." ],
5560 )
5661
5762 ffi .compile ()
5863 print ("* Complete" )
5964
65+
6066@invoke .task ()
6167def test_cffi (c ):
6268 """ Run the script to test CFFI """
@@ -73,14 +79,17 @@ def build_cppmult(c):
7379 )
7480 print ("* Complete" )
7581
82+
7683def compile_python_module (cpp_name , extension_name ):
77- invoke .run ("g++ -O3 -Wall -Werror -shared -std=c++11 -fPIC "
78- "`python3 -m pybind11 --includes` "
79- "-I /usr/include/python3.7 -I . "
80- "{0} "
81- "-o {1}`python3.7-config --extension-suffix` "
82- "-L. -lcppmult -Wl,-rpath,." .format (cpp_name , extension_name )
83- )
84+ invoke .run (
85+ "g++ -O3 -Wall -Werror -shared -std=c++11 -fPIC "
86+ "`python3 -m pybind11 --includes` "
87+ "-I /usr/include/python3.7 -I . "
88+ "{0} "
89+ "-o {1}`python3.7-config --extension-suffix` "
90+ "-L. -lcppmult -Wl,-rpath,." .format (cpp_name , extension_name )
91+ )
92+
8493
8594@invoke .task (build_cppmult )
8695def build_pybind11 (c ):
@@ -89,6 +98,7 @@ def build_pybind11(c):
8998 compile_python_module ("pybind11_wrapper.cpp" , "pybind11_example" )
9099 print ("* Complete" )
91100
101+
92102@invoke .task ()
93103def test_pybind11 (c ):
94104 """ Run the script to test PyBind11 """
@@ -107,15 +117,25 @@ def build_cython(c):
107117 compile_python_module ("cython_wrapper.cpp" , "cython_example" )
108118 print ("* Complete" )
109119
120+
110121@invoke .task ()
111122def test_cython (c ):
112123 """ Run the script to test Cython """
113124 print_banner ("Testing Cython Module" )
114125 invoke .run ("python3 cython_test.py" , pty = True )
115126
116- @invoke .task (clean , build_cmult , test_ctypes , build_cffi , test_cffi ,
117- build_pybind11 , test_pybind11 , build_cython , test_cython )
127+
128+ @invoke .task (
129+ clean ,
130+ build_cmult ,
131+ test_ctypes ,
132+ build_cffi ,
133+ test_cffi ,
134+ build_pybind11 ,
135+ test_pybind11 ,
136+ build_cython ,
137+ test_cython ,
138+ )
118139def all (c ):
119140 """ Build and run all tests """
120141 pass
121-
0 commit comments