async def create_python_binary( config: PythonBinaryConfiguration) -> CreatedBinary: entry_point: Optional[str] if config.entry_point.value is not None: entry_point = config.entry_point.value else: source_files = await Get[SourceFiles](AllSourceFilesRequest( [config.sources], strip_source_roots=True)) # NB: `PythonBinarySources` enforces that we have 0-1 sources. if len(source_files.files) == 1: module_name = source_files.files[0] entry_point = PythonBinary.translate_source_path_to_py_module_specifier( module_name) else: entry_point = None output_filename = f"{config.address.target_name}.pex" two_step_pex = await Get[TwoStepPex](TwoStepPexFromTargetsRequest( PexFromTargetsRequest( addresses=Addresses([config.address]), entry_point=entry_point, platforms=PexPlatforms.create_from_platforms_field( config.platforms), output_filename=output_filename, additional_args=config.generate_additional_args(), ))) pex = two_step_pex.pex return CreatedBinary(digest=pex.directory_digest, binary_name=pex.output_filename)
async def create_python_binary( python_binary_adaptor: PythonBinaryAdaptor) -> CreatedBinary: #TODO(#8420) This way of calculating the entry point works but is a bit hackish. entry_point = None if hasattr(python_binary_adaptor, 'entry_point'): entry_point = python_binary_adaptor.entry_point else: sources_snapshot = python_binary_adaptor.sources.snapshot if len(sources_snapshot.files) == 1: target = await Get[HydratedTarget](Address, python_binary_adaptor.address) output = await Get[SourceRootStrippedSources](HydratedTarget, target) root_filename = output.snapshot.files[0] entry_point = PythonBinary.translate_source_path_to_py_module_specifier( root_filename) request = CreatePexFromTargetClosure( build_file_addresses=BuildFileAddresses( (python_binary_adaptor.address, )), entry_point=entry_point, output_filename=f'{python_binary_adaptor.address.target_name}.pex') pex = await Get[Pex](CreatePexFromTargetClosure, request) return CreatedBinary(digest=pex.directory_digest, binary_name=pex.output_filename)
async def create_python_binary(fields: PythonBinaryFields) -> CreatedBinary: entry_point: Optional[str] if fields.entry_point.value is not None: entry_point = fields.entry_point.value else: # TODO: rework determine_source_files.py to work with the Target API. It should take the # Sources AsyncField as input, rather than TargetAdaptor. sources_result = await Get[SourcesResult](SourcesRequest, fields.sources.request) stripped_sources = await Get[SourceRootStrippedSources]( StripSnapshotRequest(sources_result.snapshot)) source_files = stripped_sources.snapshot.files # NB: `PythonBinarySources` enforces that we have 0-1 sources. if len(source_files) == 1: module_name = source_files[0] entry_point = PythonBinary.translate_source_path_to_py_module_specifier( module_name) else: entry_point = None request = CreatePexFromTargetClosure( addresses=Addresses([fields.address]), entry_point=entry_point, output_filename=f"{fields.address.target_name}.pex", ) pex = await Get[Pex](CreatePexFromTargetClosure, request) return CreatedBinary(digest=pex.directory_digest, binary_name=pex.output_filename)
async def create_python_binary( python_binary_adaptor: PythonBinaryAdaptor) -> CreatedBinary: # TODO(#8420) This way of calculating the entry point works but is a bit hackish. if hasattr(python_binary_adaptor, "entry_point"): entry_point = python_binary_adaptor.entry_point else: sources = await Get[SourceFiles](AllSourceFilesRequest( [python_binary_adaptor], strip_source_roots=True)) # NB: `python_binary` targets may have 0-1 sources. This is enforced by # `PythonBinaryAdaptor`. if len(sources.snapshot.files) == 1: module_name = sources.snapshot.files[0] entry_point = PythonBinary.translate_source_path_to_py_module_specifier( module_name) else: entry_point = None request = CreatePexFromTargetClosure( addresses=Addresses((python_binary_adaptor.address, )), entry_point=entry_point, output_filename=f"{python_binary_adaptor.address.target_name}.pex", ) pex = await Get[Pex](CreatePexFromTargetClosure, request) return CreatedBinary(digest=pex.directory_digest, binary_name=pex.output_filename)
def create_python_binary(python_binary_adaptor: PythonBinaryAdaptor, python_setup: PythonSetup) -> CreatedBinary: transitive_hydrated_targets = yield Get( TransitiveHydratedTargets, BuildFileAddresses((python_binary_adaptor.address, ))) all_targets = transitive_hydrated_targets.closure all_target_adaptors = [t.adaptor for t in all_targets] interpreter_constraints = PexInterpreterConstraints.create_from_adaptors( adaptors=tuple(all_targets), python_setup=python_setup) source_root_stripped_sources = yield [ Get(SourceRootStrippedSources, HydratedTarget, target_adaptor) for target_adaptor in all_targets ] #TODO(#8420) This way of calculating the entry point works but is a bit hackish. entry_point = None if hasattr(python_binary_adaptor, 'entry_point'): entry_point = python_binary_adaptor.entry_point else: sources_snapshot = python_binary_adaptor.sources.snapshot if len(sources_snapshot.files) == 1: target = transitive_hydrated_targets.roots[0] output = yield Get(SourceRootStrippedSources, HydratedTarget, target) root_filename = output.snapshot.files[0] entry_point = PythonBinary.translate_source_path_to_py_module_specifier( root_filename) stripped_sources_digests = [ stripped_sources.snapshot.directory_digest for stripped_sources in source_root_stripped_sources ] sources_digest = yield Get( Digest, DirectoriesToMerge(directories=tuple(stripped_sources_digests))) inits_digest = yield Get(InjectedInitDigest, Digest, sources_digest) all_input_digests = [sources_digest, inits_digest.directory_digest] merged_input_files = yield Get( Digest, DirectoriesToMerge, DirectoriesToMerge(directories=tuple(all_input_digests))) requirements = PexRequirements.create_from_adaptors(all_target_adaptors) output_filename = f"{python_binary_adaptor.address.target_name}.pex" create_requirements_pex = CreatePex( output_filename=output_filename, requirements=requirements, interpreter_constraints=interpreter_constraints, entry_point=entry_point, input_files_digest=merged_input_files, ) pex = yield Get(Pex, CreatePex, create_requirements_pex) yield CreatedBinary(digest=pex.directory_digest, binary_name=pex.output_filename)