From 4caba2b1454bf7d6401a6b76ff16a42378e5ad12 Mon Sep 17 00:00:00 2001 From: Isuru Fernando Date: Wed, 4 Nov 2026 15:42:58 -0700 Subject: [PATCH] Install build-details.json on Windows Generate a PEP 739 build-details.json using upstream's PC/layout generator, adjusted for conda's unix-like Windows layout, and install it into the stdlib directory like on unix. --- recipe/build_base.bat | 5 +++ recipe/generate_build_details_win.py | 58 ++++++++++++++++++++++++++++ recipe/meta.yaml | 2 +- 3 files changed, 64 insertions(+), 1 deletion(-) create mode 100644 recipe/generate_build_details_win.py diff --git a/recipe/build_base.bat b/recipe/build_base.bat index 2b3318dd3..c23bb7a49 100644 --- a/recipe/build_base.bat +++ b/recipe/build_base.bat @@ -236,6 +236,11 @@ if "%CONDA_BUILD_CROSS_COMPILATION%" == "1" ( %PYTHON% -Wi %PREFIX%\lib\python\compileall.py -f -q -x "bad_coding|badsyntax|py2_" %PREFIX%\lib\python if errorlevel 1 exit 1 +:: Install a PEP 739 build-details.json next to the stdlib, like on unix +%PYTHON% %RECIPE_DIR%\generate_build_details_win.py %SRC_DIR% %PREFIX%\lib\python\build-details.json +if errorlevel 1 exit 1 +type %PREFIX%\lib\python\build-details.json + :: Ensure that scripts are generated :: https://github.com/conda-forge/python-feedstock/issues/384 %PYTHON% %RECIPE_DIR%\fix_staged_scripts.py diff --git a/recipe/generate_build_details_win.py b/recipe/generate_build_details_win.py new file mode 100644 index 000000000..ca1bd6cc3 --- /dev/null +++ b/recipe/generate_build_details_win.py @@ -0,0 +1,58 @@ +"""Generate a PEP 739 build-details.json for the conda Windows layout. + +Uses upstream's PC/layout generator (which does not need to run the target +interpreter, so it also works when cross-compiling) and adjusts the paths +for conda's unix-like Windows layout, where the file is installed into the +stdlib directory (%PREFIX%\\lib\\python) just like on unix. + +Usage: python generate_build_details_win.py SRC_DIR OUTPUT_FILE +""" + +import json +import os +import sys +import types + + +def main(): + src_dir, output = sys.argv[1:3] + + # Make PC/layout/support/constants.py read the version from the sources + # rather than from the running interpreter. + os.environ["PYTHONINCLUDE"] = os.path.join(src_dir, "Include") + sys.path.insert(0, os.path.join(src_dir, "PC", "layout")) + from support.builddetails import get_builddetails + + arch = { + "win-64": "amd64", + "win-32": "win32", + "win-arm64": "arm64", + }[os.environ["target_platform"]] + + ns = types.SimpleNamespace( + include_builddetails_json=True, + include_freethreaded=os.environ.get("PY_FREETHREADING") == "yes", + debug=os.environ.get("PY_INTERP_DEBUG") == "yes", + include_dev=True, + arch=arch, + ) + ((_, (_, content)),) = list(get_builddetails(ns)) + details = json.loads(content) + + # The file lives in %PREFIX%\lib\python; all other paths are relative + # to base_prefix. + details["base_prefix"] = "../.." + # build_base.bat always installs python.exe (copied for debug and + # free-threaded builds), whereas e.g. python_d.exe is not always there. + details["base_interpreter"] = "./python.exe" + for key in ("dynamic", "dynamic_stableabi"): + details["libpython"][key] = "./" + details["libpython"][key] + details["c_api"]["headers"] = "./include/python" + + with open(output, "w", encoding="utf-8") as f: + json.dump(details, f, indent=2) + f.write("\n") + + +if __name__ == "__main__": + main() diff --git a/recipe/meta.yaml b/recipe/meta.yaml index 1ab595463..669b43955 100644 --- a/recipe/meta.yaml +++ b/recipe/meta.yaml @@ -4,7 +4,7 @@ {% set ver2 = '.'.join(version.split('.')[0:2]) %} {% set ver2nd = ''.join(version.split('.')[0:2]) %} {% set ver3nd = ''.join(version.split('.')[0:3]) %} -{% set build_number = 0 %} +{% set build_number = 1 %} # this makes the linter happy {% set channel_targets = channel_targets or 'conda-forge main' %}