def fmt(console: Console, targets: HydratedTargets, union_membership: UnionMembership) -> Fmt: results = yield [ Get(FmtResult, TargetWithSources, target.adaptor) for target in targets # TODO: make TargetAdaptor return a 'sources' field with an empty snapshot instead of # raising to remove the hasattr() checks here! if union_membership.is_member(TargetWithSources, target.adaptor) and hasattr(target.adaptor, "sources") ] for result in results: files_content = yield Get(FilesContent, Digest, result.digest) # TODO: This is hacky and inefficient, and should be replaced by using the Workspace type # once that is available on master. # Blocked on: https://github.com/pantsbuild/pants/pull/8329 for file_content in files_content: with Path(get_buildroot(), file_content.path).open('wb') as f: f.write(file_content.content) if result.stdout: console.print_stdout(result.stdout) if result.stderr: console.print_stderr(result.stderr) # Since we ran an ExecuteRequest, any failure would already have interrupted our flow exit_code = 0 yield Fmt(exit_code)
def is_testable( adaptor_with_origin: TargetAdaptorWithOrigin, *, union_membership: UnionMembership, ) -> bool: is_test_target = union_membership.is_member(TestTarget, adaptor_with_origin) is_not_a_glob = isinstance( adaptor_with_origin.origin, (SingleAddress, FilesystemLiteralSpec) ) return adaptor_with_origin.adaptor.has_sources() and (is_test_target or is_not_a_glob)
def is_lintable(target_adaptor: TargetAdaptor, *, union_membership: UnionMembership) -> bool: return ( union_membership.is_member(LintTarget, target_adaptor) # TODO: make TargetAdaptor return a 'sources' field with an empty snapshot instead of # raising to remove the hasattr() checks here! and hasattr(target_adaptor, "sources") and target_adaptor.sources.snapshot.files # i.e., sources is not empty )
def is_testable(target: HydratedTarget, *, union_membership: UnionMembership, provenance_map: AddressProvenanceMap) -> bool: is_valid_target_type = ( provenance_map.is_single_address(target.address) or union_membership.is_member(TestTarget, target.adaptor)) has_sources = hasattr( target.adaptor, "sources") and target.adaptor.sources.snapshot.files return is_valid_target_type and has_sources
def coordinator_of_tests( target: HydratedTarget, union_membership: UnionMembership, provenance_map: AddressProvenanceMap) -> AddressAndTestResult: # TODO(#6004): when streaming to live TTY, rely on V2 UI for this information. When not a # live TTY, periodically dump heavy hitters to stderr. See # https://github.com/pantsbuild/pants/issues/6004#issuecomment-492699898. if (provenance_map.is_single_address(target.address) or union_membership.is_member(TestTarget, target.adaptor)): logger.info("Starting tests: {}".format(target.address.reference())) # NB: This has the effect of "casting" a TargetAdaptor to a member of the TestTarget union. # The adaptor will always be a member because of the union membership check above, but if # it were not it would fail at runtime with a useful error message. result = yield Get(TestResult, TestTarget, target.adaptor) logger.info("Tests {}: {}".format( "succeeded" if result.status == Status.SUCCESS else "failed", target.address.reference(), )) else: result = None # Not a test target. yield AddressAndTestResult(target.address, result)
def lint(console: Console, targets: HydratedTargets, union_membership: UnionMembership) -> Lint: results = yield [ Get(LintResult, TargetWithSources, target.adaptor) for target in targets # TODO: make TargetAdaptor return a 'sources' field with an empty snapshot instead of # raising to remove the hasattr() checks here! if union_membership.is_member(TargetWithSources, target.adaptor) and hasattr(target.adaptor, "sources") ] exit_code = 0 for result in results: if result.stdout: console.print_stdout(result.stdout) if result.stderr: console.print_stderr(result.stderr) if result.exit_code != 0: exit_code = result.exit_code yield Lint(exit_code)