-
-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathbuild.py.orig
More file actions
67 lines (52 loc) · 2.08 KB
/
build.py.orig
File metadata and controls
67 lines (52 loc) · 2.08 KB
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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
"""Build script."""
import shutil
import sys
from distutils import log as distutils_log
from pathlib import Path
from typing import Any, Dict
import skbuild
import skbuild.constants
__all__ = ("build",)
def build(setup_kwargs: Dict[str, Any]) -> None:
"""Build C-extensions."""
cmake_args = [
'-DINSTALL_DOC:BOOL=OFF',
'-DRUN_GCOV:BOOL=OFF',
'-DLIB_SUFFIX='
] + (
['-DREADLINE_ROOT=/usr/local/opt/portable-readline',
'-DREADLINE_INCLUDE_DIR=/usr/local/opt/portable-readline/include',
'-DREADLINE_LIBRARY=/usr/local/opt/libedit/lib/libedit.dylib',
'-DICU_ROOT=/usr/local/opt/icu4c'] if sys.platform.startswith("darwin") else []
)
skbuild.setup(**setup_kwargs, script_args=["build_ext"])
# skbuild.setup(**setup_kwargs, script_args=cmake_args)
src_dir = Path(skbuild.constants.CMAKE_INSTALL_DIR()) / "opentrep"
dest_dir = Path("opentrep")
# Delete C-extensions copied in previous runs, just in case.
remove_files(dest_dir, "**/*.pyd")
remove_files(dest_dir, "**/*.so")
# Copy built C-extensions back to the project.
copy_files(src_dir, dest_dir, "**/*.pyd")
copy_files(src_dir, dest_dir, "**/*.so")
def remove_files(target_dir: Path, pattern: str) -> None:
"""Delete files matched with a glob pattern in a directory tree."""
for path in target_dir.glob(pattern):
if path.is_dir():
shutil.rmtree(path)
else:
path.unlink()
distutils_log.info(f"removed {path}")
def copy_files(src_dir: Path, dest_dir: Path, pattern: str) -> None:
"""Copy files matched with a glob pattern in a directory tree to another."""
for src in src_dir.glob(pattern):
dest = dest_dir / src.relative_to(src_dir)
if src.is_dir():
# NOTE: inefficient if subdirectories also match to the pattern.
copy_files(src, dest, "*")
else:
dest.parent.mkdir(parents=True, exist_ok=True)
shutil.copy2(src, dest)
distutils_log.info(f"copied {src} to {dest}")
if __name__ == "__main__":
build({})