Skip to content

Commit ef1cf22

Browse files
[3.15] gh-160004: Fix build-details.json paths with --config-file-path (GH-160007) (#160143)
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 fc1a634) Co-authored-by: Itamar Oren <itamarost@gmail.com>
1 parent 67e7ed6 commit ef1cf22

3 files changed

Lines changed: 26 additions & 3 deletions

File tree

‎Lib/test/test_build_details.py‎

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -237,6 +237,24 @@ def test_round_trip(self):
237237
self.assertEqual(data_abs_path['base_prefix'],
238238
data_rel_path['base_prefix'])
239239

240+
self.check_relative_paths(data_abs_path, data_rel_path)
241+
242+
def test_round_trip_with_config_file_path(self):
243+
data_abs_path = self.build_details_absolute_paths
244+
base_prefix = data_abs_path['base_prefix']
245+
config_dir = os.path.join(base_prefix, 'lib', 'python3.X')
246+
data_rel_path = self.build_details_absolute_paths
247+
generate_build_details.make_paths_relative(
248+
data_rel_path,
249+
config_path=os.path.join(config_dir, 'build-details.json'),
250+
)
251+
252+
# base_prefix is relative to the config file's directory...
253+
self.assertEqual(data_rel_path['base_prefix'], os.path.join('..', '..'))
254+
# ...while the other paths are still relative to base_prefix.
255+
self.check_relative_paths(data_abs_path, data_rel_path)
256+
257+
def check_relative_paths(self, data_abs_path, data_rel_path):
240258
base_prefix = data_abs_path['base_prefix']
241259

242260
top_level_keys = ('base_interpreter',)
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
Fix the paths in the :pep:`739` ``build-details.json`` file generated by
2+
:file:`Tools/build/generate-build-details.py` with both ``--relative-paths``
3+
and ``--config-file-path``. Previously, every path except ``base_prefix`` was
4+
wrong and depended on the directory the script was run from.

‎Tools/build/generate-build-details.py‎

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -150,11 +150,12 @@ def generate_data(schema_version: str) -> collections.defaultdict[str, Any]:
150150

151151

152152
def make_paths_relative(data: dict[str, Any], config_path: str | None = None) -> None:
153-
# Make base_prefix relative to the config_path directory
153+
base_prefix = data['base_prefix']
154+
# Make base_prefix relative to the config_path directory. The other paths
155+
# are still made relative to the absolute base_prefix below.
154156
if config_path:
155-
data['base_prefix'] = relative_path(data['base_prefix'],
157+
data['base_prefix'] = relative_path(base_prefix,
156158
os.path.dirname(config_path))
157-
base_prefix = data['base_prefix']
158159

159160
# Update path values to make them relative to base_prefix
160161
PATH_KEYS = (

0 commit comments

Comments
 (0)