-
Notifications
You must be signed in to change notification settings - Fork 1.1k
/
Copy pathdecorators.py
72 lines (51 loc) · 1.84 KB
/
decorators.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
import re
import warnings
from numba.core import typing, sigutils
from numba.pycc.compiler import ExportEntry
# Registry is okay to be a global because we are using pycc as a standalone
# commandline tool.
export_registry = []
def export(prototype):
warnings.warn("export() is deprecated, use the numba.pycc.CC API instead",
DeprecationWarning, stacklevel=2)
sym, sig = parse_prototype(prototype)
def wrappped(func):
fn_argtys, fn_retty = sigutils.normalize_signature(sig)
signature = typing.signature(fn_retty, *fn_argtys)
entry = ExportEntry(symbol=sym, signature=signature, function=func)
export_registry.append(entry)
return wrappped
def exportmany(prototypes):
warnings.warn("exportmany() is deprecated, use the numba.pycc.CC API instead",
DeprecationWarning, stacklevel=2)
def wrapped(func):
for proto in prototypes:
export(proto)(func)
return wrapped
def process_input_files(inputs):
"""
Read input source files for execution of legacy @export / @exportmany
decorators.
"""
for ifile in inputs:
with open(ifile) as fin:
exec(compile(fin.read(), ifile, 'exec'))
def clear_export_registry():
export_registry[:] = []
# --------------------------------- Internal ---------------------------------
re_symbol = re.compile(r'[_a-z][_a-z0-9]*', re.I)
def parse_prototype(text):
"""Separate the symbol and function-type in a a string with
"symbol function-type" (e.g. "mult float(float, float)")
Returns
---------
(symbol_string, functype_string)
"""
m = re_symbol.match(text)
if not m:
raise ValueError("Invalid function name for export prototype")
s = m.start(0)
e = m.end(0)
symbol = text[s:e]
functype = text[e + 1:]
return symbol, functype