|
6 | 6 | import shutil |
7 | 7 |
|
8 | 8 |
|
9 | | -USAGE = "usage: cythoner OUTPUT.c PRIVATE_DIR INPUT.pyx [INPUT.pxd ...]" |
| 9 | +USAGE = "usage: cythoner OUTPUT.c PRIVATE_DIR INPUT.pyx [INPUT.pxd, INPUT.pxi, ...]" |
10 | 10 | SRC_DIR = Path(__file__, "../../src/").resolve() |
11 | 11 | BUILD_SRC_DIR = Path(os.getcwd()).resolve() / "src" |
12 | 12 |
|
|
16 | 16 |
|
17 | 17 |
|
18 | 18 | c_output, private_dir, pyx_src, *pxd_srcs = [Path(x).resolve() for x in sys.argv[1:]] |
19 | | -if not pyx_src.name.endswith(".pyx") or any(not src.name.endswith(".pxd") for src in pxd_srcs): |
20 | | - raise SystemError(USAGE) |
| 19 | +# `pxd_srcs` can also contains `.pxi` files given we handle them in a similar fashion |
| 20 | +if not pyx_src.name.endswith(".pyx") or any( |
| 21 | + not src.name.endswith(".pxd") and not src.name.endswith(".pxi") for src in pxd_srcs |
| 22 | +): |
| 23 | + raise SystemExit(USAGE) |
21 | 24 |
|
22 | 25 |
|
23 | 26 | def relative_path(path: Path) -> Path: |
@@ -47,9 +50,11 @@ def relative_path(path: Path) -> Path: |
47 | 50 | pxd_tgt = pxd_parent_dir / pxd_src.name |
48 | 51 |
|
49 | 52 | pxd_parent_dir.mkdir(exist_ok=True, parents=True) |
50 | | - # `__init__.py` are required so Cython consider the directory as a package, |
51 | | - # however it content is never read so an empty file is good enough |
52 | | - (pxd_parent_dir / "__init__.py").touch() |
| 53 | + while pxd_parent_dir != private_dir: |
| 54 | + # `__init__.py` are required so Cython consider the directory as a package, |
| 55 | + # however it content is never read so an empty file is good enough |
| 56 | + (pxd_parent_dir / "__init__.py").touch() |
| 57 | + pxd_parent_dir = pxd_parent_dir.parent |
53 | 58 | shutil.copyfile(pxd_src, pxd_tgt) |
54 | 59 |
|
55 | 60 |
|
|
0 commit comments