File: cythonize.py

package info (click to toggle)
slepc4py 3.24.2-1
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 2,760 kB
  • sloc: python: 6,916; makefile: 129; ansic: 98; sh: 46
file content (52 lines) | stat: -rwxr-xr-x 1,316 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
41
42
43
44
45
46
47
48
49
50
51
52
#!/usr/bin/env python3
"""Run Cython with custom options."""
import os
import sys

appdir = os.path.dirname(os.path.abspath(__file__))
sys.path.insert(0, appdir)

import cyautodoc  # noqa: F401,E402
from Cython.Compiler.Main import main as cython_main  # noqa: E402


def cythonize(args=None):
    """Run `cython --3str --cleanup 3 <args>...`."""
    if args is None:
        argv = sys.argv[:]
    else:
        argv = [os.path.abspath(__file__)] + list(args)

    if '--cleanup' not in argv:
        argv[1:1] = ['--cleanup', '3']
    if '--3str' not in argv:
        argv[1:1] = ['--3str']

    cwd = os.getcwd()
    sys_argv = sys.argv[:]
    try:
        sys.argv[:] = argv
        cython_main(command_line=1)
        return 0
    except SystemExit as exc:
        return exc.code
    finally:
        os.chdir(cwd)
        sys.argv[:] = sys_argv


def main():
    """Entry-point to run Cython with custom options."""
    args = sys.argv[1:]
    if not args:
        topdir = os.path.dirname(appdir)
        srcdir = os.path.join(topdir, 'src')
        source = os.path.join('slepc4py', 'SLEPc.pyx')
        target = os.path.join('slepc4py', 'SLEPc.c')
        args += ['--working', srcdir]
        args += [source, '--output-file', target]
    sys.exit(cythonize(args))


if __name__ == "__main__":
    main()