Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FmtResult now operates on Snapshots #14865

Merged
merged 2 commits into from
Mar 22, 2022
Merged

Conversation

thejcannon
Copy link
Member

In order to handle the upcoming change to "unify" both fmt and lint processes for formatters, we need to have the message of FmtResult be based on a diff of 2 Snapshots. Since message can't participate in async/await, we need to change FmtResult so it already has those snapshots available (namely input and output).

This is unfortunately boilerplate for the callers, but that can potentially be cleaned up later a myriad of ways.

This also should be essentially no overhead as fmt.py was already doing this query (although it was doing it conditionally. I suspect doing it unconditionally will have very little impact on perf because this is guaranteed to be cached if the output digest differs from the input).

[ci skip-rust]

# Rust tests and lints will be skipped. Delete if not intended.
[ci skip-rust]

# Building wheels and fs_util will be skipped. Delete if not intended.
[ci skip-build-wheels]
Copy link
Member

@stuhood stuhood left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

Comment on lines +90 to +96
output_snapshot = await Get(Snapshot, Digest, result.output_digest)
return FmtResult(
setup.original_snapshot,
output_snapshot,
stdout=result.stdout.decode(),
stderr=result.stderr.decode(),
formatter_name=request.name,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would probably still be good to have the helper method take the result so that it can decode the stdout/stderr for you at the least (although obviously a bit redundant that the Snapshot needs to be precalculated... could validate that the argument Snapshot has a Digest equal to the result's Digest...?)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The stdout/stderr isn't always decoded. Sometimes it is passed through strip_v2_chroot. See

stdout=strip_v2_chroot_path(result.stdout),

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure, but whether that happened used to be handled by the optional strip_chroot_path=True, param. Fine either way though.

src/python/pants/core/goals/fmt_test.py Outdated Show resolved Hide resolved
@thejcannon thejcannon merged commit dac2076 into pantsbuild:main Mar 22, 2022
@thejcannon thejcannon deleted the snapshotty branch March 22, 2022 16:01
@Eric-Arellano
Copy link
Contributor

I think it'd be good to add back the classmethod. It's meant to help with DRY and seems like removing it results in unnecessary churn for plugin others. Bump on the strip_chroot_path=True kwarg

@thejcannon
Copy link
Member Author

I think it'd be good to add back the classmethod. It's meant to help with DRY and seems like removing it results in unnecessary churn for plugin others. Bump on the strip_chroot_path=True kwarg

I'm not sure it'd really DRY that much, but I could be in the minority. Instead I think a rule.helper a la #14238 could elide the await for the snapshot and then be truly DRY.

FmtResult(
        setup.original_snapshot,
        output_snapshot,
        stdout=result.stdout.decode(),
        stderr=result.stderr.decode(),
        formatter_name=request.name,
)
# vs
FmtResult.from_process_result(
        result,
        original_snapshot=setup.original_snapshot,
        output_snapshot=output_snapshot,
        formatter_name=request.name,
        # strip_chroot_path=True  # optional
)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants