bitter-ability-32190
02/23/2022, 5:39 PMsource_files = await Get(
SourceFiles,
SourceFilesRequest(field_set.source for field_set in request.field_sets),
)
source_files_snapshot = (
source_files.snapshot
if request.prior_formatter_result is None
else request.prior_formatter_result
)
input_digest = source_files_snapshot.digest
digest_contents = await Get(DigestContents, Digest, input_digest)
output_digest = await Get(
Digest,
CreateDigest(
FileContent(path=file_content.path, content=maybe_add_copyright(file_content.content))
for file_content in digest_contents
),
)
return FmtResult(
input=input_digest,
output=output_digest,
stdout="",
stderr="",
formatter_name=request.name,
)
hundreds-father-404
02/23/2022, 5:42 PM/n
? Indeed it calculates if it was changed based on comparing input vs output. So you could materialize to mem w/ DigestContents
and compare that wayfast-nail-55400
02/23/2022, 5:44 PMdef diff_fmt_result(rule_runner: RuleRunner, fmt_result: FmtResult) -> None:
input_digest_contents = {fc.path: fc for fc in rule_runner.request(DigestContents, [fmt_result.input])}
output_digest_contents = {fc.path: fc for fc in rule_runner.request(DigestContents, [fmt_result.output])}
for path, input_fc in input_digest_contents.items():
output_fc = output_digest_contents[path]
input_content = input_fc.content.decode().splitlines()
output_content = output_fc.content.decode().splitlines()
unidiff = "\n".join(difflib.unified_diff(input_content, output_content, lineterm = ""))
print(f"DIFF for {path}:\n{unidiff}")
def diff_fmt_result(rule_runner: RuleRunner, fmt_result: FmtResult) -> None:
input_digest_contents = {
fc.path: fc.content for fc in rule_runner.request(DigestContents, [fmt_result.input])
}
input_digest_entries = rule_runner.request(DigestEntries, [fmt_result.input])
print(f"input_digest_contents = {input_digest_contents}")
print(f"input entries = {input_digest_entries}")
print(f"input files = {','.join(sorted(input_digest_contents.keys()))}")
output_digest_contents = {
fc.path: fc.content for fc in rule_runner.request(DigestContents, [fmt_result.output])
}
output_digest_entries = rule_runner.request(DigestEntries, [fmt_result.output])
print(f"output_digest_contents = {output_digest_contents}")
print(f"output entries = {output_digest_entries}")
print(f"output files = {','.join(sorted(output_digest_contents.keys()))}")
for path, input_fc in input_digest_contents.items():
output_fc = output_digest_contents[path]
input_content = input_fc.decode().splitlines()
output_content = output_fc.decode().splitlines()
unidiff = "\n".join(difflib.unified_diff(input_content, output_content, lineterm=""))
print(f"DIFF for {path}:\n{unidiff}")
bitter-ability-32190
02/23/2022, 5:45 PMlogger.error(f"{[file_content.path for file_content in digest_contents if file_content.content != maybe_add_copyright(file_content.content)]}")
bitter-ability-32190
02/23/2022, 5:45 PMfast-nail-55400
02/23/2022, 5:46 PMmaybe_add_copyright
function look like?bitter-ability-32190
02/23/2022, 5:46 PMdef maybe_add_copyright(content: bytes) -> bytes:
if not has_copyright(content):
return COPYRIGHT_HEADER.encode() + content
return content
bitter-ability-32190
02/23/2022, 5:46 PMhundreds-father-404
02/23/2022, 5:47 PMhundreds-father-404
02/23/2022, 5:47 PMfast-nail-55400
02/23/2022, 5:48 PMdiff_fmt_result
that I pasted might be useful. (although you need to add QueryRule’s to your RuleRunner for that calls it makes.)bitter-ability-32190
02/23/2022, 5:55 PMhundreds-father-404
02/23/2022, 5:56 PMbitter-ability-32190
02/23/2022, 5:56 PMbitter-ability-32190
02/23/2022, 5:56 PMbitter-ability-32190
02/23/2022, 5:57 PMfast-nail-55400
02/23/2022, 5:59 PM--no-pantsd
to avoid the rule memoizationhundreds-father-404
02/23/2022, 5:59 PM--no-local-cache --no-pantsd
bitter-ability-32190
02/23/2022, 6:01 PMbitter-ability-32190
02/23/2022, 6:01 PMbitter-ability-32190
02/23/2022, 6:09 PMis_executable=os.stat(file_content.path).st_mode % 2 == 1
bitter-ability-32190
02/23/2022, 6:09 PMfast-nail-55400
02/23/2022, 6:10 PMfast-nail-55400
02/23/2022, 6:11 PMis_executable
over from the original FileContent
?fast-nail-55400
02/23/2022, 6:12 PMdataclasses.replace(file_content, content=maybe_add_copyright(file_content.content))
fast-nail-55400
02/23/2022, 6:12 PMcontent
on file_content
bitter-ability-32190
02/23/2022, 6:14 PMbitter-ability-32190
02/23/2022, 6:17 PMbitter-ability-32190
02/23/2022, 7:40 PMhundreds-father-404
02/23/2022, 7:41 PMchmod -x
when calling Workspace.write_digest()
fast-nail-55400
02/23/2022, 7:42 PMfast-nail-55400
02/23/2022, 7:43 PMFileContent
is eventually turned into a REAPI FileNode
which has is_executable
as a field. different value => different digestbitter-ability-32190
02/23/2022, 7:45 PMfast-nail-55400
02/23/2022, 7:46 PMis_executable
and none of the rest of the modefast-nail-55400
02/23/2022, 7:50 PMNodeProperties
proto, but Pants does not do that)