File: __init__.py

package info (click to toggle)
python-f2py 2.45.241%2B1926-5
  • links: PTS
  • area: main
  • in suites: etch, etch-m68k
  • size: 956 kB
  • ctags: 700
  • sloc: python: 8,720; ansic: 929; fortran: 109; makefile: 48; f90: 34
file content (40 lines) | stat: -rw-r--r-- 982 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
#!/usr/bin/env python

__all__ = ['run_main','compile','f2py_testing']

import os
import tempfile
import sys
import commands

import f2py2e
run_main = f2py2e.run_main
main = f2py2e.main
import f2py_testing

def compile(source,
            modulename = 'untitled',
            extra_args = '',
            verbose = 1,
            source_fn = None
            ):
    ''' Build extension module from processing source with f2py.
    Read the source of this function for more information.
    '''
    from scipy_distutils.exec_command import exec_command
    if source_fn is None:
        fname = os.path.join(tempfile.mktemp()+'.f')
    else:
        fname = source_fn

    f = open(fname,'w')
    f.write(source)
    f.close()

    args = ' -c -m %s %s %s'%(modulename,fname,extra_args)
    c = '%s -c "import f2py2e;f2py2e.main()" %s' %(sys.executable,args)
    s,o = exec_command(c)
    if source_fn is None:
        try: os.remove(fname)
        except OSError: pass
    return s