Skip to content

Commit 8c13cfe

Browse files
committed
Improve scripts/cythoner.py handling of multi-nested pxd and add pxi support
1 parent 2df9bfe commit 8c13cfe

File tree

1 file changed

+11
-6
lines changed

1 file changed

+11
-6
lines changed

scripts/cythoner.py

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
import shutil
77

88

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, ...]"
1010
SRC_DIR = Path(__file__, "../../src/").resolve()
1111
BUILD_SRC_DIR = Path(os.getcwd()).resolve() / "src"
1212

@@ -16,8 +16,11 @@
1616

1717

1818
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)
2124

2225

2326
def relative_path(path: Path) -> Path:
@@ -47,9 +50,11 @@ def relative_path(path: Path) -> Path:
4750
pxd_tgt = pxd_parent_dir / pxd_src.name
4851

4952
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
5358
shutil.copyfile(pxd_src, pxd_tgt)
5459

5560

0 commit comments

Comments
 (0)