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

feat(Python): Format docstrings #586

Merged
merged 2 commits into from
Sep 17, 2024
Merged
Show file tree
Hide file tree
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
Original file line number Diff line number Diff line change
Expand Up @@ -338,6 +338,7 @@ public void customizeAfterIntegrations(CustomizeDirective<GenerationContext, Pyt
CodegenUtils.runCommand("python3 " + file, fileManifest.getBaseDir());
}
formatCode(fileManifest);
formatDocstrings(fileManifest);
runMypy(fileManifest);
}

Expand All @@ -352,6 +353,17 @@ private void formatCode(FileManifest fileManifest) {
CodegenUtils.runCommand("python3 -m black . --exclude \"\"", fileManifest.getBaseDir());
}

private void formatDocstrings(FileManifest fileManifest) {
try {
CodegenUtils.runCommand("python3 -m docformatter -h", fileManifest.getBaseDir());
} catch (CodegenException e) {
LOGGER.warning("Unable to find the python package docformatter. Skipping formatting.");
return;
}
LOGGER.info("Running docformatter on generated code");
CodegenUtils.runCommand("python3 -m docformatter --recursive .", fileManifest.getBaseDir());
}

private void runMypy(FileManifest fileManifest) {
try {
CodegenUtils.runCommand("python3 -m mypy -h", fileManifest.getBaseDir());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -374,13 +374,6 @@ protected void writeFromDict(boolean isError) {
() -> {
writer.writeDocs(() -> {
writer.write("Creates a $L from a dictionary.\n", shapeName);
writer.write(
Copy link
Contributor

Choose a reason for hiding this comment

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

This is unrelated removal of comments that weren't supposed to be user-facing in the first place?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This comment is inaccurate for Python codegen (and is inaccurate for Smithy-Python codegen).

  • Formatting according to docstring note: SomeMemberName
    • This is the "boto3" formatting.
  • Actual Smithy-Python formatting: someMemberName
  • Smithy-Dafny Python formatting: some_member_name

writer.formatDocs(
"""
The dictionary is expected to use the modeled shape names rather \
than the parameter names as keys to be mostly compatible with boto3."""
)
);
});

if (shape.members().isEmpty() && !isError) {
Expand Down Expand Up @@ -523,13 +516,6 @@ protected void writeAsDict(boolean isError) {
"Converts the $L to a dictionary.\n",
symbolProvider.toSymbol(shape).getName()
);
writer.write(
writer.formatDocs(
"""
The dictionary uses the modeled shape names rather than the parameter names \
as keys to be mostly compatible with boto3."""
)
);
});

// If there aren't any optional members, it's best to return immediately.
Expand Down
Loading