diff --git a/Lib/test/test_build_details.py b/Lib/test/test_build_details.py index b6f4b6fe26379b..7ee73614462e51 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..57de41ae87aaae --- /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``. They are now relative to ``base_prefix``, as +required, instead of being computed from the already relative ``base_prefix``. diff --git a/Tools/build/generate-build-details.py b/Tools/build/generate-build-details.py index 738c51026b77cc..d3ccc9f5f76c84 100644 --- a/Tools/build/generate-build-details.py +++ b/Tools/build/generate-build-details.py @@ -142,11 +142,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 = (