Skip to content

Commit fdcc69b

Browse files
committed
Rename Config and Plugin to service-specific names
1 parent c337791 commit fdcc69b

8 files changed

Lines changed: 87 additions & 16 deletions

File tree

codegen/aws/core/src/main/java/software/amazon/smithy/python/aws/codegen/AwsUserAgentIntegration.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ public List<RuntimeClientPlugin> getClientPlugins(GenerationContext context) {
9797
moduleName + ".",
9898
writer -> {
9999
writer.write(USER_AGENT_PLUGIN,
100-
CodegenUtils.getConfigSymbol(c.settings()),
100+
CodegenUtils.getConfigSymbol(c.settings(), c.model()),
101101
userAgentInterceptor,
102102
versionSymbol,
103103
serviceId);

codegen/core/src/main/java/software/amazon/smithy/python/codegen/ClientGenerator.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,8 @@ public void run() {
5050

5151
private void generateService(PythonWriter writer) {
5252
var serviceSymbol = symbolProvider.toSymbol(service);
53-
var configSymbol = CodegenUtils.getConfigSymbol(context.settings());
54-
var pluginSymbol = CodegenUtils.getPluginSymbol(context.settings());
53+
var configSymbol = CodegenUtils.getConfigSymbol(context.settings(), context.model());
54+
var pluginSymbol = CodegenUtils.getPluginSymbol(context.settings(), context.model());
5555
writer.addLogger();
5656

5757
writer.openBlock("class $L:", "", serviceSymbol.getName(), () -> {
@@ -134,7 +134,7 @@ private void writeConstructorDocs(PythonWriter writer, String clientName) {
134134
private void generateOperation(PythonWriter writer, OperationShape operation) {
135135
var operationSymbol = symbolProvider.toSymbol(operation);
136136
var operationMethodSymbol = operationSymbol.expectProperty(OPERATION_METHOD);
137-
var pluginSymbol = CodegenUtils.getPluginSymbol(context.settings());
137+
var pluginSymbol = CodegenUtils.getPluginSymbol(context.settings(), context.model());
138138

139139
var input = model.expectShape(operation.getInputShape());
140140
var inputSymbol = symbolProvider.toSymbol(input);
@@ -219,7 +219,7 @@ private void writeSharedOperationInit(
219219
writer.addStdlibImport("copy", "deepcopy");
220220

221221
writer.write("""
222-
operation_plugins: list[Plugin] = [
222+
operation_plugins: list[${plugin:T}] = [
223223
$C
224224
]
225225
if plugins:
@@ -259,7 +259,7 @@ private void generateEventStreamOperation(PythonWriter writer, OperationShape op
259259
writer.putContext("operation", operationSymbol);
260260
var operationMethodSymbol = operationSymbol.expectProperty(OPERATION_METHOD);
261261
writer.putContext("operationName", operationMethodSymbol.getName());
262-
var pluginSymbol = CodegenUtils.getPluginSymbol(context.settings());
262+
var pluginSymbol = CodegenUtils.getPluginSymbol(context.settings(), context.model());
263263
writer.putContext("plugin", pluginSymbol);
264264

265265
var input = model.expectShape(operation.getInputShape());

codegen/core/src/main/java/software/amazon/smithy/python/codegen/CodegenUtils.java

Lines changed: 27 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
import java.util.logging.Logger;
2727
import software.amazon.smithy.codegen.core.CodegenException;
2828
import software.amazon.smithy.codegen.core.Symbol;
29+
import software.amazon.smithy.aws.traits.ServiceTrait;
2930
import software.amazon.smithy.model.Model;
3031
import software.amazon.smithy.model.knowledge.NullableIndex;
3132
import software.amazon.smithy.model.node.Node;
@@ -63,24 +64,46 @@ public final class CodegenUtils {
6364
private CodegenUtils() {}
6465

6566
/**
67+
* Gets the configuration object symbol for the service.
68+
*
69+
* <p>For AWS services with a {@code ServiceTrait}, this derives the name from the SDK ID
70+
* (e.g., "Bedrock Runtime" becomes "BedrockRuntimeConfig"). For services without a
71+
* {@code ServiceTrait}, falls back to the generic "Config" name.
72+
*
6673
* @param settings The client settings, used to account for module configuration.
74+
* @param model The model containing the service shape.
6775
* @return Returns the client's configuration object symbol.
6876
*/
69-
public static Symbol getConfigSymbol(PythonSettings settings) {
77+
public static Symbol getConfigSymbol(PythonSettings settings, Model model) {
78+
var service = settings.service(model);
79+
var name = service.getTrait(ServiceTrait.class)
80+
.map(trait -> StringUtils.capitalize(trait.getSdkId()).replace(" ", "") + "Config")
81+
.orElse("Config");
7082
return Symbol.builder()
71-
.name("Config")
83+
.name(name)
7284
.namespace(String.format("%s.config", settings.moduleName()), ".")
7385
.definitionFile(String.format("./src/%s/config.py", settings.moduleName()))
7486
.build();
7587
}
7688

7789
/**
90+
* Gets the plugin type hint symbol for the service.
91+
*
92+
* <p>For AWS services with a {@code ServiceTrait}, this derives the name from the SDK ID
93+
* (e.g., "Bedrock Runtime" becomes "BedrockRuntimePlugin"). For services without a
94+
* {@code ServiceTrait}, falls back to the generic "Plugin" name.
95+
*
7896
* @param settings The client settings, used to account for module configuration.
97+
* @param model The model containing the service shape.
7998
* @return Returns the client's plugin type hint symbol.
8099
*/
81-
public static Symbol getPluginSymbol(PythonSettings settings) {
100+
public static Symbol getPluginSymbol(PythonSettings settings, Model model) {
101+
var service = settings.service(model);
102+
var name = service.getTrait(ServiceTrait.class)
103+
.map(trait -> StringUtils.capitalize(trait.getSdkId()).replace(" ", "") + "Plugin")
104+
.orElse("Plugin");
82105
return Symbol.builder()
83-
.name("Plugin")
106+
.name(name)
84107
.namespace(String.format("%s.config", settings.moduleName()), ".")
85108
.definitionFile(String.format("./src/%s/config.py", settings.moduleName()))
86109
.build();

codegen/core/src/main/java/software/amazon/smithy/python/codegen/HttpProtocolTestGenerator.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,7 @@ private void generateRequestTest(OperationShape operation, HttpRequestTestCase t
192192
${C|}
193193
)
194194
""",
195-
CodegenUtils.getConfigSymbol(context.settings()),
195+
CodegenUtils.getConfigSymbol(context.settings(), context.model()),
196196
host,
197197
path,
198198
REQUEST_TEST_ASYNC_HTTP_CLIENT_SYMBOL,
@@ -453,7 +453,7 @@ private void generateResponseTest(OperationShape operation, HttpResponseTestCase
453453
${C|}
454454
)
455455
""",
456-
CodegenUtils.getConfigSymbol(context.settings()),
456+
CodegenUtils.getConfigSymbol(context.settings(), context.model()),
457457
RESPONSE_TEST_ASYNC_HTTP_CLIENT_SYMBOL,
458458
testCase.getCode(),
459459
CodegenUtils.toTuples(testCase.getHeaders()),
@@ -508,7 +508,7 @@ private void generateErrorResponseTest(
508508
${C|}
509509
)
510510
""",
511-
CodegenUtils.getConfigSymbol(context.settings()),
511+
CodegenUtils.getConfigSymbol(context.settings(), context.model()),
512512
RESPONSE_TEST_ASYNC_HTTP_CLIENT_SYMBOL,
513513
testCase.getCode(),
514514
CodegenUtils.toTuples(testCase.getHeaders()),

codegen/core/src/main/java/software/amazon/smithy/python/codegen/generators/ConfigGenerator.java

Lines changed: 39 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -261,21 +261,57 @@ private static void writeDefaultAuthSchemes(GenerationContext context, PythonWri
261261

262262
@Override
263263
public void run() {
264-
var config = CodegenUtils.getConfigSymbol(context.settings());
264+
var model = context.model();
265+
var config = CodegenUtils.getConfigSymbol(context.settings(), model);
266+
var genericConfigName = "Config";
265267
context.writerDelegator().useFileWriter(config.getDefinitionFile(), config.getNamespace(), writer -> {
266268
writeInterceptorsType(writer);
267269
generateConfig(context, writer);
270+
271+
// Generate deprecated Config alias if name differs from the generic name
272+
if (!config.getName().equals(genericConfigName)) {
273+
writer.addStdlibImport("warnings", "warn");
274+
writer.addStdlibImport("typing", "Any");
275+
writer.write("""
276+
277+
278+
class $1L($2L):
279+
\"""Deprecated: Use :class:`$2L` instead.\"""
280+
281+
def __init__(self, *args: Any, **kwargs: Any):
282+
warn(
283+
"Importing '$1L' is deprecated. Use '$2L' instead.",
284+
DeprecationWarning,
285+
stacklevel=2,
286+
)
287+
super().__init__(*args, **kwargs)
288+
""",
289+
genericConfigName,
290+
config.getName());
291+
}
268292
});
269293

270294
// Generate the plugin symbol. This is just a callable. We could do something
271295
// like have a class to implement, but that seems unnecessarily burdensome for
272296
// a single function.
273-
var plugin = CodegenUtils.getPluginSymbol(context.settings());
297+
var plugin = CodegenUtils.getPluginSymbol(context.settings(), model);
298+
var genericPluginName = "Plugin";
274299
context.writerDelegator().useFileWriter(plugin.getDefinitionFile(), plugin.getNamespace(), writer -> {
275300
writer.addStdlibImport("typing", "Callable");
276301
writer.addStdlibImport("typing", "TypeAlias");
277302
writer.write("$L: TypeAlias = Callable[[$T], None]", plugin.getName(), config);
278303
writer.writeDocs("A callable that allows customizing the config object on each request.", context);
304+
305+
// Generate deprecated Plugin alias if name differs from the generic name
306+
if (!plugin.getName().equals(genericPluginName)) {
307+
writer.write("""
308+
309+
$1L: TypeAlias = $2L
310+
\"""Deprecated: Use :data:`$2L` instead.\"""
311+
""",
312+
genericPluginName,
313+
plugin.getName());
314+
}
279315
});
280316
}
281317

@@ -308,7 +344,7 @@ private void writeInterceptorsType(PythonWriter writer) {
308344
}
309345

310346
private void generateConfig(GenerationContext context, PythonWriter writer) {
311-
var configSymbol = CodegenUtils.getConfigSymbol(context.settings());
347+
var configSymbol = CodegenUtils.getConfigSymbol(context.settings(), context.model());
312348

313349
// Initialize a set of config properties with our base properties.
314350
var properties = new TreeSet<>(Comparator.comparing(ConfigProperty::name));
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"type": "breaking",
3+
"description": "Renamed generated Config to <ServiceName>Config and Plugin to <ServiceName>Plugin. Deprecated aliases are provided."
4+
}
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"type": "breaking",
3+
"description": "Renamed generated Config to <ServiceName>Config and Plugin to <ServiceName>Plugin. Deprecated aliases are provided."
4+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"type": "breaking",
3+
"description": "Renamed generated Config to <ServiceName>Config and Plugin to <ServiceName>Plugin. Deprecated aliases are provided."
4+
}

0 commit comments

Comments
 (0)