Skip to content
Closed
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
2 changes: 1 addition & 1 deletion codegen-output/aws-json-1-0/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@

## Sample Json 1.0 Protocol Service Client

awsjson10 client
Python client for Sample Json 1.0 Protocol Service
2 changes: 1 addition & 1 deletion codegen-output/aws-json-1-0/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
[project]
name = "awsjson10"
version = "0.0.1"
description = "awsjson10 client"
description = "Python client for Sample Json 1.0 Protocol Service"
readme = "README.md"
requires-python = ">=3.12"
keywords = ["smithy", "awsjson10"]
Expand Down
2 changes: 1 addition & 1 deletion codegen-output/aws-json-1-1/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@

## Sample Json 1.1 Protocol Service Client

awsjson11 client
Python client for Sample Json 1.1 Protocol Service
2 changes: 1 addition & 1 deletion codegen-output/aws-json-1-1/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
[project]
name = "awsjson11"
version = "0.0.1"
description = "awsjson11 client"
description = "Python client for Sample Json 1.1 Protocol Service"
readme = "README.md"
requires-python = ">=3.12"
keywords = ["smithy", "awsjson11"]
Expand Down
2 changes: 1 addition & 1 deletion codegen-output/aws-query/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

## Sample Query Protocol Service Client

awsquery client
Python client for Sample Query Protocol Service

### Documentation

Expand Down
2 changes: 1 addition & 1 deletion codegen-output/aws-query/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
[project]
name = "awsquery"
version = "0.0.1"
description = "awsquery client"
description = "Python client for Sample Query Protocol Service"
readme = "README.md"
requires-python = ">=3.12"
keywords = ["smithy", "awsquery"]
Expand Down
2 changes: 1 addition & 1 deletion codegen-output/ec2-query/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

## Sample Ec2 Protocol Service Client

ec2query client
Python client for Sample Ec2 Protocol Service

### Documentation

Expand Down
2 changes: 1 addition & 1 deletion codegen-output/ec2-query/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
[project]
name = "ec2query"
version = "0.0.1"
description = "ec2query client"
description = "Python client for Sample Ec2 Protocol Service"
readme = "README.md"
requires-python = ">=3.12"
keywords = ["smithy", "ec2query"]
Expand Down
2 changes: 1 addition & 1 deletion codegen-output/my-handwritten-model/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@

## My Handwritten Model Client

my_handwritten_model client
Python client for My Handwritten Model
2 changes: 1 addition & 1 deletion codegen-output/my-handwritten-model/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
[project]
name = "my_handwritten_model"
version = "0.0.1"
description = "my_handwritten_model client"
description = "Python client for My Handwritten Model"
readme = "README.md"
requires-python = ">=3.12"
keywords = ["smithy", "my_handwritten_model"]
Expand Down
2 changes: 1 addition & 1 deletion codegen-output/non-query-compatible-rpcv2-cbor/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@

## Non Query Compatible RpcV2 Protocol Service Client

nonquerycompatiblerpcv2cbor client
Python client for Non Query Compatible RpcV2 Protocol Service
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
[project]
name = "nonquerycompatiblerpcv2cbor"
version = "0.0.1"
description = "nonquerycompatiblerpcv2cbor client"
description = "Python client for Non Query Compatible RpcV2 Protocol Service"
readme = "README.md"
requires-python = ">=3.12"
keywords = ["smithy", "nonquerycompatiblerpcv2cbor"]
Expand Down
2 changes: 1 addition & 1 deletion codegen-output/query-compatible-aws-json-1-0/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@

## Query Compatible Json 1.0 Protocol Service Client

querycompatibleawsjson10 client
Python client for Query Compatible Json 1.0 Protocol Service
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
[project]
name = "querycompatibleawsjson10"
version = "0.0.1"
description = "querycompatibleawsjson10 client"
description = "Python client for Query Compatible Json 1.0 Protocol Service"
readme = "README.md"
requires-python = ">=3.12"
keywords = ["smithy", "querycompatibleawsjson10"]
Expand Down
2 changes: 1 addition & 1 deletion codegen-output/query-compatible-rpcv2-cbor/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@

## Query Compatible RpcV2 Protocol Service Client

querycompatiblerpcv2cbor client
Python client for Query Compatible RpcV2 Protocol Service
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
[project]
name = "querycompatiblerpcv2cbor"
version = "0.0.1"
description = "querycompatiblerpcv2cbor client"
description = "Python client for Query Compatible RpcV2 Protocol Service"
readme = "README.md"
requires-python = ">=3.12"
keywords = ["smithy", "querycompatiblerpcv2cbor"]
Expand Down
2 changes: 1 addition & 1 deletion codegen-output/rest-json-1/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@

## Sample Rest Json Protocol Service Client

restjson client
Python client for Sample Rest Json Protocol Service
2 changes: 1 addition & 1 deletion codegen-output/rest-json-1/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
[project]
name = "restjson"
version = "0.0.1"
description = "restjson client"
description = "Python client for Sample Rest Json Protocol Service"
readme = "README.md"
requires-python = ">=3.12"
keywords = ["smithy", "restjson"]
Expand Down
2 changes: 1 addition & 1 deletion codegen-output/rest-xml-with-namespace/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

## Sample Rest Xml Protocol Service With Namespace Client

restxmlwithnamespace client
Python client for Sample Rest Xml Protocol Service With Namespace

### Documentation

Expand Down
2 changes: 1 addition & 1 deletion codegen-output/rest-xml-with-namespace/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
[project]
name = "restxmlwithnamespace"
version = "0.0.1"
description = "restxmlwithnamespace client"
description = "Python client for Sample Rest Xml Protocol Service With Namespace"
readme = "README.md"
requires-python = ">=3.12"
keywords = ["smithy", "restxmlwithnamespace"]
Expand Down
2 changes: 1 addition & 1 deletion codegen-output/rest-xml/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

