5454 - ``USE_OCCT`` - whether to use official Open CASCADE instead of Community Edition
5555 (`true` by default, any other value is considered `false`)
5656 - ``WASM_PYTHON_PATH`` - path to WASM Python installation,
57- used to deduce `PYMAJOR`, `PYMINOR`, `PYMICRO`, `TARGETINSTALLDIR` , `PYTHONINCLUDE`,
57+ used to deduce `PYVERSION` (e.g. '3.13.2') , `PYTHONINCLUDE`,
5858 `SIDE_MODULE_CFLAGS`, `SIDE_MODULE_LDFLAGS`.
5959 Allows to build wasm without pyodide build environment, which can be useful for debugging build issues.
6060 Example value: 'pyodide/cpython/installs/python-3.13.2'
@@ -216,27 +216,19 @@ def cecho(message, color=NO_COLOR):
216216 wasm_python_path = os .environ ["WASM_PYTHON_PATH" ]
217217 # Deduce version from path, assuming format .../python-X.Y.Z
218218 version_match = re .search (r"python-(\d+)\.(\d+)\.(\d+)" , wasm_python_path )
219- if version_match :
220- os .environ ["PYMAJOR" ] = version_match .group (1 )
221- os .environ ["PYMINOR" ] = version_match .group (2 )
222- os .environ ["PYMICRO" ] = version_match .group (3 )
223- os .environ ["TARGETINSTALLDIR" ] = wasm_python_path
224- os .environ ["PYTHONINCLUDE" ] = (
225- f"{ wasm_python_path } /include/python{ os .environ ['PYMAJOR' ]} .{ os .environ ['PYMINOR' ]} "
226- )
219+ assert version_match , f"Could not deduce python version from '{ wasm_python_path } '"
220+ python_version = version_match .group (1 )
221+ os .environ ["PYVERSION" ] = python_version
222+ os .environ ["PYTHONINCLUDE" ] = f"{ wasm_python_path } /include/python{ python_version .rpartition ('.' )[0 ]} "
227223 os .environ ["SIDE_MODULE_CFLAGS" ] = ""
228224 # Required, otherwise library will compile as .a, not .so.
229225 os .environ ["SIDE_MODULE_LDFLAGS" ] = "-s SIDE_MODULE=1"
230226 # We're outside pyodide build environment, so need to provide toolchain file ourselves.
231227 assert "WASM_TOOLCHAIN_FILE" in os .environ , "WASM_TOOLCHAIN_FILE must be set when WASM_PYTHON_PATH is provided"
232228 WASM_DEBUG = True
233229 required_vars = (
234- "PYMAJOR" ,
235- "PYMINOR" ,
236- "PYMICRO" ,
237- # Folder where WASM-Python was installed.
238- # e.g '/pyodide/cpython/installs/python-3.13.2'.
239- "TARGETINSTALLDIR" ,
230+ # E.g. '3.13.2'.
231+ "PYVERSION" ,
240232 # 'include' folder in WASM-Python installation.
241233 # e.g. '/pyodide/cpython/installs/python-3.13.2/include/python3.13'
242234 "PYTHONINCLUDE" ,
@@ -1448,15 +1440,14 @@ def get_cmake_args_prefix_path(additional_paths: "Sequence[str]" = ()) -> "list[
14481440
14491441 def compile_python_wrapper (
14501442 python_version : str ,
1451- python_library : Union [str , None ] = None ,
14521443 python_include : Union [str , None ] = None ,
14531444 python_executable : Union [str , None ] = None ,
14541445 python_path : Union [Path , None ] = None ,
14551446 ) -> Union [str , None ]:
14561447 """
14571448 :return: Path to module dir if ``python_executable`` was provided, otherwise ``None``.
14581449 """
1459- assert bool (python_path ) ^ bool (python_library and python_include )
1450+ assert bool (python_path ) ^ bool (python_include )
14601451
14611452 logger .info (f"\r Configuring python { python_version } wrapper..." )
14621453
@@ -1469,7 +1460,7 @@ def compile_python_wrapper(
14691460 prefix_paths .append (f"{ DEPS_DIR } /install/swig" )
14701461 if python_path :
14711462 # We couldn't just prefix PATH and have to provide all variables explicitly,
1472- # see run- cmake.bat note for details.
1463+ # see ifcwrap/ cmake for the details.
14731464 python_executable = (Path (python_path ) / "bin" / "python3" ).__str__ ()
14741465 python_include = run (
14751466 [
@@ -1478,20 +1469,8 @@ def compile_python_wrapper(
14781469 "import sysconfig; print(sysconfig.get_config_var('INCLUDEPY'))" ,
14791470 ]
14801471 )
1481- python_library = run (
1482- [
1483- python_executable ,
1484- "-c" ,
1485- "import sysconfig, pathlib; "
1486- "lib_dir = pathlib.Path(sysconfig.get_config_var('LIBDIR')); "
1487- "print((lib_dir / sysconfig.get_config_var('LIBRARY')).__str__())" ,
1488- ]
1489- )
1490- if platform .system () == "Darwin" :
1491- # Oddly on Mac `LIBRARY` returns .a that doesn't even exists.
1492- python_library = Path (python_library ).with_suffix (".dylib" ).__str__ ()
14931472
1494- assert python_library and python_include
1473+ assert python_include
14951474 run_cmake (
14961475 "" ,
14971476 cmake_args
@@ -1500,7 +1479,6 @@ def compile_python_wrapper(
15001479 * ([f"-DPYTHON_EXECUTABLE={ python_executable } " ] if python_executable else []),
15011480 # Needed because pyodide is expecting setup.py to be in the root.
15021481 * ([f"-DPYTHON_MODULE_INSTALL_DIR={ REPO_PATH } " ] * WASM ),
1503- f"-DPYTHON_LIBRARY={ python_library } " ,
15041482 f"-DPYTHON_INCLUDE_DIR={ python_include } " ,
15051483 f"-DCMAKE_INSTALL_PREFIX={ DEPS_DIR } /install/ifcopenshell/tmp" ,
15061484 "-DUSERSPACE_PYTHON_PREFIX="
@@ -1538,26 +1516,13 @@ def compile_python_wrapper(
15381516 return module_dir
15391517
15401518 if "wasm" in flags :
1541- compile_python_wrapper (
1542- f"{ os .environ ['PYMAJOR' ]} .{ os .environ ['PYMINOR' ]} .{ os .environ ['PYMICRO' ]} " ,
1543- f"{ os .environ ['TARGETINSTALLDIR' ]} /lib/libpython{ os .environ ['PYMAJOR' ]} .{ os .environ ['PYMINOR' ]} .a" ,
1544- os .environ ["PYTHONINCLUDE" ],
1545- None ,
1546- )
1519+ compile_python_wrapper (os .environ ["PYVERSION" ], os .environ ["PYTHONINCLUDE" ])
15471520 # Copy setup.py where pyodide build system expects it.
15481521 shutil .copy (REPO_PATH / "pyodide" / "setup.py" , REPO_PATH )
15491522
15501523 elif USE_CURRENT_PYTHON_VERSION :
15511524 python_info = sysconfig .get_paths ()
1552-
1553- py_path_components = [sysconfig .get_config_var ("LIBDIR" ), sysconfig .get_config_var ("INSTSONAME" )]
1554-
1555- if sysconfig .get_config_var ("multiarchsubdir" ):
1556- py_path_components .insert (1 , sysconfig .get_config_var ("multiarchsubdir" ).replace ("/" , "" ))
1557-
1558- python_lib = os .path .join (* py_path_components )
1559-
1560- compile_python_wrapper (platform .python_version (), python_lib , python_info ["include" ], sys .executable )
1525+ compile_python_wrapper (platform .python_version (), python_info ["include" ], sys .executable )
15611526 else :
15621527 for python_version in PYTHON_VERSIONS :
15631528 python_path = Path (DEPS_DIR ) / "install" / f"python-{ python_version } "
0 commit comments