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

Support docformatter 1.6.0+ #18790

Merged
merged 1 commit into from
Apr 22, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 21 additions & 4 deletions src/python/pants/backend/python/lint/docformatter/rules.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,10 @@
from pants.backend.python.util_rules.pex import PexRequest, VenvPex, VenvPexProcess
from pants.core.goals.fmt import FmtResult, FmtTargetsRequest
from pants.core.util_rules.partitions import PartitionerType
from pants.engine.process import ProcessResult
from pants.engine.process import FallibleProcessResult, ProcessExecutionFailure
from pants.engine.rules import Get, collect_rules, rule
from pants.engine.target import FieldSet, Target
from pants.option.global_options import KeepSandboxes
from pants.util.logging import LogLevel
from pants.util.strutil import pluralize

Expand All @@ -36,11 +37,12 @@ class DocformatterRequest(FmtTargetsRequest):

@rule(desc="Format with docformatter", level=LogLevel.DEBUG)
async def docformatter_fmt(
request: DocformatterRequest.Batch, docformatter: Docformatter
request: DocformatterRequest.Batch, docformatter: Docformatter, keep_sandboxes: KeepSandboxes
) -> FmtResult:
docformatter_pex = await Get(VenvPex, PexRequest, docformatter.to_pex_request())
description = f"Run Docformatter on {pluralize(len(request.files), 'file')}."
result = await Get(
ProcessResult,
FallibleProcessResult,
VenvPexProcess(
docformatter_pex,
argv=(
Expand All @@ -50,10 +52,25 @@ async def docformatter_fmt(
),
input_digest=request.snapshot.digest,
output_files=request.files,
description=(f"Run Docformatter on {pluralize(len(request.files), 'file')}."),
description=description,
level=LogLevel.DEBUG,
),
)
# Docformatter 1.6.0+ very annoyingly returns an exit code of 3 if run with `--in-place`
# and any files changed. Earlier versions do not return this code in fmt mode.
# (All versions return 3 in check mode if any files would have changed, but that is
# not an issue here).
if result.exit_code not in [0, 3]:
# TODO(#12725):It would be more straightforward to force the exception with:
Copy link
Member

Choose a reason for hiding this comment

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

I don't get the reference to #12725

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ah, I cargo-culted that from other files that mentioned the inability to convert FallibleProcessResult to ProcessResult.

Yeah, I'm not 100% sure why that is the referenced PR.

Copy link
Member

Choose a reason for hiding this comment

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

also, I would expect the TODO to reference an open issue.. ;)

# result = await Get(ProcessResult, FallibleProcessResult, result)
raise ProcessExecutionFailure(
result.exit_code,
result.stdout,
result.stderr,
description,
keep_sandboxes=keep_sandboxes,
)

return await FmtResult.create(request, result)


Expand Down