async def format_terraform_targets( terraform_fmt_targets: TerraformFmtTargets, union_membership: UnionMembership ) -> LanguageFmtResults: original_sources = await Get( SourceFiles, SourceFilesRequest( target[TerraformModuleSourcesField] for target in terraform_fmt_targets.targets ), ) prior_formatter_result = original_sources.snapshot results = [] fmt_request_types: Iterable[type[StyleRequest]] = union_membership[TerraformFmtRequest] for fmt_request_type in fmt_request_types: request = fmt_request_type( ( fmt_request_type.field_set_type.create(target) for target in terraform_fmt_targets.targets if fmt_request_type.field_set_type.is_applicable(target) ), prior_formatter_result=prior_formatter_result, ) if not request.field_sets: continue result = await Get(FmtResult, TerraformFmtRequest, request) results.append(result) if result.did_change: prior_formatter_result = await Get(Snapshot, Digest, result.output) return LanguageFmtResults( tuple(results), input=original_sources.snapshot.digest, output=prior_formatter_result.digest, )
async def format_python_target( python_fmt_targets: PythonFmtTargets, union_membership: UnionMembership) -> LanguageFmtResults: targets_with_origins = python_fmt_targets.targets_with_origins original_sources = await Get[SourceFiles](AllSourceFilesRequest( target_with_origin.target[PythonSources] for target_with_origin in python_fmt_targets.targets_with_origins)) prior_formatter_result = original_sources.snapshot results: List[FmtResult] = [] config_collection_types: Iterable[ Type[FmtConfigurations]] = union_membership.union_rules[ PythonFmtConfigurations] for config_collection_type in config_collection_types: result = await Get[FmtResult]( PythonFmtConfigurations, config_collection_type( (config_collection_type.config_type.create(target_with_origin) for target_with_origin in targets_with_origins), prior_formatter_result=prior_formatter_result, ), ) if result != FmtResult.noop(): results.append(result) prior_formatter_result = await Get[Snapshot](Digest, result.digest) return LanguageFmtResults( tuple(results), combined_digest=prior_formatter_result.directory_digest)
async def format_shell_targets( shell_fmt_targets: ShellFmtTargets, union_membership: UnionMembership ) -> LanguageFmtResults: original_sources = await Get( SourceFiles, SourceFilesRequest(target[ShellSources] for target in shell_fmt_targets.targets), ) prior_formatter_result = original_sources.snapshot results = [] fmt_request_types = union_membership.union_rules[ShellFmtRequest] for fmt_request_type in fmt_request_types: result = await Get( EnrichedFmtResult, ShellFmtRequest, fmt_request_type( ( fmt_request_type.field_set_type.create(target) for target in shell_fmt_targets.targets ), prior_formatter_result=prior_formatter_result, ), ) results.append(result) if result.did_change: prior_formatter_result = await Get(Snapshot, Digest, result.output) return LanguageFmtResults( tuple(results), input=original_sources.snapshot.digest, output=prior_formatter_result.digest, )
async def format_python_target( python_fmt_targets: PythonFmtTargets, union_membership: UnionMembership) -> LanguageFmtResults: original_sources = await Get( SourceFiles, SourceFilesRequest(target[PythonSources] for target in python_fmt_targets.targets), ) prior_formatter_result = original_sources.snapshot results: List[FmtResult] = [] fmt_request_types: Iterable[Type[ PythonFmtRequest]] = union_membership.union_rules[PythonFmtRequest] for fmt_request_type in fmt_request_types: result = await Get( FmtResult, PythonFmtRequest, fmt_request_type( (fmt_request_type.field_set_type.create(target) for target in python_fmt_targets.targets), prior_formatter_result=prior_formatter_result, ), ) results.append(result) if result.did_change: prior_formatter_result = await Get(Snapshot, Digest, result.output) return LanguageFmtResults( tuple(results), input=original_sources.snapshot.digest, output=prior_formatter_result.digest, )
async def format_python_target( python_fmt_targets: PythonFmtTargets, union_membership: UnionMembership) -> LanguageFmtResults: targets_with_origins = python_fmt_targets.targets_with_origins original_sources = await Get[SourceFiles](AllSourceFilesRequest( target_with_origin.target[PythonSources] for target_with_origin in python_fmt_targets.targets_with_origins)) prior_formatter_result = original_sources.snapshot results: List[FmtResult] = [] field_set_collection_types: Iterable[ Type[FmtFieldSets]] = union_membership.union_rules[PythonFmtFieldSets] for field_set_collection_type in field_set_collection_types: result = await Get[FmtResult]( PythonFmtFieldSets, field_set_collection_type( (field_set_collection_type.field_set_type.create( target_with_origin) for target_with_origin in targets_with_origins), prior_formatter_result=prior_formatter_result, ), ) if result != FmtResult.noop(): results.append(result) if result.did_change: prior_formatter_result = await Get[Snapshot](Digest, result.output) return LanguageFmtResults( tuple(results), input=original_sources.snapshot.digest, output=prior_formatter_result.digest, )
def language_fmt_results(self) -> LanguageFmtResults: addresses = [ target_with_origin.target.address for target_with_origin in self.targets_with_origins ] # NB: Due to mocking `await Get[Digest](DirectoriesToMerge), the digest we use here does # not matter. digest = EMPTY_DIRECTORY_DIGEST return LanguageFmtResults( (FmtResult(digest=digest, stdout=self.stdout(addresses), stderr=""), ), combined_digest=digest, )
def language_fmt_results(self, result_digest: Digest) -> LanguageFmtResults: # Note: we return a result that would result in a change so that we can validate that this # result is not actually returned. return LanguageFmtResults( (FmtResult( input=EMPTY_DIGEST, output=result_digest, stdout="", stderr="", formatter_name="InvalidFormatter", ), ), input=EMPTY_DIGEST, output=result_digest, )
def language_fmt_results(self, result_digest: Digest) -> LanguageFmtResults: addresses = [target.address for target in self.targets] return LanguageFmtResults( ( FmtResult( input=EMPTY_DIGEST, output=result_digest, stdout=self.stdout(addresses), stderr="", formatter_name=self.formatter_name, ), ), input=EMPTY_DIGEST, output=result_digest, )
def language_fmt_results(self, result_digest: Digest) -> LanguageFmtResults: return LanguageFmtResults( ( FmtResult( input=result_digest, output=result_digest, stdout="", stderr="", formatter_name="SmalltalkDidNotChange", ), FmtResult.skip(formatter_name="SmalltalkSkipped"), ), input=EMPTY_DIGEST, output=result_digest, )
def language_fmt_results(self, result_digest: Digest) -> LanguageFmtResults: output = (result_digest if any( tgt.address.target_name == "needs_formatting" for tgt in self.targets) else EMPTY_DIGEST) return LanguageFmtResults( (FmtResult( input=EMPTY_DIGEST, output=output, stdout="", stderr="", formatter_name="FortranConditionallyDidChange", ), ), input=EMPTY_DIGEST, output=result_digest, )