Skip to content
Open
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 @@ -168,8 +168,7 @@ private void writeSharedOperationInit(PythonWriter writer, OperationShape operat
writer.write("""
:param plugins: A list of callables that modify the configuration dynamically.
Changes made by these plugins only apply for the duration of the operation
execution and will not affect any other operation invocations.
""");
execution and will not affect any other operation invocations.""");

});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -345,10 +345,7 @@ def __init__(
*,
${C|}
):
\"""Constructor.

${C|}
\"""
${C|}
""",
configSymbol.getName(),
Expand Down Expand Up @@ -376,17 +373,20 @@ private void writeInitParams(PythonWriter writer, Collection<ConfigProperty> pro
}

private void documentProperties(PythonWriter writer, Collection<ConfigProperty> properties) {
var iter = properties.iterator();
while (iter.hasNext()) {
var property = iter.next();
var docs = writer.formatDocs(String.format(":param %s: %s", property.name(), property.documentation()));
writer.writeDocs(() ->{
var iter = properties.iterator();
writer.write("\nConstructor.\n");
while (iter.hasNext()) {
var property = iter.next();
var docs = writer.formatDocs(String.format(":param %s: %s", property.name(), property.documentation()));

if (iter.hasNext()) {
docs += "\n";
}

if (iter.hasNext()) {
docs += "\n";
writer.write(docs);
}

writer.write(docs);
}
});
}

private void initializeProperties(PythonWriter writer, Collection<ConfigProperty> properties) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.Set;
import java.util.stream.Collectors;
import software.amazon.smithy.python.codegen.GenerationContext;
import software.amazon.smithy.utils.SmithyInternalApi;
Expand All @@ -15,6 +16,8 @@
*/
@SmithyInternalApi
public final class InitGenerator implements Runnable {
// Set of directories that need __init__.py files
private static final Set<String> PACKAGE_DIRECTORIES = Set.of("src", "tests");

private final GenerationContext context;

Expand All @@ -31,6 +34,7 @@ public void run() {
.stream()
.map(Paths::get)
.filter(path -> !path.getParent().equals(context.fileManifest().getBaseDir()))
.filter(path -> PACKAGE_DIRECTORIES.contains(path.getName(0).toString()))
.collect(Collectors.groupingBy(Path::getParent, Collectors.toSet()));
for (var entry : directories.entrySet()) {
var initPath = entry.getKey().resolve("__init__.py");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,8 @@ private void writeProperties() {
${?useField}\
field(${?sensitive}repr=False, ${/sensitive}${defaultKey:L}=${defaultValue:L})\
${/useField}
${?docs}""\"${docs:L}""\"${/docs}""", memberName, symbolProvider.toSymbol(member));
${?docs}""\"${docs:L}""\"${/docs}
""", memberName, symbolProvider.toSymbol(member));
writer.popState();
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,8 @@ public PythonWriter writeDocs(Runnable runnable) {
pushState();
writeInline("\"\"\"");
runnable.run();
trimTrailingWhitespaces();
ensureNewline();
write("\"\"\"");
popState();
return this;
Expand All @@ -143,6 +145,35 @@ public PythonWriter writeDocs(String docs) {
return this;
}

/**
* Trims all trailing whitespace from the writer buffer.
*
* @return Returns the writer.
*/
public PythonWriter trimTrailingWhitespaces() {
// Disable the writer formatting config to ensure toString()
// returns the unmodified state of the underlying StringBuilder
trimBlankLines(-1);
trimTrailingSpaces(false);

String current = super.toString();
int end = current.length() - 1;
while (end >= 0 && Character.isWhitespace(current.charAt(end))) {
end--;
}

String trailing = current.substring(end + 1);
if (!trailing.isEmpty()) {
unwrite(trailing);
}

// Re-enable the formatting config
trimBlankLines();
trimTrailingSpaces(true);

return this;
}

private static final int MAX_LINE_LENGTH = CodegenUtils.MAX_PREFERRED_LINE_LENGTH - 8;

/**
Expand Down
Loading