summaryrefslogtreecommitdiff
path: root/numpy/f2py
diff options
context:
space:
mode:
authorStephan Hoyer <shoyer@google.com>2019-05-13 08:09:26 -0700
committerStephan Hoyer <shoyer@google.com>2019-05-13 08:09:26 -0700
commit07452c86c78a1cf213a764d17f060b4887ec3681 (patch)
tree12c7ae7b14552bd28334277e7e244b603ca4300a /numpy/f2py
parent804f71bb42fef775a85a52366dc4bd1a22c130a8 (diff)
parent4ad33d21b1a30f931e23307e9f9355b70f633bed (diff)
downloadnumpy-07452c86c78a1cf213a764d17f060b4887ec3681.tar.gz
Merge branch 'master' into implement-numpy-implementation
Diffstat (limited to 'numpy/f2py')
-rwxr-xr-xnumpy/f2py/crackfortran.py2
-rwxr-xr-xnumpy/f2py/f2py2e.py8
-rw-r--r--numpy/f2py/rules.py103
3 files changed, 54 insertions, 59 deletions
diff --git a/numpy/f2py/crackfortran.py b/numpy/f2py/crackfortran.py
index 0e9cba1eb..2aaf5d7c6 100755
--- a/numpy/f2py/crackfortran.py
+++ b/numpy/f2py/crackfortran.py
@@ -2512,7 +2512,7 @@ def _eval_scalar(value, params):
value = value.split('_')[0]
try:
value = str(eval(value, {}, params))
- except (NameError, SyntaxError):
+ except (NameError, SyntaxError, TypeError):
return value
except Exception as msg:
errmess('"%s" in evaluating %r '
diff --git a/numpy/f2py/f2py2e.py b/numpy/f2py/f2py2e.py
index 47223151f..110337f92 100755
--- a/numpy/f2py/f2py2e.py
+++ b/numpy/f2py/f2py2e.py
@@ -269,7 +269,8 @@ def scaninputline(inputline):
options["f2py_wrapper_output"] = l
elif f == 1:
try:
- open(l).close()
+ with open(l):
+ pass
files.append(l)
except IOError as detail:
errmess('IOError: %s. Skipping file "%s".\n' %
@@ -333,9 +334,8 @@ def callcrackfortran(files, options):
if options['signsfile'][-6:] == 'stdout':
sys.stdout.write(pyf)
else:
- f = open(options['signsfile'], 'w')
- f.write(pyf)
- f.close()
+ with open(options['signsfile'], 'w') as f:
+ f.write(pyf)
if options["coutput"] is None:
for mod in postlist:
mod["coutput"] = "%smodule.c" % mod["name"]
diff --git a/numpy/f2py/rules.py b/numpy/f2py/rules.py
index 23d36b2c2..6769f1b1f 100644
--- a/numpy/f2py/rules.py
+++ b/numpy/f2py/rules.py
@@ -1257,82 +1257,77 @@ def buildmodule(m, um):
fn = os.path.join(options['buildpath'], vrd['coutput'])
ret['csrc'] = fn
- f = open(fn, 'w')
- f.write(ar['modulebody'].replace('\t', 2 * ' '))
- f.close()
+ with open(fn, 'w') as f:
+ f.write(ar['modulebody'].replace('\t', 2 * ' '))
outmess('\tWrote C/API module "%s" to file "%s"\n' % (m['name'], fn))
if options['dorestdoc']:
fn = os.path.join(
options['buildpath'], vrd['modulename'] + 'module.rest')
- f = open(fn, 'w')
- f.write('.. -*- rest -*-\n')
- f.write('\n'.join(ar['restdoc']))
- f.close()
+ with open(fn, 'w') as f:
+ f.write('.. -*- rest -*-\n')
+ f.write('\n'.join(ar['restdoc']))
outmess('\tReST Documentation is saved to file "%s/%smodule.rest"\n' %
(options['buildpath'], vrd['modulename']))
if options['dolatexdoc']:
fn = os.path.join(
options['buildpath'], vrd['modulename'] + 'module.tex')
ret['ltx'] = fn
- f = open(fn, 'w')
- f.write(
- '%% This file is auto-generated with f2py (version:%s)\n' % (f2py_version))
- if 'shortlatex' not in options:
+ with open(fn, 'w') as f:
f.write(
- '\\documentclass{article}\n\\usepackage{a4wide}\n\\begin{document}\n\\tableofcontents\n\n')
- f.write('\n'.join(ar['latexdoc']))
- if 'shortlatex' not in options:
- f.write('\\end{document}')
- f.close()
+ '%% This file is auto-generated with f2py (version:%s)\n' % (f2py_version))
+ if 'shortlatex' not in options:
+ f.write(
+ '\\documentclass{article}\n\\usepackage{a4wide}\n\\begin{document}\n\\tableofcontents\n\n')
+ f.write('\n'.join(ar['latexdoc']))
+ if 'shortlatex' not in options:
+ f.write('\\end{document}')
outmess('\tDocumentation is saved to file "%s/%smodule.tex"\n' %
(options['buildpath'], vrd['modulename']))
if funcwrappers:
wn = os.path.join(options['buildpath'], vrd['f2py_wrapper_output'])
ret['fsrc'] = wn
- f = open(wn, 'w')
- f.write('C -*- fortran -*-\n')
- f.write(
- 'C This file is autogenerated with f2py (version:%s)\n' % (f2py_version))
- f.write(
- 'C It contains Fortran 77 wrappers to fortran functions.\n')
- lines = []
- for l in ('\n\n'.join(funcwrappers) + '\n').split('\n'):
- if l and l[0] == ' ':
- while len(l) >= 66:
- lines.append(l[:66] + '\n &')
- l = l[66:]
- lines.append(l + '\n')
- else:
- lines.append(l + '\n')
- lines = ''.join(lines).replace('\n &\n', '\n')
- f.write(lines)
- f.close()
+ with open(wn, 'w') as f:
+ f.write('C -*- fortran -*-\n')
+ f.write(
+ 'C This file is autogenerated with f2py (version:%s)\n' % (f2py_version))
+ f.write(
+ 'C It contains Fortran 77 wrappers to fortran functions.\n')
+ lines = []
+ for l in ('\n\n'.join(funcwrappers) + '\n').split('\n'):
+ if l and l[0] == ' ':
+ while len(l) >= 66:
+ lines.append(l[:66] + '\n &')
+ l = l[66:]
+ lines.append(l + '\n')
+ else:
+ lines.append(l + '\n')
+ lines = ''.join(lines).replace('\n &\n', '\n')
+ f.write(lines)
outmess('\tFortran 77 wrappers are saved to "%s"\n' % (wn))
if funcwrappers2:
wn = os.path.join(
options['buildpath'], '%s-f2pywrappers2.f90' % (vrd['modulename']))
ret['fsrc'] = wn
- f = open(wn, 'w')
- f.write('! -*- f90 -*-\n')
- f.write(
- '! This file is autogenerated with f2py (version:%s)\n' % (f2py_version))
- f.write(
- '! It contains Fortran 90 wrappers to fortran functions.\n')
- lines = []
- for l in ('\n\n'.join(funcwrappers2) + '\n').split('\n'):
- if len(l) > 72 and l[0] == ' ':
- lines.append(l[:72] + '&\n &')
- l = l[72:]
- while len(l) > 66:
- lines.append(l[:66] + '&\n &')
- l = l[66:]
- lines.append(l + '\n')
- else:
- lines.append(l + '\n')
- lines = ''.join(lines).replace('\n &\n', '\n')
- f.write(lines)
- f.close()
+ with open(wn, 'w') as f:
+ f.write('! -*- f90 -*-\n')
+ f.write(
+ '! This file is autogenerated with f2py (version:%s)\n' % (f2py_version))
+ f.write(
+ '! It contains Fortran 90 wrappers to fortran functions.\n')
+ lines = []
+ for l in ('\n\n'.join(funcwrappers2) + '\n').split('\n'):
+ if len(l) > 72 and l[0] == ' ':
+ lines.append(l[:72] + '&\n &')
+ l = l[72:]
+ while len(l) > 66:
+ lines.append(l[:66] + '&\n &')
+ l = l[66:]
+ lines.append(l + '\n')
+ else:
+ lines.append(l + '\n')
+ lines = ''.join(lines).replace('\n &\n', '\n')
+ f.write(lines)
outmess('\tFortran 90 wrappers are saved to "%s"\n' % (wn))
return ret