Merge lp:~spud/spud/pythonbindingbug into lp:spud

Proposed by Cian Wilson
Status: Merged
Approved by: Patrick Farrell
Approved revision: 419
Merged at revision: 420
Proposed branch: lp:~spud/spud/pythonbindingbug
Merge into: lp:spud
Diff against target: 265 lines (+63/-53)
2 files modified
python/libspud.py.in (+62/-52)
python/test_ctypes.py (+1/-1)
To merge this branch: bzr merge lp:~spud/spud/pythonbindingbug
Reviewer Review Type Date Requested Status
Spud developers Pending
Review via email: mp+68331@code.launchpad.net

Description of the change

These changes should bring the python bindings back into line with the rest of spud.

All the python tests in test_ctypes.py work again now (don't know if they cover all interfaces but I did try to update them all).

To post a comment you must log in.
Revision history for this message
Patrick Farrell (pefarrell) wrote :

Looks good.

I can't believe I didn't request David do it when he proposed merging the recent spud changes ... !

Revision history for this message
Cian Wilson (cwilson) wrote :

For some reason this started failing for me last night. I guess I updated wherever I was picking up libspud.py from (I think my co of the fluidity trunk) but it's always been a bit mysterious to me which version I'm actually using.

None of the fluidity short or medium tests (I only grepped for 'import libspud') seem to depend on this, which I could rectify but I'm not sure where buildbot would pick up its version of libspud.py (and dependency on libspud-dev) from.

Saw you had a suggestion of packaging the python interface. Would doing this improve this situation?

Revision history for this message
Patrick Farrell (pefarrell) wrote :

You can find out where your python interpreter is getting it with

$ python -v -c "import libspud" 2>&1 | grep "import libspud"
import libspud # precompiled from /home/pef/fluidity/adjoint/python/libspud.pyc

Yes, I think someone should package the python bindings. There's a nice example in the libadjoint source tree, if anyone cares ;-)

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'python/libspud.py.in'
2--- python/libspud.py.in 2011-07-06 05:47:12 +0000
3+++ python/libspud.py.in 2011-07-19 05:52:17 +0000
4@@ -59,106 +59,116 @@
5
6 libspud = cdll.LoadLibrary('@prefix@' + '/lib/libspud.so')
7
8-cclear_options = libspud.cspud_clear_options_
9+cclear_options = libspud.spud_clear_options
10 cclear_options.argtypes = []
11 cclear_options.restype = None
12
13 def clear_options():
14 cclear_options()
15
16-cload_options = libspud.cspud_load_options_
17-cload_options.argtypes = [c_char_p, POINTER(c_int)]
18-cload_options.restype = None
19+cload_options = libspud.spud_load_options
20+cload_options.argtypes = [c_char_p, c_int]
21+cload_options.restype = c_int
22
23 def load_options(s):
24- cload_options(s, byref(c_int(len(s))))
25+ out = cload_options(s, c_int(len(s)))
26+ if out != SPUD_NO_ERROR:
27+ raise spud_exceptions[out]
28
29-cwrite_options = libspud.cspud_write_options_
30-cwrite_options.argtypes = [c_char_p, POINTER(c_int)]
31-cwrite_options.restype = None
32+cwrite_options = libspud.spud_write_options
33+cwrite_options.argtypes = [c_char_p, c_int]
34+cwrite_options.restype = c_int
35
36 def write_options(filename):
37- cwrite_options(filename, byref(c_int(len(filename))))
38+ out = cwrite_options(filename, c_int(len(filename)))
39+ if out != SPUD_NO_ERROR:
40+ raise spud_exceptions[out]
41
42-cget_child_name = libspud.cspud_get_child_name_
43-cget_child_name.argtypes = [c_char_p, POINTER(c_int), POINTER(c_int), c_char_p, POINTER(c_int)]
44+cget_child_name = libspud.spud_get_child_name
45+cget_child_name.argtypes = [c_char_p, c_int, c_int, c_char_p, c_int]
46 cget_child_name.restype = c_int
47
48 def get_child_name(s, idx):
49 val = create_string_buffer(OPTION_PATH_LEN)
50- out = cget_child_name(s, byref(c_int(len(s))), byref(c_int(idx)), val, byref(c_int(len(val))))
51+ out = cget_child_name(s, c_int(len(s)), c_int(idx), val, c_int(len(val)))
52
53 if out != SPUD_NO_ERROR:
54 raise spud_exceptions[out]
55
56 return val.value.strip()
57
58-cnumber_of_children = libspud.cspud_number_of_children_
59-cnumber_of_children.argtypes = [c_char_p, POINTER(c_int)]
60-cnumber_of_children.restype = c_int
61+cget_number_of_children = libspud.spud_get_number_of_children
62+cget_number_of_children.argtypes = [c_char_p, c_int, POINTER(c_int)]
63+cget_number_of_children.restype = c_int
64
65-def number_of_children(s):
66- return cnumber_of_children(s, byref(c_int(len(s))))
67+def get_number_of_children(s):
68+ val = c_int()
69+ out = cget_number_of_children(s, c_int(len(s)), byref(val))
70+
71+ if out != SPUD_NO_ERROR:
72+ raise spud_exceptions[out]
73+
74+ return val.value
75
76-coption_count = libspud.cspud_option_count_
77-coption_count.argtypes = [c_char_p, POINTER(c_int)]
78+coption_count = libspud.spud_option_count
79+coption_count.argtypes = [c_char_p, c_int]
80 coption_count.restype = c_int
81
82 def option_count(s):
83- return coption_count(s, byref(c_int(len(s))))
84+ return coption_count(s, c_int(len(s)))
85
86-chave_option = libspud.cspud_have_option_
87-chave_option.argtypes = [c_char_p, POINTER(c_int)]
88+chave_option = libspud.spud_have_option
89+chave_option.argtypes = [c_char_p, c_int]
90 chave_option.restype = c_int
91
92 def have_option(s):
93- out = chave_option(s, byref(c_int(len(s))))
94+ out = chave_option(s, c_int(len(s)))
95
96 if out == 1:
97 return True
98 else:
99 return False
100
101-cget_option_type = libspud.cspud_get_option_type_
102-cget_option_type.argtypes = [c_char_p, POINTER(c_int), POINTER(c_int)]
103+cget_option_type = libspud.spud_get_option_type
104+cget_option_type.argtypes = [c_char_p, c_int, POINTER(c_int)]
105 cget_option_type.restype = c_int
106
107 def get_option_type(s):
108 val = c_int()
109- out = cget_option_type(s, byref(c_int(len(s))), byref(val))
110+ out = cget_option_type(s, c_int(len(s)), byref(val))
111
112 if out != SPUD_NO_ERROR:
113 raise spud_exceptions[out]
114
115 return pytype_map[val.value]
116
117-cget_option_rank = libspud.cspud_get_option_rank_
118-cget_option_rank.argtypes = [c_char_p, POINTER(c_int), POINTER(c_int)]
119+cget_option_rank = libspud.spud_get_option_rank
120+cget_option_rank.argtypes = [c_char_p, c_int, POINTER(c_int)]
121 cget_option_rank.restype = c_int
122
123 def get_option_rank(s):
124 rank = c_int()
125- out = cget_option_rank(s, byref(c_int(len(s))), byref(rank))
126+ out = cget_option_rank(s, c_int(len(s)), byref(rank))
127 if out != SPUD_NO_ERROR:
128 raise spud_exceptions[out]
129 return rank.value
130
131-cget_option_shape = libspud.cspud_get_option_shape_
132-cget_option_shape.argtypes = [c_char_p, POINTER(c_int), POINTER(c_int)]
133+cget_option_shape = libspud.spud_get_option_shape
134+cget_option_shape.argtypes = [c_char_p, c_int, POINTER(c_int)]
135 cget_option_shape.restype = int
136
137 def get_option_shape(s):
138 shape_type = c_int * 2
139 shape = shape_type()
140- out = cget_option_shape(s, byref(c_int(len(s))), shape)
141+ out = cget_option_shape(s, c_int(len(s)), shape)
142
143 if out != SPUD_NO_ERROR:
144 raise spud_exceptions[out]
145
146 return tuple(shape)
147
148-cget_option = libspud.cspud_get_option_
149-cget_option.argtypes = [c_char_p, POINTER(c_int), c_void_p]
150+cget_option = libspud.spud_get_option
151+cget_option.argtypes = [c_char_p, c_int, c_void_p]
152 cget_option.restype = c_int
153
154 def get_option(s):
155@@ -177,7 +187,7 @@
156 for i in range(rank-1, -1, -1): val_type = val_type*shape[i]
157 val = val_type()
158
159- out = cget_option(s, byref(c_int(len(s))), byref(val))
160+ out = cget_option(s, c_int(len(s)), byref(val))
161 if out != SPUD_NO_ERROR:
162 raise spud_exceptions[out]
163
164@@ -189,20 +199,20 @@
165 val_out = val.value
166 return val_out
167
168-cadd_option = libspud.cspud_add_option_
169-cadd_option.argtypes = [c_char_p, POINTER(c_int)]
170+cadd_option = libspud.spud_add_option
171+cadd_option.argtypes = [c_char_p, c_int]
172 cadd_option.restype = c_int
173
174 def add_option(s):
175- out = cadd_option(s, byref(c_int(len(s))))
176+ out = cadd_option(s, c_int(len(s)))
177
178 if out != SPUD_NO_ERROR:
179 raise spud_exceptions[out]
180
181 return
182
183-cset_option = libspud.cspud_set_option_
184-cset_option.argtypes = [c_char_p, POINTER(c_int), c_void_p, POINTER(c_int), POINTER(c_int), POINTER(c_int)]
185+cset_option = libspud.spud_set_option
186+cset_option.argtypes = [c_char_p, c_int, c_void_p, c_int, c_int, POINTER(c_int)]
187 cset_option.restype = c_int
188
189 def set_option(s, val):
190@@ -246,50 +256,50 @@
191 if py_type is str:
192 shape = shape_type(len(val), -1)
193 rank = 1
194- out = cset_option(s, byref(c_int(len(s))), (c_val), byref(c_int(spud_code)), byref(c_int(rank)), shape)
195+ out = cset_option(s, c_int(len(s)), (c_val), c_int(spud_code), c_int(rank), shape)
196 else:
197- out = cset_option(s, byref(c_int(len(s))), byref(c_val), byref(c_int(spud_code)), byref(c_int(rank)), shape)
198+ out = cset_option(s, c_int(len(s)), byref(c_val), c_int(spud_code), c_int(rank), shape)
199
200 if out != SPUD_NO_ERROR:
201 raise spud_exceptions[out]
202
203-cset_option_attribute = libspud.cspud_set_option_attribute_
204-cset_option_attribute.argtypes = [c_char_p, POINTER(c_int), c_char_p, POINTER(c_int)]
205+cset_option_attribute = libspud.spud_set_option_attribute
206+cset_option_attribute.argtypes = [c_char_p, c_int, c_char_p, c_int]
207 cset_option_attribute.restype = c_int
208
209 def set_option_attribute(s, val):
210- out = cset_option_attribute(s, byref(c_int(len(s))), val, byref(c_int(len(val))))
211+ out = cset_option_attribute(s, c_int(len(s)), val, c_int(len(val)))
212
213 if out != SPUD_NO_ERROR:
214 raise spud_exceptions[out]
215
216 return
217
218-cdelete_option = libspud.cspud_delete_option_
219-cdelete_option.argtypes = [c_char_p, POINTER(c_int)]
220+cdelete_option = libspud.spud_delete_option
221+cdelete_option.argtypes = [c_char_p, c_int]
222 cdelete_option.restype = c_int
223
224 def delete_option(s):
225- out = cdelete_option(s, byref(c_int(len(s))))
226+ out = cdelete_option(s, c_int(len(s)))
227
228 if out != SPUD_NO_ERROR:
229 raise spud_exceptions[out]
230
231 return
232
233-cmove_option = libspud.cspud_move_option_
234-cmove_option.argtypes = [c_char_p, POINTER(c_int), c_char_p, POINTER(c_int)]
235+cmove_option = libspud.spud_move_option
236+cmove_option.argtypes = [c_char_p, c_int, c_char_p, c_int]
237 cmove_option.restype = c_int
238
239 def move_option(s1, s2):
240- out = cmove_option(s1, byref(c_int(len(s1))), s2, byref(c_int(len(s2))))
241+ out = cmove_option(s1, c_int(len(s1)), s2, c_int(len(s2)))
242
243 if out != SPUD_NO_ERROR:
244 raise spud_exceptions[out]
245
246 return
247
248-cprint_options = libspud.cspud_print_options_
249+cprint_options = libspud.spud_print_options
250 cprint_options.restype = None
251 cprint_options.argtypes = []
252
253
254=== modified file 'python/test_ctypes.py'
255--- python/test_ctypes.py 2011-07-06 05:35:39 +0000
256+++ python/test_ctypes.py 2011-07-19 05:52:17 +0000
257@@ -5,7 +5,7 @@
258
259 libspud.print_options()
260
261-print libspud.number_of_children('/geometry')
262+print libspud.get_number_of_children('/geometry')
263 print libspud.get_child_name('geometry', 0)
264
265 print libspud.option_count('/problem_type')

Subscribers

People subscribed via source and target branches