Skip to content

Commit fb8f10a

Browse files
committed
Add --install-path and --calculate-system-install-path
Signed-off-by: Filipe Laíns <lains@riseup.net>
1 parent e88fe72 commit fb8f10a

2 files changed

Lines changed: 38 additions & 7 deletions

File tree

‎Lib/sysconfig/_build_details.py‎

Lines changed: 34 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -403,31 +403,59 @@ def from_interpreter(cls) -> SchemaBase: ...
403403
# Generation/CLI helpers.
404404

405405

406-
def generate(path: _PathType, relative_paths=False) -> None:
407-
"""Generates build-details.json for the current interpreter."""
406+
def generate(
407+
output_path: _PathType,
408+
install_path: _PathType | None = None,
409+
relative_paths=False,
410+
) -> None:
411+
"""Generates build-details.json for the current interpreter.
412+
413+
**install_path** allows overwriting the intended installation path. The file
414+
will still be written to **output_path**, but `base_prefix` will be relative
415+
to **install_path**. This is helpful when separting the build and install
416+
steps. If **install_path** is not specified, it will default to
417+
**output_path**.
418+
"""
408419
data = BuildDetails.from_interpreter()
409420

421+
if not install_path:
422+
install_path = output_path
423+
410424
if relative_paths:
411425
data = data.as_relocatable()
412426
# If relative_paths is enabled, we also make base_prefix relative.
413-
data.base_prefix = data.base_prefix.relative_to(path)
427+
data.base_prefix = data.base_prefix.relative_to(install_path, walk_up=True)
414428

415-
with open(path, 'w', encoding='utf-8') as f:
429+
with open(output_path, 'w', encoding='utf-8') as f:
416430
f.write(data.as_json() + '\n')
417431

418432

419433
def main() -> None:
420434
parser = argparse.ArgumentParser(exit_on_error=False)
421-
parser.add_argument('location')
435+
parser.add_argument('output_path')
422436
parser.add_argument(
423437
'--relative-paths',
424438
action='store_true',
425439
help='Whether to specify paths as absolute, or as relative paths to ``base_prefix``.',
426440
)
441+
install_path_group = parser.add_mutually_exclusive_group()
442+
install_path_group.add_argument(
443+
'--install-path',
444+
nargs=1,
445+
help='Overwrite the intended instalation path. Used when calculating a relative value for ``base_prefix``.',
446+
)
447+
install_path_group.add_argument(
448+
'--calculate-system-install-path',
449+
action='store_true',
450+
help='Calculate the install path for the system build-details.json file, and use that value.',
451+
)
427452

428453
args = parser.parse_args()
429454

430-
generate(args.location, args.relative_paths)
455+
if args.calculate_system_install_path:
456+
args.install_path = os.path.join(sysconfig.get_path('stdlib'), 'build-details.json')
457+
458+
generate(args.output_path, args.install_path, args.relative_paths)
431459

432460

433461
if __name__ == '__main__':

‎Makefile.pre.in‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1035,7 +1035,10 @@ pybuilddir.txt: $(PYTHON_FOR_BUILD_DEPS)
10351035
fi
10361036

10371037
$(BUILD_DETAILS): pybuilddir.txt
1038-
$(RUNSHARED_FOR_BUILD) $(PYTHON_FOR_BUILD) -m sysconfig._build_details --relative-paths `cat pybuilddir.txt`/$(BUILD_DETAILS)
1038+
$(RUNSHARED_FOR_BUILD) $(PYTHON_FOR_BUILD) -m sysconfig._build_details \
1039+
--relative-paths \
1040+
--calculate-system-install-path \
1041+
`cat pybuilddir.txt`/$(BUILD_DETAILS)
10391042

10401043
# Build static library
10411044
$(LIBRARY): $(LIBRARY_OBJS)

0 commit comments

Comments
 (0)