summaryrefslogtreecommitdiff
path: root/numpy/f2py/__init__.py
diff options
context:
space:
mode:
authormattip <matti.picus@gmail.com>2019-01-20 16:09:33 +0200
committermattip <matti.picus@gmail.com>2019-01-20 17:24:59 +0200
commitd26842f9ce822f32b4c6165aff75d950e400beb8 (patch)
treef57090966de9d6bece34a9286d92041db2501b59 /numpy/f2py/__init__.py
parentf07a38da97a6a36eb12b203f6c1ffa4bf2b2cb87 (diff)
downloadnumpy-d26842f9ce822f32b4c6165aff75d950e400beb8.tar.gz
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]