@@ -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
419433def 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
433461if __name__ == '__main__' :
0 commit comments