Skip to content

Commit 5a4f949

Browse files
committed
Formatted code with black
1 parent 85f015e commit 5a4f949

File tree

3 files changed

+34
-16
lines changed

3 files changed

+34
-16
lines changed

python-bindings/overview_article/ctypes_test.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,4 +24,3 @@
2424
c_lib.cmult.restype = ctypes.c_float
2525
answer = c_lib.cmult(x, ctypes.c_float(y))
2626
print(f" In Python: int: {x} float {y:.1f} return val {answer:.1f}")
27-

python-bindings/overview_article/cython_test.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,3 @@
66

77
answer = cython_example.pymult(x, y)
88
print(f" In Python: int: {x} float {y:.1f} return val {answer:.1f}")
9-

python-bindings/overview_article/tasks.py

Lines changed: 34 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,19 @@
55
import os
66
import pathlib
77

8+
89
@invoke.task
910
def 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+
1416
def print_banner(msg):
1517
print("==================================================")
1618
print("= {} ".format(msg))
1719

20+
1821
@invoke.task
1922
def 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)
3438
def 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()
6167
def test_cffi(c):
6268
""" Run the script to test CFFI """
@@ -73,14 +79,17 @@ def build_cppmult(c):
7379
)
7480
print("* Complete")
7581

82+
7683
def 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)
8695
def 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()
93103
def 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()
111122
def 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+
)
118139
def all(c):
119140
""" Build and run all tests """
120141
pass
121-

0 commit comments

Comments
 (0)