MCPcopy Create free account
hub / github.com/IfcOpenShell/IfcOpenShell / compile_python_wrapper

Function compile_python_wrapper

nix/build-all.py:1446–1518  ·  view source on GitHub ↗

:return: Path to module dir if ``python_executable`` was provided, otherwise ``None``.

(
        python_version: str,
        python_include: Union[str, None] = None,
        python_executable: Union[str, None] = None,
        python_path: Union[Path, None] = None,
    )

Source from the content-addressed store, hash-verified

1444 os.makedirs(python_dir, exist_ok=True)
1445
1446 def compile_python_wrapper(
1447 python_version: str,
1448 python_include: Union[str, None] = None,
1449 python_executable: Union[str, None] = None,
1450 python_path: Union[Path, None] = None,
1451 ) -> Union[str, None]:
1452 """
1453 :return: Path to module dir if ``python_executable`` was provided, otherwise ``None``.
1454 """
1455 assert bool(python_path) ^ bool(python_include)
1456
1457 logger.info(f"\rConfiguring python {python_version} wrapper...")
1458
1459 cache_path = os.path.join(python_dir, "CMakeCache.txt")
1460 if os.path.exists(cache_path):
1461 os.remove(cache_path)
1462
1463 if python_path:
1464 # We couldn't just prefix PATH and have to provide all variables explicitly,
1465 # see ifcwrap/cmake for the details.
1466 python_executable = (Path(python_path) / "bin" / "python3").__str__()
1467 python_include = run(
1468 [
1469 python_executable,
1470 "-c",
1471 "import sysconfig; print(sysconfig.get_config_var('INCLUDEPY'))",
1472 ]
1473 )
1474
1475 assert python_include
1476 run_cmake(
1477 "",
1478 cmake_args
1479 + get_cmake_args_prefix_path()
1480 + [
1481 *([f"-DPYTHON_EXECUTABLE={python_executable}"] if python_executable else []),
1482 # Needed because pyodide is expecting setup.py to be in the root.
1483 *([f"-DPYTHON_MODULE_INSTALL_DIR={REPO_PATH}"] * WASM),
1484 f"-DPYTHON_INCLUDE_DIR={python_include}",
1485 f"-DCMAKE_INSTALL_PREFIX={DEPS_DIR}/install/ifcopenshell/tmp",
1486 "-DUSERSPACE_PYTHON_PREFIX="
1487 + ["Off", "On"][os.environ.get("PYTHON_USER_SITE", "").lower() in {"1", "on", "true"}],
1488 ],
1489 cmake_dir=CMAKE_DIR,
1490 cwd=python_dir,
1491 )
1492
1493 logger.info(f"\rBuilding python {python_version} wrapper... ")
1494
1495 run([make, f"-j{IFCOS_NUM_BUILD_PROCS}", "ifcopenshell_wrapper", "VERBOSE=1"], cwd=python_dir)
1496 run([make, "install/local"], cwd=os.path.join(python_dir, "ifcwrap"))
1497
1498 if python_executable:
1499 run([python_executable, "-m", "ensurepip"])
1500 run([python_executable, "-m", "pip", "install", "--user", "numpy", "typing_extensions"])
1501 module_dir = run(
1502 [python_executable, "-c", "import inspect, ifcopenshell; print(inspect.getfile(ifcopenshell))"]
1503 )

Callers 1

build-all.pyFile · 0.85

Calls 8

run_cmakeFunction · 0.85
lowerMethod · 0.80
runFunction · 0.70
joinMethod · 0.45
removeMethod · 0.45
__str__Method · 0.45
getMethod · 0.45

Tested by

no test coverage detected