File: cythonize.py

package info (click to toggle)
mpi4py 4.1.1-4
  • links: PTS, VCS
  • area: main
  • in suites:
  • size: 4,564 kB
  • sloc: python: 35,306; ansic: 16,482; sh: 842; makefile: 618; cpp: 193; f90: 178
file content (51 lines) | stat: -rw-r--r-- 1,253 bytes parent folder | download | duplicates (4)
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
#!/usr/bin/env python
"""Run Cython with custom options."""

import os
import pathlib
import sys

from Cython.Compiler.Main import main as cython_main


def cythonize(args=None):
    """Run `cython --3str --cleanup 3 <args>...`."""
    if args is None:
        argv = sys.argv[:]
    else:
        arg0 = str(pathlib.Path(__file__).resolve())
        argv = [arg0, *args]

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

    cwd = pathlib.Path.cwd()
    sys_argv = sys.argv[:]
    try:
        sys.argv[:] = argv
        cython_main(command_line=1)
    except SystemExit as exc:
        return exc.code
    else:
        return 0
    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 = pathlib.Path(__file__).resolve().parent.parent
        source = pathlib.Path() / "src" / "mpi4py" / "MPI.pyx"
        target = pathlib.Path() / "src" / "mpi4py" / "MPI.c"
        args += ["--working", str(topdir)]
        args += [str(source), "--output-file", str(target)]
    sys.exit(cythonize(args))


if __name__ == "__main__":
    main()