Skip to content

Commit fc1a634

Browse files
authored
gh-160004: Fix build-details.json paths with --config-file-path (#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.
1 parent 4036afb commit fc1a634

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
@@ -217,6 +217,24 @@ def test_round_trip(self):
217217
self.assertEqual(data_abs_path['base_prefix'],
218218
data_rel_path['base_prefix'])
219219

220+
self.check_relative_paths(data_abs_path, data_rel_path)
221+
222+
def test_round_trip_with_config_file_path(self):
223+
data_abs_path = self.build_details_absolute_paths
224+
base_prefix = data_abs_path['base_prefix']
225+
config_dir = os.path.join(base_prefix, 'lib', 'python3.X')
226+
data_rel_path = self.build_details_absolute_paths
227+
generate_build_details.make_paths_relative(
228+
data_rel_path,
229+
config_path=os.path.join(config_dir, 'build-details.json'),
230+
)
231+
232+
# base_prefix is relative to the config file's directory...
233+
self.assertEqual(data_rel_path['base_prefix'], os.path.join('..', '..'))
234+
# ...while the other paths are still relative to base_prefix.
235+
self.check_relative_paths(data_abs_path, data_rel_path)
236+
237+
def check_relative_paths(self, data_abs_path, data_rel_path):
220238
base_prefix = data_abs_path['base_prefix']
221239

222240
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
@@ -142,11 +142,12 @@ def generate_data(schema_version: str) -> collections.defaultdict[str, Any]:
142142

143143

144144
def make_paths_relative(data: dict[str, Any], config_path: str | None = None) -> None:
145-
# Make base_prefix relative to the config_path directory
145+
base_prefix = data['base_prefix']
146+
# Make base_prefix relative to the config_path directory. The other paths
147+
# are still made relative to the absolute base_prefix below.
146148
if config_path:
147-
data['base_prefix'] = relative_path(data['base_prefix'],
149+
data['base_prefix'] = relative_path(base_prefix,
148150
os.path.dirname(config_path))
149-
base_prefix = data['base_prefix']
150151

151152
# Update path values to make them relative to base_prefix
152153
PATH_KEYS = (

0 commit comments

Comments
 (0)