## Sample Rest Xml Protocol Service Client

restxml client
Python client for Sample Rest Xml Protocol Service

### Documentation

Expand Down
2 changes: 1 addition & 1 deletion codegen-output/rest-xml/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
[project]
name = "restxml"
version = "0.0.1"
description = "restxml client"
description = "Python client for Sample Rest Xml Protocol Service"
readme = "README.md"
requires-python = ">=3.12"
keywords = ["smithy", "restxml"]
Expand Down
2 changes: 1 addition & 1 deletion codegen-output/rpcv2-cbor/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@

## RpcV2 Protocol Service Client

rpcv2cbor client
Python client for RpcV2 Protocol Service
2 changes: 1 addition & 1 deletion codegen-output/rpcv2-cbor/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
[project]
name = "rpcv2cbor"
version = "0.0.1"
description = "rpcv2cbor client"
description = "Python client for RpcV2 Protocol Service"
readme = "README.md"
requires-python = ">=3.12"
keywords = ["smithy", "rpcv2cbor"]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
package software.amazon.smithy.python.codegen;

import java.util.Arrays;
import java.util.Locale;
import java.util.Objects;
import software.amazon.smithy.codegen.core.CodegenException;
import software.amazon.smithy.model.Model;
Expand Down Expand Up @@ -56,9 +55,8 @@ private PythonSettings(Builder builder) {
builder.service,
builder.moduleName,
builder.moduleVersion,
StringUtils.isBlank(builder.moduleDescription)
? builder.moduleName + " " + builder.artifactType.name().toLowerCase(Locale.ENGLISH)
: builder.moduleDescription,
// Unset descriptions stay empty; SetupGenerator resolves them from the service.
StringUtils.isBlank(builder.moduleDescription) ? "" : builder.moduleDescription,
builder.artifactType);
}

Expand Down Expand Up @@ -87,10 +85,9 @@ public ServiceShape service(Model model) {
public static PythonSettings fromNode(ObjectNode config) {
config.warnIfAdditionalProperties(Arrays.asList(SERVICE, MODULE_NAME, MODULE_DESCRIPTION, MODULE_VERSION));

String moduleName = config.expectStringMember(MODULE_NAME).getValue();
Builder builder = builder()
.service(config.expectStringMember(SERVICE).expectShapeId())
.moduleName(moduleName)
.moduleName(config.expectStringMember(MODULE_NAME).getValue())
.moduleVersion(config.expectStringMember(MODULE_VERSION).getValue());
config.getStringMember(MODULE_DESCRIPTION).map(StringNode::getValue).ifPresent(builder::moduleDescription);
return builder.build();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,24 @@ public static void generateSetup(
GenerationContext context
) {
var dependencies = gatherDependencies(context.writerDelegator().getDependencies().stream());
writePyproject(settings, context.writerDelegator(), dependencies);
writeReadme(settings, context);
var description = resolveDescription(settings, context);
writePyproject(settings, description, context.writerDelegator(), dependencies);
writeReadme(settings, description, context);
}

/**
* Use the configured description if set, otherwise describe the client or types
* package by the service's {@code smithy.api#title} trait or else the service shape's name.
*/
private static String resolveDescription(PythonSettings settings, GenerationContext context) {
if (!StringUtils.isBlank(settings.moduleDescription())) {
return settings.moduleDescription();
}
var service = context.model().expectShape(settings.service());
var artifact = settings.artifactType() == PythonSettings.ArtifactType.TYPES ? "types" : "client";
return "Python " + artifact + " for " + service.getTrait(TitleTrait.class)
.map(StringTrait::getValue)
.orElse(service.getId().getName());
}

/**
Expand Down Expand Up @@ -106,6 +122,7 @@ private static Map<String, Map<String, SymbolDependency>> gatherDependencies(
*/
private static void writePyproject(
PythonSettings settings,
String description,
WriterDelegator<PythonWriter> writers,
Map<String, Map<String, SymbolDependency>> dependencies
) {
Expand Down Expand Up @@ -139,7 +156,7 @@ private static void writePyproject(
"Programming Language :: Python :: 3.14",
"Programming Language :: Python :: 3.15"
]
""", settings.moduleName(), settings.moduleVersion(), settings.moduleDescription());
""", settings.moduleName(), settings.moduleVersion(), description);

Optional.ofNullable(dependencies.get(PythonDependency.Type.DEPENDENCY.getType())).ifPresent(deps -> {
writer.openBlock("dependencies = [", "]\n", () -> writeDependencyList(writer, deps.values()));
Expand Down Expand Up @@ -283,6 +300,7 @@ private static List<String> getOptionalDependencies(SymbolDependency dependency)

private static void writeReadme(
PythonSettings settings,
String description,
GenerationContext context
) {
var service = context.model().expectShape(settings.service());
Expand All @@ -292,17 +310,13 @@ private static void writeReadme(
.map(StringTrait::getValue)
.orElse(StringUtils.capitalize(settings.moduleName()));

var description = StringUtils.isBlank(settings.moduleDescription())
? "Generated service client for " + title
: StringUtils.wrap(settings.moduleDescription(), 80);

context.writerDelegator().useFileWriter("README.md", writer -> {
writer.pushState(new ReadmeSection());
writer.write("""
## $L Client

$L
""", title, description);
""", title, StringUtils.wrap(description, 80));

service.getTrait(DocumentationTrait.class).map(StringTrait::getValue).ifPresent(documentation -> {
writer.write("""
Expand Down
Loading
Loading