summaryrefslogtreecommitdiff
path: root/numpy/f2py/__init__.py
diff options
context:
space:
mode:
authorCharles Harris <charlesr.harris@gmail.com>2019-01-20 11:54:44 -0700
committerGitHub <noreply@github.com>2019-01-20 11:54:44 -0700
commit568d0f7483f7b94029d49707ccd6371f9f5c554c (patch)
tree3e546aae0f0e5d337fd758852b0623c7c1902b4c /numpy/f2py/__init__.py
parent2b05f3e38431842ff06df9b2958d22c5a0588767 (diff)
parentd26842f9ce822f32b4c6165aff75d950e400beb8 (diff)
downloadnumpy-568d0f7483f7b94029d49707ccd6371f9f5c554c.tar.gz
Merge pull request #12807 from mattip/f2py-source-bytes
BUG, DOC: test, fix that f2py.compile accepts str and bytes, rework docs
Diffstat (limited to 'numpy/f2py/__init__.py')
-rw-r--r--numpy/f2py/__init__.py22
1 files changed, 19 insertions, 3 deletions
diff --git a/numpy/f2py/__init__.py b/numpy/f2py/__init__.py
index 23a4b7c41..d146739bb 100644
--- a/numpy/f2py/__init__.py
+++ b/numpy/f2py/__init__.py
@@ -28,12 +28,16 @@ def compile(source,
extension='.f'
):
"""
- Build extension module from processing source with f2py.
+ Build extension module from a Fortran 77 source string with f2py.
Parameters
----------
- source : str
+ source : str or bytes
Fortran source of module / subroutine to compile
+
+ .. versionchanged:: 1.16.0
+ Accept str as well as bytes
+
modulename : str, optional
The name of the compiled python module
extra_args : str or list, optional
@@ -55,6 +59,16 @@ def compile(source,
.. versionadded:: 1.11.0
+ Returns
+ -------
+ result : int
+ 0 on success
+
+ Examples
+ --------
+ .. include:: compile_session.dat
+ :literal:
+
"""
import tempfile
import shlex
@@ -67,9 +81,11 @@ def compile(source,
else:
fname = source_fn
+ if not isinstance(source, str):
+ source = str(source, 'utf-8')
try:
with open(fname, 'w') as f:
- f.write(str(source))
+ f.write(source)
args = ['-c', '-m', modulename, f.name]