diff --git a/codegen/core/src/main/java/software/amazon/smithy/python/codegen/SmithyPythonDependency.java b/codegen/core/src/main/java/software/amazon/smithy/python/codegen/SmithyPythonDependency.java index a09293113..0e1a456e1 100644 --- a/codegen/core/src/main/java/software/amazon/smithy/python/codegen/SmithyPythonDependency.java +++ b/codegen/core/src/main/java/software/amazon/smithy/python/codegen/SmithyPythonDependency.java @@ -39,6 +39,24 @@ public final class SmithyPythonDependency { Type.DEPENDENCY, false); + /** + * The awscrt package. + */ + public static final PythonDependency AWS_CRT = new PythonDependency( + "awscrt", + ">=0.23.10", + Type.DEPENDENCY, + false); + + /** + * The aiohttp package. + */ + public static final PythonDependency AIO_HTTP = new PythonDependency( + "aiohttp", + "~=3", + Type.DEPENDENCY, + false); + /** * The core smithy-json python package. */ diff --git a/codegen/core/src/main/java/software/amazon/smithy/python/codegen/generators/ConfigGenerator.java b/codegen/core/src/main/java/software/amazon/smithy/python/codegen/generators/ConfigGenerator.java index 1d120d6d9..6d7f107ae 100644 --- a/codegen/core/src/main/java/software/amazon/smithy/python/codegen/generators/ConfigGenerator.java +++ b/codegen/core/src/main/java/software/amazon/smithy/python/codegen/generators/ConfigGenerator.java @@ -138,7 +138,8 @@ private static List getHttpProperties(GenerationContext context) if (usesHttp2(context)) { clientBuilder .initialize(writer -> { - writer.addDependency(SmithyPythonDependency.SMITHY_HTTP.withOptionalDependencies("awscrt")); + writer.addDependency(SmithyPythonDependency.SMITHY_HTTP); + writer.addDependency(SmithyPythonDependency.AWS_CRT); writer.addImport("smithy_http.aio.crt", "AWSCRTHTTPClient"); writer.write("self.http_client = http_client or AWSCRTHTTPClient()"); }); @@ -146,7 +147,8 @@ private static List getHttpProperties(GenerationContext context) } else { clientBuilder .initialize(writer -> { - writer.addDependency(SmithyPythonDependency.SMITHY_HTTP.withOptionalDependencies("aiohttp")); + writer.addDependency(SmithyPythonDependency.SMITHY_HTTP); + writer.addDependency(SmithyPythonDependency.AIO_HTTP); writer.addImport("smithy_http.aio.aiohttp", "AIOHTTPClient"); writer.write("self.http_client = http_client or AIOHTTPClient()"); }); @@ -171,11 +173,12 @@ private static boolean usesHttp2(GenerationContext context) { return true; } - // Bidirectional streaming REQUIRES h2 inherently + // enable CRT/http2 client if the service supports any event streams (single or bi-directional) + // TODO: Long term, only bi-directional evenstreams strictly require h2 var eventIndex = EventStreamIndex.of(context.model()); var topDownIndex = TopDownIndex.of(context.model()); for (OperationShape operation : topDownIndex.getContainedOperations(context.settings().service())) { - if (eventIndex.getInputInfo(operation).isPresent() && eventIndex.getOutputInfo(operation).isPresent()) { + if (eventIndex.getInputInfo(operation).isPresent() || eventIndex.getOutputInfo(operation).isPresent()) { return true; } }