MCPcopy
hub / github.com/numpy/numpy / find_functions

Function find_functions

numpy/_core/code_generators/genapi.py:224–312  ·  view source on GitHub ↗

Scan the file, looking for tagged functions. Assuming ``tag=='API'``, a tagged function looks like:: /*API*/ static returntype* function_name(argtype1 arg1, argtype2 arg2) { } where the return type must be on a separate line, the function n

(filename, tag='API')

Source from the content-addressed store, hash-verified

222
223
224def find_functions(filename, tag='API'):
225 """
226 Scan the file, looking for tagged functions.
227
228 Assuming ``tag=='API'``, a tagged function looks like::
229
230 /*API*/
231 static returntype*
232 function_name(argtype1 arg1, argtype2 arg2)
233 {
234 }
235
236 where the return type must be on a separate line, the function
237 name must start the line, and the opening ``{`` must start the line.
238
239 An optional documentation comment in ReST format may follow the tag,
240 as in::
241
242 /*API
243 This function does foo...
244 */
245 """
246 if filename.endswith(('.c.src', '.h.src')):
247 fo = io.StringIO(process_c_file(filename))
248 else:
249 fo = open(filename, 'r')
250 functions = []
251 return_type = None
252 function_name = None
253 function_args = []
254 doclist = []
255 SCANNING, STATE_DOC, STATE_RETTYPE, STATE_NAME, STATE_ARGS = list(range(5))
256 state = SCANNING
257 tagcomment = '/*' + tag
258 for lineno, line in enumerate(fo):
259 try:
260 line = line.strip()
261 if state == SCANNING:
262 if line.startswith(tagcomment):
263 if line.endswith('*/'):
264 state = STATE_RETTYPE
265 else:
266 state = STATE_DOC
267 elif state == STATE_DOC:
268 if line.startswith('*/'):
269 state = STATE_RETTYPE
270 else:
271 line = line.lstrip(' *')
272 doclist.append(line)
273 elif state == STATE_RETTYPE:
274 # first line of declaration with return type
275 m = re.match(r'NPY_NO_EXPORT\s+(.*)$', line)
276 if m:
277 line = m.group(1)
278 return_type = line
279 state = STATE_NAME
280 elif state == STATE_NAME:
281 # second line, with function name

Callers 1

get_api_functionsFunction · 0.85

Calls 11

openFunction · 0.85
ParseErrorClass · 0.85
split_argumentsFunction · 0.85
FunctionClass · 0.85
endswithMethod · 0.80
stripMethod · 0.80
startswithMethod · 0.80
lstripMethod · 0.80
rstripMethod · 0.80
joinMethod · 0.80
closeMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…