1
+ #!/usr/bin/env python3
2
+
1
3
from collections import defaultdict
2
4
import re
3
5
import sys
4
6
import os
5
7
import fnmatch
8
+ import argparse
6
9
7
10
"""
8
11
This is relatively rudimentary, but works for the purpose intended
34
37
35
38
"""
36
39
37
- pyflintlibdir = "/Users/davideinstein/projects/python-flint/src/flint/flintlib"
38
- arbdocdir = "/Users/davideinstein/projects/arb/doc/source"
39
- flintdocdir = "/Users/davideinstein/projects/flint2/doc/source"
40
-
41
40
# recognize a function definition in rst
42
41
is_func = re .compile (r"\.\.( )+(c:)?function( )*::" )
43
42
# rename types to avoid python -- c name collisions
@@ -64,7 +63,7 @@ def get_cython_struct_types(file):
64
63
ret .append (l .split ()[- 1 ])
65
64
return ret
66
65
67
- def fill_import_dict ():
66
+ def fill_import_dict (pyflintlibdir ):
68
67
"""
69
68
Get a map from cython structs to the pxd that defines them
70
69
"""
@@ -138,13 +137,13 @@ def gen_imports(function_list):
138
137
print ("from flint.flintlib." + k + " cimport " + types )
139
138
return ret
140
139
141
- def generate_pxd_file (h_name ):
142
- fill_import_dict ()
140
+ def generate_pxd_file (h_name , opts ):
141
+ fill_import_dict (opts . flint_lib_dir )
143
142
l = []
144
- docdir = arbdocdir
143
+ docdir = opts . arb_doc_dir
145
144
name = h_name
146
145
if name [:6 ] == "flint/" :
147
- docdir = flintdocdir
146
+ docdir = opts . flint_doc_dir
148
147
name = name [6 :]
149
148
with open (os .path .join (docdir , name + ".rst" )) as f :
150
149
l = get_functions (f )
@@ -159,7 +158,27 @@ def generate_pxd_file(h_name):
159
158
else :
160
159
print (" " + f )
161
160
161
+
162
+ def main (* args ):
163
+ usage = """
164
+ $ cd /path/to/python-flint
165
+ $ bin/rst_to_pxd.py flint/fmpz --flint-doc-dir=/path/to/flint/doc/source
166
+ """
167
+ parser = argparse .ArgumentParser (description = 'Generate a pxd file from an rst file' ,
168
+ usage = usage )
169
+ parser .add_argument ('--flint-lib-dir' , help = 'location of the flintlib submodule' ,
170
+ default = "./src/flint/flintlib" )
171
+ parser .add_argument ('--arb-doc-dir' , help = 'location of the arb doc source directory' ,
172
+ default = "/Users/davideinstein/projects/arb/doc/source" )
173
+ parser .add_argument ('--flint-doc-dir' , help = 'location of the flint doc source directory' ,
174
+ default = "/Users/davideinstein/projects/flint2/doc/source" )
175
+ parser .add_argument ('name' , help = 'name of the rst file to parse (e.g. flint/fmpz)' )
176
+
177
+ args = parser .parse_args ()
178
+
179
+ generate_pxd_file (args .name , args )
180
+
181
+
162
182
if __name__ == "__main__" :
183
+ main (* sys .argv [1 :])
163
184
164
- name = sys .argv [1 ]
165
- generate_pxd_file (name )
0 commit comments