8000 Releasing the crackfortran as a general-purpose tool for parsing Fort… · numpy/numpy@ee1036e · GitHub
[go: up one dir, main page]

Skip to content

Commit ee1036e

Browse files
committed
Releasing the crackfortran as a general-purpose tool for parsing Fortran declarations
The `crackfortran` tool is developed to be a backend for the f2py utility. However, crackfortran could also be very useful on its own. The use of crackfortran could be demonstrated by the following example: ```json ► crackfortran symbol.f90 -show Reading fortran codes... Reading file 'symbol.f90' (format:free) Post-processing... Block: symbol Post-processing (stage 2)... [{'args': ['x', 'y', 'symx', 'opt'], 'block': 'subroutine', 'body': [], 'common': {'pltdat': ['model', 'ploter'], 'symbls': ['nsym', 'symbl']}, 'commonvars': ['model', 'ploter', 'nsym', 'symbl'], 'entry': {}, 'externals': [], 'from': 'symbol.f90', 'implicit': None, 'interfaced': [], 'name': 'symbol', 'sortvars': ['model', 'nsym', 'ploter', 'symbl', 'opt', 'x', 'y', 'symx'], 'vars': {'model': {'attrspec': [], 'typespec': 'integer'}, 'nsym': {'attrspec': [], 'typespec': 'integer'}, 'opt': {'typespec': 'integer'}, 'ploter': {'attrspec': [], 'typespec': 'integer'}, 'symbl': {'attrspec': [], 'dimension': ['20', '2'], 'typespec': 'integer'}, 'symx': {'attrspec': [], 'dimension': ['2'], 'typespec': 'integer'}, 'x': {'typespec': 'real'}, 'y': {'typespec': 'real'}}}] ``` The tool presents the subroutine declaration statements as a JSON that can be consumed by other tools for further analysis. Therefore, this patch adds changes required to expose crackfortran as an entry point, next to f2py3.
1 parent 15211ed commit ee1036e

File tree

2 files changed

+17
-1
lines changed

2 files changed

+17
-1
lines changed

numpy/f2py/crackfortran.py

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3691,13 +3691,21 @@ def fix_usage(varname, value):
36913691
post_processing_hooks.append(character_backward_compatibility_hook)
36923692

36933693

3694-
if __name__ == "__main__":
3694+
def main():
3695+
if len(sys.argv) < 2:
3696+
print(__doc__)
3697+
sys.exit(1)
3698+
36953699
files = []
36963700
funcs = []
36973701
f = 1
36983702
f2 = 0
36993703
f3 = 0
3704+
strictf77 = 0
3705+
f77modulename = 0
3706+
skipemptyends = 0
37003707
showblocklist = 0
3708+
pyffilename = None
37013709
for l in sys.argv[1:]:
37023710
if l == '':
37033711
pass
@@ -3757,6 +3765,10 @@ def fix_usage(varname, value):
37573765
statement).
37583766
""", 0)
37593767

3768+
if len(files) == 0:
3769+
print('No input files specified, nothing to do')
3770+
sys.exit(0)
3771+
37603772
postlist = crackfortran(files)
37613773
if pyffilename:
37623774
outmess('Writing fortran code to file %s\n' % repr(pyffilename), 0)
@@ -3765,3 +3777,6 @@ def fix_usage(varname, value):
37653777
f.write(pyf)
37663778
if showblocklist:
37673779
show(postlist)
3780+
3781+
if __name__ == "__main__":
3782+
main()

pyproject.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ classifiers = [
4343

4444
[project.scripts]
4545
f2py = 'numpy.f2py.f2py2e:main'
46+
crackfortran = 'numpy.f2py.crackfortran:main'
4647

4748
[project.entry-points.array_api]
4849
numpy = 'numpy.array_api'

0 commit comments

Comments
 (0)
0