From 319676b8e88731acf81e23614bc8a9466ec15217 Mon Sep 17 00:00:00 2001 From: Itamar Oren Date: Wed, 21 Oct 2026 16:05:50 -0700 Subject: [PATCH] gh-160004: Fix build-details.json paths with `--config-file-path` (GH-160007) `make_paths_relative()` now keeps the absolute `base_prefix` for computing the other paths, and only the stored `base_prefix` is made relative to the config file's directory. This is the same fix python-build-standalone carries in `patch-python-relative-build-details.patch` (by @geofft). That patch also changes the Makefile to generate relative paths by default; this PR leaves the Makefile alone. (cherry picked from commit fc1a634099fdcc03b4e92b048d7f9ff87a3f134c) Co-authored-by: Itamar Oren --- Lib/test/test_build_details.py | 18 ++++++++++++++++++ ...6-10-20-23-30-00.gh-issue-160004.CfgPth.rst | 4 ++++ Tools/build/generate-build-details.py | 7 ++++--- 3 files changed, 26 insertions(+), 3 deletions(-) create mode 100644 Misc/NEWS.d/next/Build/2026-10-20-23-30-00.gh-issue-160004.CfgPth.rst diff --git a/Lib/test/test_build_details.py b/Lib/test/test_build_details.py index feca620f9a259c..780c5246cab97b 100644 --- a/Lib/test/test_build_details.py +++ b/Lib/test/test_build_details.py @@ -217,6 +217,24 @@ def test_round_trip(self): self.assertEqual(data_abs_path['base_prefix'], data_rel_path['base_prefix']) + self.check_relative_paths(data_abs_path, data_rel_path) + + def test_round_trip_with_config_file_path(self): + data_abs_path = self.build_details_absolute_paths + base_prefix = data_abs_path['base_prefix'] + config_dir = os.path.join(base_prefix, 'lib', 'python3.X') + data_rel_path = self.build_details_absolute_paths + generate_build_details.make_paths_relative( + data_rel_path, + config_path=os.path.join(config_dir, 'build-details.json'), + ) + + # base_prefix is relative to the config file's directory... + self.assertEqual(data_rel_path['base_prefix'], os.path.join('..', '..')) + # ...while the other paths are still relative to base_prefix. + self.check_relative_paths(data_abs_path, data_rel_path) + + def check_relative_paths(self, data_abs_path, data_rel_path): base_prefix = data_abs_path['base_prefix'] top_level_keys = ('base_interpreter',) diff --git a/Misc/NEWS.d/next/Build/2026-10-20-23-30-00.gh-issue-160004.CfgPth.rst b/Misc/NEWS.d/next/Build/2026-10-20-23-30-00.gh-issue-160004.CfgPth.rst new file mode 100644 index 00000000000000..247f4677fc27c6 --- /dev/null +++ b/Misc/NEWS.d/next/Build/2026-10-20-23-30-00.gh-issue-160004.CfgPth.rst @@ -0,0 +1,4 @@ +Fix the paths in the :pep:`739` ``build-details.json`` file generated by +:file:`Tools/build/generate-build-details.py` with both ``--relative-paths`` +and ``--config-file-path``. Previously, every path except ``base_prefix`` was +wrong and depended on the directory the script was run from. diff --git a/Tools/build/generate-build-details.py b/Tools/build/generate-build-details.py index 8aae9bf9fe8d41..20f07a85b6eb12 100644 --- a/Tools/build/generate-build-details.py +++ b/Tools/build/generate-build-details.py @@ -140,11 +140,12 @@ def generate_data(schema_version: str) -> collections.defaultdict[str, Any]: def make_paths_relative(data: dict[str, Any], config_path: str | None = None) -> None: - # Make base_prefix relative to the config_path directory + base_prefix = data['base_prefix'] + # Make base_prefix relative to the config_path directory. The other paths + # are still made relative to the absolute base_prefix below. if config_path: - data['base_prefix'] = relative_path(data['base_prefix'], + data['base_prefix'] = relative_path(base_prefix, os.path.dirname(config_path)) - base_prefix = data['base_prefix'] # Update path values to make them relative to base_prefix PATH_KEYS = (