Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions Lib/test/test_build_details.py
Original file line number Diff line number Diff line change
Expand Up @@ -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',)
Expand Down
Original file line number Diff line number Diff line change
@@ -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``.
7 changes: 4 additions & 3 deletions Tools/build/generate-build-details.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 = (
Expand Down
Loading