From 4e7240e4e19a127d20ac14614e00c5b731bf2e3a Mon Sep 17 00:00:00 2001 From: Lucas McDonald Date: Mon, 7 Oct 2024 15:48:58 -0700 Subject: [PATCH 01/76] m --- ...irectedDafnyPythonLocalServiceCodegen.java | 33 +++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/codegen/smithy-dafny-codegen/src/main/java/software/amazon/polymorph/smithypython/localservice/extensions/DirectedDafnyPythonLocalServiceCodegen.java b/codegen/smithy-dafny-codegen/src/main/java/software/amazon/polymorph/smithypython/localservice/extensions/DirectedDafnyPythonLocalServiceCodegen.java index 423f5ee97..fd82d0b16 100644 --- a/codegen/smithy-dafny-codegen/src/main/java/software/amazon/polymorph/smithypython/localservice/extensions/DirectedDafnyPythonLocalServiceCodegen.java +++ b/codegen/smithy-dafny-codegen/src/main/java/software/amazon/polymorph/smithypython/localservice/extensions/DirectedDafnyPythonLocalServiceCodegen.java @@ -10,9 +10,12 @@ import software.amazon.polymorph.smithypython.common.nameresolver.SmithyNameResolver; import software.amazon.polymorph.smithypython.localservice.DafnyLocalServiceCodegenConstants; import software.amazon.polymorph.smithypython.localservice.customize.ReferencesFileWriter; +import software.amazon.polymorph.traits.LocalServiceTrait; import software.amazon.smithy.build.FileManifest; import software.amazon.smithy.codegen.core.*; import software.amazon.smithy.codegen.core.directed.*; +import software.amazon.smithy.model.shapes.ShapeId; +import software.amazon.smithy.model.shapes.StructureShape; import software.amazon.smithy.python.codegen.*; /** @@ -455,6 +458,36 @@ public void generateService( return; } + ShapeId configShapeId = directive.service().getTrait(LocalServiceTrait.class).get().getConfigId(); + StructureShape configShape = directive.model().expectShape(configShapeId).asStructureShape().get(); + + if ( + directive + .shape() + .getId() + .getNamespace() + .equals(directive.context().settings().getService().getNamespace()) + ) { + directive + .context() + .writerDelegator() + .useShapeWriter( + configShape, + writer -> { + DafnyPythonLocalServiceStructureGenerator generator = + new DafnyPythonLocalServiceStructureGenerator( + directive.model(), + directive.settings(), + directive.symbolProvider(), + writer, + configShape, + TopologicalIndex.of(directive.model()).getRecursiveShapes() + ); + generator.run(); + } + ); + } + protocolGenerator.generateSharedSerializerComponents(directive.context()); protocolGenerator.generateRequestSerializers(directive.context()); From bf0df254e7b82395c7c2e20c3def762af719752f Mon Sep 17 00:00:00 2001 From: Lucas McDonald Date: Mon, 7 Oct 2024 15:50:46 -0700 Subject: [PATCH 02/76] m --- ...irectedDafnyPythonLocalServiceCodegen.java | 52 ++++++++----------- 1 file changed, 22 insertions(+), 30 deletions(-) diff --git a/codegen/smithy-dafny-codegen/src/main/java/software/amazon/polymorph/smithypython/localservice/extensions/DirectedDafnyPythonLocalServiceCodegen.java b/codegen/smithy-dafny-codegen/src/main/java/software/amazon/polymorph/smithypython/localservice/extensions/DirectedDafnyPythonLocalServiceCodegen.java index fd82d0b16..928bfcf5b 100644 --- a/codegen/smithy-dafny-codegen/src/main/java/software/amazon/polymorph/smithypython/localservice/extensions/DirectedDafnyPythonLocalServiceCodegen.java +++ b/codegen/smithy-dafny-codegen/src/main/java/software/amazon/polymorph/smithypython/localservice/extensions/DirectedDafnyPythonLocalServiceCodegen.java @@ -453,39 +453,31 @@ public void generateService( new SynchronousClientGenerator(directive.context(), directive.service()) .run(); - var protocolGenerator = directive.context().protocolGenerator(); - if (protocolGenerator == null) { - return; - } - ShapeId configShapeId = directive.service().getTrait(LocalServiceTrait.class).get().getConfigId(); StructureShape configShape = directive.model().expectShape(configShapeId).asStructureShape().get(); - if ( - directive - .shape() - .getId() - .getNamespace() - .equals(directive.context().settings().getService().getNamespace()) - ) { - directive - .context() - .writerDelegator() - .useShapeWriter( - configShape, - writer -> { - DafnyPythonLocalServiceStructureGenerator generator = - new DafnyPythonLocalServiceStructureGenerator( - directive.model(), - directive.settings(), - directive.symbolProvider(), - writer, - configShape, - TopologicalIndex.of(directive.model()).getRecursiveShapes() - ); - generator.run(); - } - ); + directive + .context() + .writerDelegator() + .useShapeWriter( + configShape, + writer -> { + DafnyPythonLocalServiceStructureGenerator generator = + new DafnyPythonLocalServiceStructureGenerator( + directive.model(), + directive.settings(), + directive.symbolProvider(), + writer, + configShape, + TopologicalIndex.of(directive.model()).getRecursiveShapes() + ); + generator.run(); + } + ); + + var protocolGenerator = directive.context().protocolGenerator(); + if (protocolGenerator == null) { + return; } protocolGenerator.generateSharedSerializerComponents(directive.context()); From 689cee0932813e07f2f30fcfabc452245ae647ed Mon Sep 17 00:00:00 2001 From: Lucas McDonald Date: Mon, 7 Oct 2024 15:59:39 -0700 Subject: [PATCH 03/76] m --- ...PythonLocalServiceClientCodegenPlugin.java | 30 +++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/codegen/smithy-dafny-codegen/src/main/java/software/amazon/polymorph/smithypython/localservice/extensions/DafnyPythonLocalServiceClientCodegenPlugin.java b/codegen/smithy-dafny-codegen/src/main/java/software/amazon/polymorph/smithypython/localservice/extensions/DafnyPythonLocalServiceClientCodegenPlugin.java index c99824b2c..e7688e45c 100644 --- a/codegen/smithy-dafny-codegen/src/main/java/software/amazon/polymorph/smithypython/localservice/extensions/DafnyPythonLocalServiceClientCodegenPlugin.java +++ b/codegen/smithy-dafny-codegen/src/main/java/software/amazon/polymorph/smithypython/localservice/extensions/DafnyPythonLocalServiceClientCodegenPlugin.java @@ -10,6 +10,7 @@ import software.amazon.polymorph.utils.ModelUtils; import software.amazon.smithy.build.PluginContext; import software.amazon.smithy.build.SmithyBuildPlugin; +import software.amazon.smithy.codegen.core.TopologicalIndex; import software.amazon.smithy.codegen.core.directed.CodegenDirector; import software.amazon.smithy.model.Model; import software.amazon.smithy.model.shapes.AbstractShapeBuilder; @@ -106,6 +107,7 @@ public static Model transformModelForLocalService( serviceShape ); transformedModel = transformStringEnumShapesToEnumShapes(transformedModel); + transformedModel = transformServiceShapeToAddOrphanedShapes(transformedModel); return transformedModel; } @@ -188,6 +190,7 @@ public static Model transformServiceShapeToAddReferenceResources( .getReferentId(); if (model.expectShape(referenceShapeId).isResourceShape()) { transformedServiceShapeBuilder.addResource(referenceShapeId); + transformedServiceShapeBuilder.addMember() } } return shape; @@ -208,6 +211,33 @@ public static Model transformServiceShapeToAddReferenceResources( ); } + /** + * Smithy plugins require that resource shapes are attached to a ServiceShape. + * Smithy plugins also do not understand Polymorph's {@link ReferenceTrait} and will not + * discover the linked shape. + * This parses Polymorph's ReferenceTrait to attach any referenced resources to the {@param serviceShape} + * so the Smithy plugin's shape discovery can find the shape. + * @param model + * @return + */ + public static Model transformServiceShapeToAddOrphanedShapes( + Model model + ) { + ModelTransformer + .create() + .mapShapes( + model, + shape -> { + if (!TopologicalIndex.of(model).getRecursiveShapes().contains(shape)) { + System.out.println("not in: " + shape.getId()); + } + return shape; + } + ); + + return model; + } + /** * Replace any StringShapes with EnumTraits * with StringShapes. From 35427ab9e4bcd3ea90fbd401c2e320dcd3f13290 Mon Sep 17 00:00:00 2001 From: Lucas McDonald Date: Mon, 7 Oct 2024 16:00:22 -0700 Subject: [PATCH 04/76] m --- .../extensions/DafnyPythonLocalServiceClientCodegenPlugin.java | 1 - 1 file changed, 1 deletion(-) diff --git a/codegen/smithy-dafny-codegen/src/main/java/software/amazon/polymorph/smithypython/localservice/extensions/DafnyPythonLocalServiceClientCodegenPlugin.java b/codegen/smithy-dafny-codegen/src/main/java/software/amazon/polymorph/smithypython/localservice/extensions/DafnyPythonLocalServiceClientCodegenPlugin.java index e7688e45c..e32f7f931 100644 --- a/codegen/smithy-dafny-codegen/src/main/java/software/amazon/polymorph/smithypython/localservice/extensions/DafnyPythonLocalServiceClientCodegenPlugin.java +++ b/codegen/smithy-dafny-codegen/src/main/java/software/amazon/polymorph/smithypython/localservice/extensions/DafnyPythonLocalServiceClientCodegenPlugin.java @@ -190,7 +190,6 @@ public static Model transformServiceShapeToAddReferenceResources( .getReferentId(); if (model.expectShape(referenceShapeId).isResourceShape()) { transformedServiceShapeBuilder.addResource(referenceShapeId); - transformedServiceShapeBuilder.addMember() } } return shape; From 04bd5ec9ed7ad25c8b2a62f61b0d0121d45d602a Mon Sep 17 00:00:00 2001 From: Lucas McDonald Date: Mon, 7 Oct 2024 16:01:24 -0700 Subject: [PATCH 05/76] m --- .../DafnyPythonLocalServiceClientCodegenPlugin.java | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/codegen/smithy-dafny-codegen/src/main/java/software/amazon/polymorph/smithypython/localservice/extensions/DafnyPythonLocalServiceClientCodegenPlugin.java b/codegen/smithy-dafny-codegen/src/main/java/software/amazon/polymorph/smithypython/localservice/extensions/DafnyPythonLocalServiceClientCodegenPlugin.java index e32f7f931..f4c7edf52 100644 --- a/codegen/smithy-dafny-codegen/src/main/java/software/amazon/polymorph/smithypython/localservice/extensions/DafnyPythonLocalServiceClientCodegenPlugin.java +++ b/codegen/smithy-dafny-codegen/src/main/java/software/amazon/polymorph/smithypython/localservice/extensions/DafnyPythonLocalServiceClientCodegenPlugin.java @@ -107,7 +107,7 @@ public static Model transformModelForLocalService( serviceShape ); transformedModel = transformStringEnumShapesToEnumShapes(transformedModel); - transformedModel = transformServiceShapeToAddOrphanedShapes(transformedModel); + transformedModel = transformServiceShapeToAddOrphanedShapes(transformedModel, serviceShape); return transformedModel; } @@ -220,14 +220,16 @@ public static Model transformServiceShapeToAddReferenceResources( * @return */ public static Model transformServiceShapeToAddOrphanedShapes( - Model model + Model model, + ServiceShape serviceShape ) { ModelTransformer .create() .mapShapes( model, shape -> { - if (!TopologicalIndex.of(model).getRecursiveShapes().contains(shape)) { + if (!TopologicalIndex.of(model).getRecursiveShapes().contains(shape) + && shape.getId().getNamespace().equals(serviceShape.getId().getNamespace())) { System.out.println("not in: " + shape.getId()); } return shape; From 495ee9f66f5f3380f162eefb333b5e906d8d6271 Mon Sep 17 00:00:00 2001 From: Lucas McDonald Date: Mon, 7 Oct 2024 16:02:52 -0700 Subject: [PATCH 06/76] m --- .../extensions/DafnyPythonLocalServiceClientCodegenPlugin.java | 2 ++ 1 file changed, 2 insertions(+) diff --git a/codegen/smithy-dafny-codegen/src/main/java/software/amazon/polymorph/smithypython/localservice/extensions/DafnyPythonLocalServiceClientCodegenPlugin.java b/codegen/smithy-dafny-codegen/src/main/java/software/amazon/polymorph/smithypython/localservice/extensions/DafnyPythonLocalServiceClientCodegenPlugin.java index f4c7edf52..260474de5 100644 --- a/codegen/smithy-dafny-codegen/src/main/java/software/amazon/polymorph/smithypython/localservice/extensions/DafnyPythonLocalServiceClientCodegenPlugin.java +++ b/codegen/smithy-dafny-codegen/src/main/java/software/amazon/polymorph/smithypython/localservice/extensions/DafnyPythonLocalServiceClientCodegenPlugin.java @@ -236,6 +236,8 @@ public static Model transformServiceShapeToAddOrphanedShapes( } ); + System.out.println("size = " + TopologicalIndex.of(model).getRecursiveShapes().size()); + return model; } From 9fc74b6a9267b5d86d78b9f8619fa6ab06b615ef Mon Sep 17 00:00:00 2001 From: Lucas McDonald Date: Mon, 7 Oct 2024 16:04:42 -0700 Subject: [PATCH 07/76] m --- .../DafnyPythonLocalServiceClientCodegenPlugin.java | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/codegen/smithy-dafny-codegen/src/main/java/software/amazon/polymorph/smithypython/localservice/extensions/DafnyPythonLocalServiceClientCodegenPlugin.java b/codegen/smithy-dafny-codegen/src/main/java/software/amazon/polymorph/smithypython/localservice/extensions/DafnyPythonLocalServiceClientCodegenPlugin.java index 260474de5..214346b21 100644 --- a/codegen/smithy-dafny-codegen/src/main/java/software/amazon/polymorph/smithypython/localservice/extensions/DafnyPythonLocalServiceClientCodegenPlugin.java +++ b/codegen/smithy-dafny-codegen/src/main/java/software/amazon/polymorph/smithypython/localservice/extensions/DafnyPythonLocalServiceClientCodegenPlugin.java @@ -13,10 +13,7 @@ import software.amazon.smithy.codegen.core.TopologicalIndex; import software.amazon.smithy.codegen.core.directed.CodegenDirector; import software.amazon.smithy.model.Model; -import software.amazon.smithy.model.shapes.AbstractShapeBuilder; -import software.amazon.smithy.model.shapes.EnumShape; -import software.amazon.smithy.model.shapes.ServiceShape; -import software.amazon.smithy.model.shapes.ShapeId; +import software.amazon.smithy.model.shapes.*; import software.amazon.smithy.model.traits.DocumentationTrait; import software.amazon.smithy.model.traits.EnumTrait; import software.amazon.smithy.model.transform.ModelTransformer; @@ -223,6 +220,8 @@ public static Model transformServiceShapeToAddOrphanedShapes( Model model, ServiceShape serviceShape ) { + ServiceShape.Builder transformedServiceShapeBuilder = + serviceShape.toBuilder(); ModelTransformer .create() .mapShapes( @@ -231,6 +230,7 @@ public static Model transformServiceShapeToAddOrphanedShapes( if (!TopologicalIndex.of(model).getRecursiveShapes().contains(shape) && shape.getId().getNamespace().equals(serviceShape.getId().getNamespace())) { System.out.println("not in: " + shape.getId()); + transformedServiceShapeBuilder.addMember(MemberShape.builder().target(shape.getId()).build()); } return shape; } From a8a4555d2a6c082b6a87b7b05a793a7457f7fcc8 Mon Sep 17 00:00:00 2001 From: Lucas McDonald Date: Mon, 7 Oct 2024 16:07:42 -0700 Subject: [PATCH 08/76] m --- .../DafnyPythonLocalServiceClientCodegenPlugin.java | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/codegen/smithy-dafny-codegen/src/main/java/software/amazon/polymorph/smithypython/localservice/extensions/DafnyPythonLocalServiceClientCodegenPlugin.java b/codegen/smithy-dafny-codegen/src/main/java/software/amazon/polymorph/smithypython/localservice/extensions/DafnyPythonLocalServiceClientCodegenPlugin.java index 214346b21..53ec8a9b0 100644 --- a/codegen/smithy-dafny-codegen/src/main/java/software/amazon/polymorph/smithypython/localservice/extensions/DafnyPythonLocalServiceClientCodegenPlugin.java +++ b/codegen/smithy-dafny-codegen/src/main/java/software/amazon/polymorph/smithypython/localservice/extensions/DafnyPythonLocalServiceClientCodegenPlugin.java @@ -230,7 +230,10 @@ public static Model transformServiceShapeToAddOrphanedShapes( if (!TopologicalIndex.of(model).getRecursiveShapes().contains(shape) && shape.getId().getNamespace().equals(serviceShape.getId().getNamespace())) { System.out.println("not in: " + shape.getId()); - transformedServiceShapeBuilder.addMember(MemberShape.builder().target(shape.getId()).build()); + transformedServiceShapeBuilder.addMember(MemberShape.builder() + .target(shape.getId()) + .id(shape.getId()) + .build()); } return shape; } From 4c100b55474e19ebb18907397ac0e14f59fbcccf Mon Sep 17 00:00:00 2001 From: Lucas McDonald Date: Mon, 7 Oct 2024 16:08:30 -0700 Subject: [PATCH 09/76] m --- .../DafnyPythonLocalServiceClientCodegenPlugin.java | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/codegen/smithy-dafny-codegen/src/main/java/software/amazon/polymorph/smithypython/localservice/extensions/DafnyPythonLocalServiceClientCodegenPlugin.java b/codegen/smithy-dafny-codegen/src/main/java/software/amazon/polymorph/smithypython/localservice/extensions/DafnyPythonLocalServiceClientCodegenPlugin.java index 53ec8a9b0..c158e26a7 100644 --- a/codegen/smithy-dafny-codegen/src/main/java/software/amazon/polymorph/smithypython/localservice/extensions/DafnyPythonLocalServiceClientCodegenPlugin.java +++ b/codegen/smithy-dafny-codegen/src/main/java/software/amazon/polymorph/smithypython/localservice/extensions/DafnyPythonLocalServiceClientCodegenPlugin.java @@ -230,10 +230,7 @@ public static Model transformServiceShapeToAddOrphanedShapes( if (!TopologicalIndex.of(model).getRecursiveShapes().contains(shape) && shape.getId().getNamespace().equals(serviceShape.getId().getNamespace())) { System.out.println("not in: " + shape.getId()); - transformedServiceShapeBuilder.addMember(MemberShape.builder() - .target(shape.getId()) - .id(shape.getId()) - .build()); + transformedServiceShapeBuilder.addMixin(shape); } return shape; } From 523e3c3b795ea14a7198daeafe9d176bc35baf35 Mon Sep 17 00:00:00 2001 From: Lucas McDonald Date: Mon, 7 Oct 2024 16:09:51 -0700 Subject: [PATCH 10/76] m --- .../extensions/DafnyPythonLocalServiceClientCodegenPlugin.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/codegen/smithy-dafny-codegen/src/main/java/software/amazon/polymorph/smithypython/localservice/extensions/DafnyPythonLocalServiceClientCodegenPlugin.java b/codegen/smithy-dafny-codegen/src/main/java/software/amazon/polymorph/smithypython/localservice/extensions/DafnyPythonLocalServiceClientCodegenPlugin.java index c158e26a7..7f6b4fd49 100644 --- a/codegen/smithy-dafny-codegen/src/main/java/software/amazon/polymorph/smithypython/localservice/extensions/DafnyPythonLocalServiceClientCodegenPlugin.java +++ b/codegen/smithy-dafny-codegen/src/main/java/software/amazon/polymorph/smithypython/localservice/extensions/DafnyPythonLocalServiceClientCodegenPlugin.java @@ -228,7 +228,8 @@ public static Model transformServiceShapeToAddOrphanedShapes( model, shape -> { if (!TopologicalIndex.of(model).getRecursiveShapes().contains(shape) - && shape.getId().getNamespace().equals(serviceShape.getId().getNamespace())) { + && shape.getId().getNamespace().equals(serviceShape.getId().getNamespace()) + && shape.isStructureShape() || shape.isUnionShape()) { System.out.println("not in: " + shape.getId()); transformedServiceShapeBuilder.addMixin(shape); } From 0d00cd96b77cf3092044bd522751f18d71e3ae39 Mon Sep 17 00:00:00 2001 From: Lucas McDonald Date: Mon, 7 Oct 2024 16:11:28 -0700 Subject: [PATCH 11/76] m --- .../extensions/DafnyPythonLocalServiceClientCodegenPlugin.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/codegen/smithy-dafny-codegen/src/main/java/software/amazon/polymorph/smithypython/localservice/extensions/DafnyPythonLocalServiceClientCodegenPlugin.java b/codegen/smithy-dafny-codegen/src/main/java/software/amazon/polymorph/smithypython/localservice/extensions/DafnyPythonLocalServiceClientCodegenPlugin.java index 7f6b4fd49..30ff39dbf 100644 --- a/codegen/smithy-dafny-codegen/src/main/java/software/amazon/polymorph/smithypython/localservice/extensions/DafnyPythonLocalServiceClientCodegenPlugin.java +++ b/codegen/smithy-dafny-codegen/src/main/java/software/amazon/polymorph/smithypython/localservice/extensions/DafnyPythonLocalServiceClientCodegenPlugin.java @@ -229,7 +229,7 @@ public static Model transformServiceShapeToAddOrphanedShapes( shape -> { if (!TopologicalIndex.of(model).getRecursiveShapes().contains(shape) && shape.getId().getNamespace().equals(serviceShape.getId().getNamespace()) - && shape.isStructureShape() || shape.isUnionShape()) { + && (shape.isStructureShape() || shape.isUnionShape())) { System.out.println("not in: " + shape.getId()); transformedServiceShapeBuilder.addMixin(shape); } From 6a65d57b50b55bf1544ca5bd88de992e3808bb1a Mon Sep 17 00:00:00 2001 From: Lucas McDonald Date: Mon, 7 Oct 2024 16:12:10 -0700 Subject: [PATCH 12/76] m --- .../extensions/DafnyPythonLocalServiceClientCodegenPlugin.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/codegen/smithy-dafny-codegen/src/main/java/software/amazon/polymorph/smithypython/localservice/extensions/DafnyPythonLocalServiceClientCodegenPlugin.java b/codegen/smithy-dafny-codegen/src/main/java/software/amazon/polymorph/smithypython/localservice/extensions/DafnyPythonLocalServiceClientCodegenPlugin.java index 30ff39dbf..68cbbf600 100644 --- a/codegen/smithy-dafny-codegen/src/main/java/software/amazon/polymorph/smithypython/localservice/extensions/DafnyPythonLocalServiceClientCodegenPlugin.java +++ b/codegen/smithy-dafny-codegen/src/main/java/software/amazon/polymorph/smithypython/localservice/extensions/DafnyPythonLocalServiceClientCodegenPlugin.java @@ -229,7 +229,8 @@ public static Model transformServiceShapeToAddOrphanedShapes( shape -> { if (!TopologicalIndex.of(model).getRecursiveShapes().contains(shape) && shape.getId().getNamespace().equals(serviceShape.getId().getNamespace()) - && (shape.isStructureShape() || shape.isUnionShape())) { + && (shape.isStructureShape() || shape.isUnionShape()) + && !serviceShape.getOperations().contains(shape.getId())) { System.out.println("not in: " + shape.getId()); transformedServiceShapeBuilder.addMixin(shape); } From f1c3fca1811a740ae255d719c259f373ebad3338 Mon Sep 17 00:00:00 2001 From: Lucas McDonald Date: Mon, 7 Oct 2024 16:14:04 -0700 Subject: [PATCH 13/76] m --- .../DafnyPythonLocalServiceClientCodegenPlugin.java | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/codegen/smithy-dafny-codegen/src/main/java/software/amazon/polymorph/smithypython/localservice/extensions/DafnyPythonLocalServiceClientCodegenPlugin.java b/codegen/smithy-dafny-codegen/src/main/java/software/amazon/polymorph/smithypython/localservice/extensions/DafnyPythonLocalServiceClientCodegenPlugin.java index 68cbbf600..c6c3eecf3 100644 --- a/codegen/smithy-dafny-codegen/src/main/java/software/amazon/polymorph/smithypython/localservice/extensions/DafnyPythonLocalServiceClientCodegenPlugin.java +++ b/codegen/smithy-dafny-codegen/src/main/java/software/amazon/polymorph/smithypython/localservice/extensions/DafnyPythonLocalServiceClientCodegenPlugin.java @@ -4,6 +4,9 @@ package software.amazon.polymorph.smithypython.localservice.extensions; import java.util.Map; +import java.util.Set; +import java.util.stream.Collectors; + import software.amazon.polymorph.smithypython.common.nameresolver.SmithyNameResolver; import software.amazon.polymorph.traits.JavaDocTrait; import software.amazon.polymorph.traits.ReferenceTrait; @@ -222,12 +225,13 @@ public static Model transformServiceShapeToAddOrphanedShapes( ) { ServiceShape.Builder transformedServiceShapeBuilder = serviceShape.toBuilder(); + Set knownShapes = model.shapes().collect(Collectors.toSet()) ModelTransformer .create() .mapShapes( model, shape -> { - if (!TopologicalIndex.of(model).getRecursiveShapes().contains(shape) + if (knownShapes.contains(shape) && shape.getId().getNamespace().equals(serviceShape.getId().getNamespace()) && (shape.isStructureShape() || shape.isUnionShape()) && !serviceShape.getOperations().contains(shape.getId())) { From cfe7a3c45f173db409b6754443447439b89bd76e Mon Sep 17 00:00:00 2001 From: Lucas McDonald Date: Mon, 7 Oct 2024 16:14:20 -0700 Subject: [PATCH 14/76] m --- .../DafnyPythonLocalServiceClientCodegenPlugin.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/codegen/smithy-dafny-codegen/src/main/java/software/amazon/polymorph/smithypython/localservice/extensions/DafnyPythonLocalServiceClientCodegenPlugin.java b/codegen/smithy-dafny-codegen/src/main/java/software/amazon/polymorph/smithypython/localservice/extensions/DafnyPythonLocalServiceClientCodegenPlugin.java index c6c3eecf3..8d142f79f 100644 --- a/codegen/smithy-dafny-codegen/src/main/java/software/amazon/polymorph/smithypython/localservice/extensions/DafnyPythonLocalServiceClientCodegenPlugin.java +++ b/codegen/smithy-dafny-codegen/src/main/java/software/amazon/polymorph/smithypython/localservice/extensions/DafnyPythonLocalServiceClientCodegenPlugin.java @@ -225,13 +225,13 @@ public static Model transformServiceShapeToAddOrphanedShapes( ) { ServiceShape.Builder transformedServiceShapeBuilder = serviceShape.toBuilder(); - Set knownShapes = model.shapes().collect(Collectors.toSet()) + Set knownShapes = model.shapes().collect(Collectors.toSet()); ModelTransformer .create() .mapShapes( model, shape -> { - if (knownShapes.contains(shape) + if (!knownShapes.contains(shape) && shape.getId().getNamespace().equals(serviceShape.getId().getNamespace()) && (shape.isStructureShape() || shape.isUnionShape()) && !serviceShape.getOperations().contains(shape.getId())) { From 3ce6972807fa80e4c81c9371cfadf0549763eee8 Mon Sep 17 00:00:00 2001 From: Lucas McDonald Date: Mon, 7 Oct 2024 16:15:09 -0700 Subject: [PATCH 15/76] m --- .../DafnyPythonLocalServiceClientCodegenPlugin.java | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/codegen/smithy-dafny-codegen/src/main/java/software/amazon/polymorph/smithypython/localservice/extensions/DafnyPythonLocalServiceClientCodegenPlugin.java b/codegen/smithy-dafny-codegen/src/main/java/software/amazon/polymorph/smithypython/localservice/extensions/DafnyPythonLocalServiceClientCodegenPlugin.java index 8d142f79f..476734529 100644 --- a/codegen/smithy-dafny-codegen/src/main/java/software/amazon/polymorph/smithypython/localservice/extensions/DafnyPythonLocalServiceClientCodegenPlugin.java +++ b/codegen/smithy-dafny-codegen/src/main/java/software/amazon/polymorph/smithypython/localservice/extensions/DafnyPythonLocalServiceClientCodegenPlugin.java @@ -232,9 +232,11 @@ public static Model transformServiceShapeToAddOrphanedShapes( model, shape -> { if (!knownShapes.contains(shape) - && shape.getId().getNamespace().equals(serviceShape.getId().getNamespace()) - && (shape.isStructureShape() || shape.isUnionShape()) - && !serviceShape.getOperations().contains(shape.getId())) { + && !TopologicalIndex.of(model).getRecursiveShapes().contains(shape) +// && shape.getId().getNamespace().equals(serviceShape.getId().getNamespace()) +// && (shape.isStructureShape() || shape.isUnionShape()) +// && !serviceShape.getOperations().contains(shape.getId()) + ) { System.out.println("not in: " + shape.getId()); transformedServiceShapeBuilder.addMixin(shape); } From 21293bfe0aca5222efad62d179b5fea99781f14f Mon Sep 17 00:00:00 2001 From: Lucas McDonald Date: Mon, 7 Oct 2024 16:28:34 -0700 Subject: [PATCH 16/76] m --- ...PythonLocalServiceClientCodegenPlugin.java | 4 +- ...irectedDafnyPythonLocalServiceCodegen.java | 45 +++++++++++++++++++ 2 files changed, 47 insertions(+), 2 deletions(-) diff --git a/codegen/smithy-dafny-codegen/src/main/java/software/amazon/polymorph/smithypython/localservice/extensions/DafnyPythonLocalServiceClientCodegenPlugin.java b/codegen/smithy-dafny-codegen/src/main/java/software/amazon/polymorph/smithypython/localservice/extensions/DafnyPythonLocalServiceClientCodegenPlugin.java index 476734529..b82c1d906 100644 --- a/codegen/smithy-dafny-codegen/src/main/java/software/amazon/polymorph/smithypython/localservice/extensions/DafnyPythonLocalServiceClientCodegenPlugin.java +++ b/codegen/smithy-dafny-codegen/src/main/java/software/amazon/polymorph/smithypython/localservice/extensions/DafnyPythonLocalServiceClientCodegenPlugin.java @@ -16,6 +16,7 @@ import software.amazon.smithy.codegen.core.TopologicalIndex; import software.amazon.smithy.codegen.core.directed.CodegenDirector; import software.amazon.smithy.model.Model; +import software.amazon.smithy.model.neighbor.Walker; import software.amazon.smithy.model.shapes.*; import software.amazon.smithy.model.traits.DocumentationTrait; import software.amazon.smithy.model.traits.EnumTrait; @@ -225,14 +226,13 @@ public static Model transformServiceShapeToAddOrphanedShapes( ) { ServiceShape.Builder transformedServiceShapeBuilder = serviceShape.toBuilder(); - Set knownShapes = model.shapes().collect(Collectors.toSet()); + Set knownShapes = new Walker(model).walkShapes(serviceShape); ModelTransformer .create() .mapShapes( model, shape -> { if (!knownShapes.contains(shape) - && !TopologicalIndex.of(model).getRecursiveShapes().contains(shape) // && shape.getId().getNamespace().equals(serviceShape.getId().getNamespace()) // && (shape.isStructureShape() || shape.isUnionShape()) // && !serviceShape.getOperations().contains(shape.getId()) diff --git a/codegen/smithy-dafny-codegen/src/main/java/software/amazon/polymorph/smithypython/localservice/extensions/DirectedDafnyPythonLocalServiceCodegen.java b/codegen/smithy-dafny-codegen/src/main/java/software/amazon/polymorph/smithypython/localservice/extensions/DirectedDafnyPythonLocalServiceCodegen.java index 928bfcf5b..91672511c 100644 --- a/codegen/smithy-dafny-codegen/src/main/java/software/amazon/polymorph/smithypython/localservice/extensions/DirectedDafnyPythonLocalServiceCodegen.java +++ b/codegen/smithy-dafny-codegen/src/main/java/software/amazon/polymorph/smithypython/localservice/extensions/DirectedDafnyPythonLocalServiceCodegen.java @@ -14,6 +14,7 @@ import software.amazon.smithy.build.FileManifest; import software.amazon.smithy.codegen.core.*; import software.amazon.smithy.codegen.core.directed.*; +import software.amazon.smithy.model.shapes.Shape; import software.amazon.smithy.model.shapes.ShapeId; import software.amazon.smithy.model.shapes.StructureShape; import software.amazon.smithy.python.codegen.*; @@ -475,6 +476,50 @@ public void generateService( } ); + for (ShapeId shapeId : directive.service().getMixins()) { + Shape mixinShape = directive.model().expectShape(shapeId); + if (mixinShape.isStructureShape()) { + directive + .context() + .writerDelegator() + .useShapeWriter( + configShape, + writer -> { + DafnyPythonLocalServiceStructureGenerator generator = + new DafnyPythonLocalServiceStructureGenerator( + directive.model(), + directive.settings(), + directive.symbolProvider(), + writer, + configShape, + TopologicalIndex.of(directive.model()).getRecursiveShapes() + ); + generator.run(); + } + ); + } else if (mixinShape.isUnionShape()) { + directive + .context() + .writerDelegator() + .useShapeWriter( + configShape, + writer -> { + DafnyPythonLocalServiceStructureGenerator generator = + new DafnyPythonLocalServiceStructureGenerator( + directive.model(), + directive.settings(), + directive.symbolProvider(), + writer, + configShape, + TopologicalIndex.of(directive.model()).getRecursiveShapes() + ); + generator.run(); + } + ); + } + + } + var protocolGenerator = directive.context().protocolGenerator(); if (protocolGenerator == null) { return; From 66f4aa311306ab31de1590d95d5f110442ee0916 Mon Sep 17 00:00:00 2001 From: Lucas McDonald Date: Mon, 7 Oct 2024 16:32:08 -0700 Subject: [PATCH 17/76] m --- .../DafnyPythonLocalServiceClientCodegenPlugin.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/codegen/smithy-dafny-codegen/src/main/java/software/amazon/polymorph/smithypython/localservice/extensions/DafnyPythonLocalServiceClientCodegenPlugin.java b/codegen/smithy-dafny-codegen/src/main/java/software/amazon/polymorph/smithypython/localservice/extensions/DafnyPythonLocalServiceClientCodegenPlugin.java index b82c1d906..829e642da 100644 --- a/codegen/smithy-dafny-codegen/src/main/java/software/amazon/polymorph/smithypython/localservice/extensions/DafnyPythonLocalServiceClientCodegenPlugin.java +++ b/codegen/smithy-dafny-codegen/src/main/java/software/amazon/polymorph/smithypython/localservice/extensions/DafnyPythonLocalServiceClientCodegenPlugin.java @@ -233,9 +233,9 @@ public static Model transformServiceShapeToAddOrphanedShapes( model, shape -> { if (!knownShapes.contains(shape) -// && shape.getId().getNamespace().equals(serviceShape.getId().getNamespace()) -// && (shape.isStructureShape() || shape.isUnionShape()) -// && !serviceShape.getOperations().contains(shape.getId()) + && shape.getId().getNamespace().equals(serviceShape.getId().getNamespace()) + && (shape.isStructureShape() || shape.isUnionShape()) + && !serviceShape.getOperations().contains(shape.getId()) ) { System.out.println("not in: " + shape.getId()); transformedServiceShapeBuilder.addMixin(shape); From ec48abfcb83e5ee02407586d1048eac703f65d33 Mon Sep 17 00:00:00 2001 From: Lucas McDonald Date: Mon, 7 Oct 2024 16:38:38 -0700 Subject: [PATCH 18/76] m --- ...PythonLocalServiceClientCodegenPlugin.java | 37 ++++++++++--------- ...irectedDafnyPythonLocalServiceCodegen.java | 5 +++ 2 files changed, 25 insertions(+), 17 deletions(-) diff --git a/codegen/smithy-dafny-codegen/src/main/java/software/amazon/polymorph/smithypython/localservice/extensions/DafnyPythonLocalServiceClientCodegenPlugin.java b/codegen/smithy-dafny-codegen/src/main/java/software/amazon/polymorph/smithypython/localservice/extensions/DafnyPythonLocalServiceClientCodegenPlugin.java index 829e642da..daba3e6c2 100644 --- a/codegen/smithy-dafny-codegen/src/main/java/software/amazon/polymorph/smithypython/localservice/extensions/DafnyPythonLocalServiceClientCodegenPlugin.java +++ b/codegen/smithy-dafny-codegen/src/main/java/software/amazon/polymorph/smithypython/localservice/extensions/DafnyPythonLocalServiceClientCodegenPlugin.java @@ -9,6 +9,7 @@ import software.amazon.polymorph.smithypython.common.nameresolver.SmithyNameResolver; import software.amazon.polymorph.traits.JavaDocTrait; +import software.amazon.polymorph.traits.LocalServiceTrait; import software.amazon.polymorph.traits.ReferenceTrait; import software.amazon.polymorph.utils.ModelUtils; import software.amazon.smithy.build.PluginContext; @@ -226,23 +227,25 @@ public static Model transformServiceShapeToAddOrphanedShapes( ) { ServiceShape.Builder transformedServiceShapeBuilder = serviceShape.toBuilder(); - Set knownShapes = new Walker(model).walkShapes(serviceShape); - ModelTransformer - .create() - .mapShapes( - model, - shape -> { - if (!knownShapes.contains(shape) - && shape.getId().getNamespace().equals(serviceShape.getId().getNamespace()) - && (shape.isStructureShape() || shape.isUnionShape()) - && !serviceShape.getOperations().contains(shape.getId()) - ) { - System.out.println("not in: " + shape.getId()); - transformedServiceShapeBuilder.addMixin(shape); - } - return shape; - } - ); + transformedServiceShapeBuilder.addMixin( + model.expectShape(serviceShape.getTrait(LocalServiceTrait.class).get().getConfigId()) + ); +// +// ModelTransformer +// .create() +// .mapShapes( +// model, +// shape -> { +// if (!knownShapes.contains(shape) +// && shape.getId().getNamespace().equals(serviceShape.getId().getNamespace()) +// && (shape.isStructureShape() || shape.isUnionShape()) +// && !serviceShape.getOperations().contains(shape.getId()) +// ) { +// System.out.println("not in: " + shape.getId()); +// } +// return shape; +// } +// ); System.out.println("size = " + TopologicalIndex.of(model).getRecursiveShapes().size()); diff --git a/codegen/smithy-dafny-codegen/src/main/java/software/amazon/polymorph/smithypython/localservice/extensions/DirectedDafnyPythonLocalServiceCodegen.java b/codegen/smithy-dafny-codegen/src/main/java/software/amazon/polymorph/smithypython/localservice/extensions/DirectedDafnyPythonLocalServiceCodegen.java index 91672511c..1f04ae0b3 100644 --- a/codegen/smithy-dafny-codegen/src/main/java/software/amazon/polymorph/smithypython/localservice/extensions/DirectedDafnyPythonLocalServiceCodegen.java +++ b/codegen/smithy-dafny-codegen/src/main/java/software/amazon/polymorph/smithypython/localservice/extensions/DirectedDafnyPythonLocalServiceCodegen.java @@ -6,6 +6,7 @@ import static java.lang.String.format; import java.nio.file.Path; +import java.util.Set; import java.util.logging.Logger; import software.amazon.polymorph.smithypython.common.nameresolver.SmithyNameResolver; import software.amazon.polymorph.smithypython.localservice.DafnyLocalServiceCodegenConstants; @@ -14,6 +15,7 @@ import software.amazon.smithy.build.FileManifest; import software.amazon.smithy.codegen.core.*; import software.amazon.smithy.codegen.core.directed.*; +import software.amazon.smithy.model.neighbor.Walker; import software.amazon.smithy.model.shapes.Shape; import software.amazon.smithy.model.shapes.ShapeId; import software.amazon.smithy.model.shapes.StructureShape; @@ -457,6 +459,9 @@ public void generateService( ShapeId configShapeId = directive.service().getTrait(LocalServiceTrait.class).get().getConfigId(); StructureShape configShape = directive.model().expectShape(configShapeId).asStructureShape().get(); + Set knownShapes = new Walker(directive.model()).walkShapes(directive.service()); + + directive .context() .writerDelegator() From d07fcf8f0e296d8e4dd6200283c81574790888b2 Mon Sep 17 00:00:00 2001 From: Lucas McDonald Date: Mon, 7 Oct 2024 16:42:18 -0700 Subject: [PATCH 19/76] m --- .../DafnyPythonLocalServiceClientCodegenPlugin.java | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/codegen/smithy-dafny-codegen/src/main/java/software/amazon/polymorph/smithypython/localservice/extensions/DafnyPythonLocalServiceClientCodegenPlugin.java b/codegen/smithy-dafny-codegen/src/main/java/software/amazon/polymorph/smithypython/localservice/extensions/DafnyPythonLocalServiceClientCodegenPlugin.java index daba3e6c2..c622201e2 100644 --- a/codegen/smithy-dafny-codegen/src/main/java/software/amazon/polymorph/smithypython/localservice/extensions/DafnyPythonLocalServiceClientCodegenPlugin.java +++ b/codegen/smithy-dafny-codegen/src/main/java/software/amazon/polymorph/smithypython/localservice/extensions/DafnyPythonLocalServiceClientCodegenPlugin.java @@ -227,10 +227,14 @@ public static Model transformServiceShapeToAddOrphanedShapes( ) { ServiceShape.Builder transformedServiceShapeBuilder = serviceShape.toBuilder(); + + ShapeId configShapeId = model.expectShape(serviceShape.getTrait(LocalServiceTrait.class).get().getConfigId(); transformedServiceShapeBuilder.addMixin( - model.expectShape(serviceShape.getTrait(LocalServiceTrait.class).get().getConfigId()) + MemberShape.builder() + .target(configShapeId) + .build() ); -// + // ModelTransformer // .create() // .mapShapes( From a66909e44f613d92fb656133cf913cea8e2ed161 Mon Sep 17 00:00:00 2001 From: Lucas McDonald Date: Mon, 7 Oct 2024 16:42:52 -0700 Subject: [PATCH 20/76] m --- .../DafnyPythonLocalServiceClientCodegenPlugin.java | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/codegen/smithy-dafny-codegen/src/main/java/software/amazon/polymorph/smithypython/localservice/extensions/DafnyPythonLocalServiceClientCodegenPlugin.java b/codegen/smithy-dafny-codegen/src/main/java/software/amazon/polymorph/smithypython/localservice/extensions/DafnyPythonLocalServiceClientCodegenPlugin.java index c622201e2..da3329b5a 100644 --- a/codegen/smithy-dafny-codegen/src/main/java/software/amazon/polymorph/smithypython/localservice/extensions/DafnyPythonLocalServiceClientCodegenPlugin.java +++ b/codegen/smithy-dafny-codegen/src/main/java/software/amazon/polymorph/smithypython/localservice/extensions/DafnyPythonLocalServiceClientCodegenPlugin.java @@ -253,7 +253,18 @@ public static Model transformServiceShapeToAddOrphanedShapes( System.out.println("size = " + TopologicalIndex.of(model).getRecursiveShapes().size()); - return model; + return ModelTransformer + .create() + .mapShapes( + model, + shape -> { + if (shape.getId().equals(serviceShape.getId())) { + return transformedServiceShapeBuilder.build(); + } else { + return shape; + } + } + ); } /** From e2e52059fad7d68ff3d24ab6738d7a3149591d6d Mon Sep 17 00:00:00 2001 From: Lucas McDonald Date: Mon, 7 Oct 2024 16:43:34 -0700 Subject: [PATCH 21/76] m --- .../DafnyPythonLocalServiceClientCodegenPlugin.java | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/codegen/smithy-dafny-codegen/src/main/java/software/amazon/polymorph/smithypython/localservice/extensions/DafnyPythonLocalServiceClientCodegenPlugin.java b/codegen/smithy-dafny-codegen/src/main/java/software/amazon/polymorph/smithypython/localservice/extensions/DafnyPythonLocalServiceClientCodegenPlugin.java index da3329b5a..3b2667a01 100644 --- a/codegen/smithy-dafny-codegen/src/main/java/software/amazon/polymorph/smithypython/localservice/extensions/DafnyPythonLocalServiceClientCodegenPlugin.java +++ b/codegen/smithy-dafny-codegen/src/main/java/software/amazon/polymorph/smithypython/localservice/extensions/DafnyPythonLocalServiceClientCodegenPlugin.java @@ -228,10 +228,11 @@ public static Model transformServiceShapeToAddOrphanedShapes( ServiceShape.Builder transformedServiceShapeBuilder = serviceShape.toBuilder(); - ShapeId configShapeId = model.expectShape(serviceShape.getTrait(LocalServiceTrait.class).get().getConfigId(); + Shape configShape = model.expectShape(serviceShape.getTrait(LocalServiceTrait.class).get().getConfigId()); + transformedServiceShapeBuilder.addMixin( MemberShape.builder() - .target(configShapeId) + .target(configShape.getId()) .build() ); From 18c56cf1f6a2471a9aeb178daec3e56f4bf99147 Mon Sep 17 00:00:00 2001 From: Lucas McDonald Date: Mon, 7 Oct 2024 16:43:51 -0700 Subject: [PATCH 22/76] m --- .../extensions/DafnyPythonLocalServiceClientCodegenPlugin.java | 1 + 1 file changed, 1 insertion(+) diff --git a/codegen/smithy-dafny-codegen/src/main/java/software/amazon/polymorph/smithypython/localservice/extensions/DafnyPythonLocalServiceClientCodegenPlugin.java b/codegen/smithy-dafny-codegen/src/main/java/software/amazon/polymorph/smithypython/localservice/extensions/DafnyPythonLocalServiceClientCodegenPlugin.java index 3b2667a01..0ff6c003c 100644 --- a/codegen/smithy-dafny-codegen/src/main/java/software/amazon/polymorph/smithypython/localservice/extensions/DafnyPythonLocalServiceClientCodegenPlugin.java +++ b/codegen/smithy-dafny-codegen/src/main/java/software/amazon/polymorph/smithypython/localservice/extensions/DafnyPythonLocalServiceClientCodegenPlugin.java @@ -233,6 +233,7 @@ public static Model transformServiceShapeToAddOrphanedShapes( transformedServiceShapeBuilder.addMixin( MemberShape.builder() .target(configShape.getId()) + .id(configShape.getId()) .build() ); From 0034c8549573293050e8d0cc7968b83ffff7ae81 Mon Sep 17 00:00:00 2001 From: Lucas McDonald Date: Mon, 7 Oct 2024 16:45:08 -0700 Subject: [PATCH 23/76] m --- .../extensions/DafnyPythonLocalServiceClientCodegenPlugin.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/codegen/smithy-dafny-codegen/src/main/java/software/amazon/polymorph/smithypython/localservice/extensions/DafnyPythonLocalServiceClientCodegenPlugin.java b/codegen/smithy-dafny-codegen/src/main/java/software/amazon/polymorph/smithypython/localservice/extensions/DafnyPythonLocalServiceClientCodegenPlugin.java index 0ff6c003c..08275a511 100644 --- a/codegen/smithy-dafny-codegen/src/main/java/software/amazon/polymorph/smithypython/localservice/extensions/DafnyPythonLocalServiceClientCodegenPlugin.java +++ b/codegen/smithy-dafny-codegen/src/main/java/software/amazon/polymorph/smithypython/localservice/extensions/DafnyPythonLocalServiceClientCodegenPlugin.java @@ -233,7 +233,7 @@ public static Model transformServiceShapeToAddOrphanedShapes( transformedServiceShapeBuilder.addMixin( MemberShape.builder() .target(configShape.getId()) - .id(configShape.getId()) + .id(ShapeId.from(serviceShape.getId() + "$" + configShape.getId())) .build() ); From 237feb274c95a6c2da4c4e6354c580b4af31b5b2 Mon Sep 17 00:00:00 2001 From: Lucas McDonald Date: Mon, 7 Oct 2024 16:45:30 -0700 Subject: [PATCH 24/76] m --- .../extensions/DafnyPythonLocalServiceClientCodegenPlugin.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/codegen/smithy-dafny-codegen/src/main/java/software/amazon/polymorph/smithypython/localservice/extensions/DafnyPythonLocalServiceClientCodegenPlugin.java b/codegen/smithy-dafny-codegen/src/main/java/software/amazon/polymorph/smithypython/localservice/extensions/DafnyPythonLocalServiceClientCodegenPlugin.java index 08275a511..eddbf0d0b 100644 --- a/codegen/smithy-dafny-codegen/src/main/java/software/amazon/polymorph/smithypython/localservice/extensions/DafnyPythonLocalServiceClientCodegenPlugin.java +++ b/codegen/smithy-dafny-codegen/src/main/java/software/amazon/polymorph/smithypython/localservice/extensions/DafnyPythonLocalServiceClientCodegenPlugin.java @@ -233,7 +233,7 @@ public static Model transformServiceShapeToAddOrphanedShapes( transformedServiceShapeBuilder.addMixin( MemberShape.builder() .target(configShape.getId()) - .id(ShapeId.from(serviceShape.getId() + "$" + configShape.getId())) + .id(ShapeId.from(serviceShape.getId() + "$" + configShape.getId().getName())) .build() ); From 38ff2ef852b7a8c1ea8519b68bf0e3724c0cffb9 Mon Sep 17 00:00:00 2001 From: Lucas McDonald Date: Tue, 8 Oct 2024 08:57:42 -0700 Subject: [PATCH 25/76] m --- ...irectedDafnyPythonLocalServiceCodegen.java | 178 ++++++++++++------ 1 file changed, 120 insertions(+), 58 deletions(-) diff --git a/codegen/smithy-dafny-codegen/src/main/java/software/amazon/polymorph/smithypython/localservice/extensions/DirectedDafnyPythonLocalServiceCodegen.java b/codegen/smithy-dafny-codegen/src/main/java/software/amazon/polymorph/smithypython/localservice/extensions/DirectedDafnyPythonLocalServiceCodegen.java index 1f04ae0b3..5f2c9b0a5 100644 --- a/codegen/smithy-dafny-codegen/src/main/java/software/amazon/polymorph/smithypython/localservice/extensions/DirectedDafnyPythonLocalServiceCodegen.java +++ b/codegen/smithy-dafny-codegen/src/main/java/software/amazon/polymorph/smithypython/localservice/extensions/DirectedDafnyPythonLocalServiceCodegen.java @@ -6,6 +6,9 @@ import static java.lang.String.format; import java.nio.file.Path; +import java.util.ArrayList; +import java.util.Iterator; +import java.util.List; import java.util.Set; import java.util.logging.Logger; import software.amazon.polymorph.smithypython.common.nameresolver.SmithyNameResolver; @@ -460,71 +463,130 @@ public void generateService( StructureShape configShape = directive.model().expectShape(configShapeId).asStructureShape().get(); Set knownShapes = new Walker(directive.model()).walkShapes(directive.service()); + Set unknownShapes = directive.model().toSet(); + unknownShapes.removeAll(knownShapes); + List orderedShapes = new ArrayList(); - directive - .context() - .writerDelegator() - .useShapeWriter( - configShape, - writer -> { - DafnyPythonLocalServiceStructureGenerator generator = - new DafnyPythonLocalServiceStructureGenerator( - directive.model(), - directive.settings(), - directive.symbolProvider(), - writer, - configShape, - TopologicalIndex.of(directive.model()).getRecursiveShapes() - ); - generator.run(); - } - ); + TopologicalIndex topologicalIndex = TopologicalIndex.of(directive.model()); + Iterator var7 = topologicalIndex.getOrderedShapes().iterator(); + + Shape shape; + while(var7.hasNext()) { + shape = (Shape)var7.next(); + if (unknownShapes.contains(shape)) { + orderedShapes.add(shape); + } + } - for (ShapeId shapeId : directive.service().getMixins()) { - Shape mixinShape = directive.model().expectShape(shapeId); - if (mixinShape.isStructureShape()) { - directive - .context() - .writerDelegator() - .useShapeWriter( - configShape, - writer -> { - DafnyPythonLocalServiceStructureGenerator generator = - new DafnyPythonLocalServiceStructureGenerator( - directive.model(), - directive.settings(), - directive.symbolProvider(), - writer, - configShape, - TopologicalIndex.of(directive.model()).getRecursiveShapes() - ); - generator.run(); - } - ); - } else if (mixinShape.isUnionShape()) { - directive - .context() - .writerDelegator() - .useShapeWriter( - configShape, - writer -> { - DafnyPythonLocalServiceStructureGenerator generator = - new DafnyPythonLocalServiceStructureGenerator( - directive.model(), - directive.settings(), - directive.symbolProvider(), - writer, - configShape, - TopologicalIndex.of(directive.model()).getRecursiveShapes() - ); - generator.run(); - } - ); + var7 = topologicalIndex.getRecursiveShapes().iterator(); + + while(var7.hasNext()) { + shape = (Shape)var7.next(); + if (unknownShapes.contains(shape)) { + orderedShapes.add(shape); } + } + + Iterator var9 = orderedShapes.iterator(); + while(var9.hasNext()) { + Shape shapeToGenerate = (Shape)var9.next(); + if (unknownShapes.contains(shapeToGenerate)) { + if (shapeToGenerate.isUnionShape()) { + if ( + directive + .shape() + .getId() + .getNamespace() + .equals(directive.context().settings().getService().getNamespace()) + ) { + directive + .context() + .writerDelegator() + .useShapeWriter( + directive.shape(), + writer -> { + DafnyPythonLocalServiceUnionGenerator generator = + new DafnyPythonLocalServiceUnionGenerator( + directive.model(), + directive.symbolProvider(), + writer, + shapeToGenerate.asUnionShape().get(), + TopologicalIndex.of(directive.model()).getRecursiveShapes() + ); + generator.run(); + } + ); + } + } + } } +// +// directive +// .context() +// .writerDelegator() +// .useShapeWriter( +// configShape, +// writer -> { +// DafnyPythonLocalServiceStructureGenerator generator = +// new DafnyPythonLocalServiceStructureGenerator( +// directive.model(), +// directive.settings(), +// directive.symbolProvider(), +// writer, +// configShape, +// TopologicalIndex.of(directive.model()).getRecursiveShapes() +// ); +// generator.run(); +// } +// ); +// +// for (ShapeId shapeId : directive.service().getMixins()) { +// Shape mixinShape = directive.model().expectShape(shapeId); +// if (mixinShape.isStructureShape()) { +// directive +// .context() +// .writerDelegator() +// .useShapeWriter( +// configShape, +// writer -> { +// DafnyPythonLocalServiceStructureGenerator generator = +// new DafnyPythonLocalServiceStructureGenerator( +// directive.model(), +// directive.settings(), +// directive.symbolProvider(), +// writer, +// configShape, +// TopologicalIndex.of(directive.model()).getRecursiveShapes() +// ); +// generator.run(); +// } +// ); +// } else if (mixinShape.isUnionShape()) { +// directive +// .context() +// .writerDelegator() +// .useShapeWriter( +// configShape, +// writer -> { +// DafnyPythonLocalServiceStructureGenerator generator = +// new DafnyPythonLocalServiceStructureGenerator( +// directive.model(), +// directive.settings(), +// directive.symbolProvider(), +// writer, +// configShape, +// TopologicalIndex.of(directive.model()).getRecursiveShapes() +// ); +// generator.run(); +// } +// ); +// } +// +// } + var protocolGenerator = directive.context().protocolGenerator(); if (protocolGenerator == null) { return; From 7602df473aab3229592dfcbd4b05b73c4bcb88fc Mon Sep 17 00:00:00 2001 From: Lucas McDonald Date: Tue, 8 Oct 2024 08:58:07 -0700 Subject: [PATCH 26/76] m --- ...PythonLocalServiceClientCodegenPlugin.java | 52 +++++++++---------- 1 file changed, 26 insertions(+), 26 deletions(-) diff --git a/codegen/smithy-dafny-codegen/src/main/java/software/amazon/polymorph/smithypython/localservice/extensions/DafnyPythonLocalServiceClientCodegenPlugin.java b/codegen/smithy-dafny-codegen/src/main/java/software/amazon/polymorph/smithypython/localservice/extensions/DafnyPythonLocalServiceClientCodegenPlugin.java index eddbf0d0b..31d038370 100644 --- a/codegen/smithy-dafny-codegen/src/main/java/software/amazon/polymorph/smithypython/localservice/extensions/DafnyPythonLocalServiceClientCodegenPlugin.java +++ b/codegen/smithy-dafny-codegen/src/main/java/software/amazon/polymorph/smithypython/localservice/extensions/DafnyPythonLocalServiceClientCodegenPlugin.java @@ -225,17 +225,17 @@ public static Model transformServiceShapeToAddOrphanedShapes( Model model, ServiceShape serviceShape ) { - ServiceShape.Builder transformedServiceShapeBuilder = - serviceShape.toBuilder(); - - Shape configShape = model.expectShape(serviceShape.getTrait(LocalServiceTrait.class).get().getConfigId()); - - transformedServiceShapeBuilder.addMixin( - MemberShape.builder() - .target(configShape.getId()) - .id(ShapeId.from(serviceShape.getId() + "$" + configShape.getId().getName())) - .build() - ); +// ServiceShape.Builder transformedServiceShapeBuilder = +// serviceShape.toBuilder(); +// +// Shape configShape = model.expectShape(serviceShape.getTrait(LocalServiceTrait.class).get().getConfigId()); +// +// transformedServiceShapeBuilder.addMixin( +// MemberShape.builder() +// .target(configShape.getId()) +// .id(ShapeId.from(serviceShape.getId() + "$" + configShape.getId().getName())) +// .build() +// ); // ModelTransformer // .create() @@ -252,21 +252,21 @@ public static Model transformServiceShapeToAddOrphanedShapes( // return shape; // } // ); - - System.out.println("size = " + TopologicalIndex.of(model).getRecursiveShapes().size()); - - return ModelTransformer - .create() - .mapShapes( - model, - shape -> { - if (shape.getId().equals(serviceShape.getId())) { - return transformedServiceShapeBuilder.build(); - } else { - return shape; - } - } - ); +// +// System.out.println("size = " + TopologicalIndex.of(model).getRecursiveShapes().size()); +// +// return ModelTransformer +// .create() +// .mapShapes( +// model, +// shape -> { +// if (shape.getId().equals(serviceShape.getId())) { +// return transformedServiceShapeBuilder.build(); +// } else { +// return shape; +// } +// } +// ); } /** From 6d2c2964c3619651b2997fc38853bfa6291b2365 Mon Sep 17 00:00:00 2001 From: Lucas McDonald Date: Tue, 8 Oct 2024 08:58:40 -0700 Subject: [PATCH 27/76] m --- .../extensions/DafnyPythonLocalServiceClientCodegenPlugin.java | 1 + 1 file changed, 1 insertion(+) diff --git a/codegen/smithy-dafny-codegen/src/main/java/software/amazon/polymorph/smithypython/localservice/extensions/DafnyPythonLocalServiceClientCodegenPlugin.java b/codegen/smithy-dafny-codegen/src/main/java/software/amazon/polymorph/smithypython/localservice/extensions/DafnyPythonLocalServiceClientCodegenPlugin.java index 31d038370..fbd9667d2 100644 --- a/codegen/smithy-dafny-codegen/src/main/java/software/amazon/polymorph/smithypython/localservice/extensions/DafnyPythonLocalServiceClientCodegenPlugin.java +++ b/codegen/smithy-dafny-codegen/src/main/java/software/amazon/polymorph/smithypython/localservice/extensions/DafnyPythonLocalServiceClientCodegenPlugin.java @@ -225,6 +225,7 @@ public static Model transformServiceShapeToAddOrphanedShapes( Model model, ServiceShape serviceShape ) { + return model; // ServiceShape.Builder transformedServiceShapeBuilder = // serviceShape.toBuilder(); // From 26b0be10cbeba8570f915b000ba3ee97886928bc Mon Sep 17 00:00:00 2001 From: Lucas McDonald Date: Tue, 8 Oct 2024 09:00:15 -0700 Subject: [PATCH 28/76] m --- .../DirectedDafnyPythonLocalServiceCodegen.java | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/codegen/smithy-dafny-codegen/src/main/java/software/amazon/polymorph/smithypython/localservice/extensions/DirectedDafnyPythonLocalServiceCodegen.java b/codegen/smithy-dafny-codegen/src/main/java/software/amazon/polymorph/smithypython/localservice/extensions/DirectedDafnyPythonLocalServiceCodegen.java index 5f2c9b0a5..11e75d4bb 100644 --- a/codegen/smithy-dafny-codegen/src/main/java/software/amazon/polymorph/smithypython/localservice/extensions/DirectedDafnyPythonLocalServiceCodegen.java +++ b/codegen/smithy-dafny-codegen/src/main/java/software/amazon/polymorph/smithypython/localservice/extensions/DirectedDafnyPythonLocalServiceCodegen.java @@ -6,11 +6,10 @@ import static java.lang.String.format; import java.nio.file.Path; -import java.util.ArrayList; -import java.util.Iterator; -import java.util.List; -import java.util.Set; +import java.util.*; import java.util.logging.Logger; +import java.util.stream.Collectors; + import software.amazon.polymorph.smithypython.common.nameresolver.SmithyNameResolver; import software.amazon.polymorph.smithypython.localservice.DafnyLocalServiceCodegenConstants; import software.amazon.polymorph.smithypython.localservice.customize.ReferencesFileWriter; @@ -463,7 +462,7 @@ public void generateService( StructureShape configShape = directive.model().expectShape(configShapeId).asStructureShape().get(); Set knownShapes = new Walker(directive.model()).walkShapes(directive.service()); - Set unknownShapes = directive.model().toSet(); + Set unknownShapes = directive.model().shapes().collect(Collectors.toSet()); unknownShapes.removeAll(knownShapes); List orderedShapes = new ArrayList(); From b56c840f5ae85ab8f6b12f2a3e2a1f20cdb8856d Mon Sep 17 00:00:00 2001 From: Lucas McDonald Date: Tue, 8 Oct 2024 09:03:03 -0700 Subject: [PATCH 29/76] m --- .../extensions/DirectedDafnyPythonLocalServiceCodegen.java | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/codegen/smithy-dafny-codegen/src/main/java/software/amazon/polymorph/smithypython/localservice/extensions/DirectedDafnyPythonLocalServiceCodegen.java b/codegen/smithy-dafny-codegen/src/main/java/software/amazon/polymorph/smithypython/localservice/extensions/DirectedDafnyPythonLocalServiceCodegen.java index 11e75d4bb..eee636ce7 100644 --- a/codegen/smithy-dafny-codegen/src/main/java/software/amazon/polymorph/smithypython/localservice/extensions/DirectedDafnyPythonLocalServiceCodegen.java +++ b/codegen/smithy-dafny-codegen/src/main/java/software/amazon/polymorph/smithypython/localservice/extensions/DirectedDafnyPythonLocalServiceCodegen.java @@ -494,10 +494,8 @@ public void generateService( if (unknownShapes.contains(shapeToGenerate)) { if (shapeToGenerate.isUnionShape()) { if ( - directive - .shape() - .getId() - .getNamespace() + shapeToGenerate + .getId().getNamespace() .equals(directive.context().settings().getService().getNamespace()) ) { directive From 1e83075a7aec065eae5ee0044658e138c758d2a3 Mon Sep 17 00:00:00 2001 From: Lucas McDonald Date: Tue, 8 Oct 2024 09:03:46 -0700 Subject: [PATCH 30/76] m --- .../extensions/DirectedDafnyPythonLocalServiceCodegen.java | 1 + 1 file changed, 1 insertion(+) diff --git a/codegen/smithy-dafny-codegen/src/main/java/software/amazon/polymorph/smithypython/localservice/extensions/DirectedDafnyPythonLocalServiceCodegen.java b/codegen/smithy-dafny-codegen/src/main/java/software/amazon/polymorph/smithypython/localservice/extensions/DirectedDafnyPythonLocalServiceCodegen.java index eee636ce7..df8ec41c8 100644 --- a/codegen/smithy-dafny-codegen/src/main/java/software/amazon/polymorph/smithypython/localservice/extensions/DirectedDafnyPythonLocalServiceCodegen.java +++ b/codegen/smithy-dafny-codegen/src/main/java/software/amazon/polymorph/smithypython/localservice/extensions/DirectedDafnyPythonLocalServiceCodegen.java @@ -498,6 +498,7 @@ public void generateService( .getId().getNamespace() .equals(directive.context().settings().getService().getNamespace()) ) { + System.out.println("doing " + shapeToGenerate.getId()); directive .context() .writerDelegator() From 5f8a83fc37a468b398596d6bb7d0bb6d1fa03716 Mon Sep 17 00:00:00 2001 From: Lucas McDonald Date: Tue, 8 Oct 2024 09:04:52 -0700 Subject: [PATCH 31/76] m --- .../extensions/DirectedDafnyPythonLocalServiceCodegen.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/codegen/smithy-dafny-codegen/src/main/java/software/amazon/polymorph/smithypython/localservice/extensions/DirectedDafnyPythonLocalServiceCodegen.java b/codegen/smithy-dafny-codegen/src/main/java/software/amazon/polymorph/smithypython/localservice/extensions/DirectedDafnyPythonLocalServiceCodegen.java index df8ec41c8..c63d1c021 100644 --- a/codegen/smithy-dafny-codegen/src/main/java/software/amazon/polymorph/smithypython/localservice/extensions/DirectedDafnyPythonLocalServiceCodegen.java +++ b/codegen/smithy-dafny-codegen/src/main/java/software/amazon/polymorph/smithypython/localservice/extensions/DirectedDafnyPythonLocalServiceCodegen.java @@ -511,7 +511,7 @@ public void generateService( directive.symbolProvider(), writer, shapeToGenerate.asUnionShape().get(), - TopologicalIndex.of(directive.model()).getRecursiveShapes() + topologicalIndex.getRecursiveShapes() ); generator.run(); } From d3942f77b1396d712d7125cbef08c3bc13b9e5f5 Mon Sep 17 00:00:00 2001 From: Lucas McDonald Date: Tue, 8 Oct 2024 09:05:38 -0700 Subject: [PATCH 32/76] m --- .../extensions/DirectedDafnyPythonLocalServiceCodegen.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/codegen/smithy-dafny-codegen/src/main/java/software/amazon/polymorph/smithypython/localservice/extensions/DirectedDafnyPythonLocalServiceCodegen.java b/codegen/smithy-dafny-codegen/src/main/java/software/amazon/polymorph/smithypython/localservice/extensions/DirectedDafnyPythonLocalServiceCodegen.java index c63d1c021..c725597ba 100644 --- a/codegen/smithy-dafny-codegen/src/main/java/software/amazon/polymorph/smithypython/localservice/extensions/DirectedDafnyPythonLocalServiceCodegen.java +++ b/codegen/smithy-dafny-codegen/src/main/java/software/amazon/polymorph/smithypython/localservice/extensions/DirectedDafnyPythonLocalServiceCodegen.java @@ -503,7 +503,7 @@ public void generateService( .context() .writerDelegator() .useShapeWriter( - directive.shape(), + shapeToGenerate, writer -> { DafnyPythonLocalServiceUnionGenerator generator = new DafnyPythonLocalServiceUnionGenerator( From 21b13a2750a61ed9da63c39c73b4487cfd1e10d0 Mon Sep 17 00:00:00 2001 From: Lucas McDonald Date: Tue, 8 Oct 2024 09:14:46 -0700 Subject: [PATCH 33/76] m --- ...irectedDafnyPythonLocalServiceCodegen.java | 31 +++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/codegen/smithy-dafny-codegen/src/main/java/software/amazon/polymorph/smithypython/localservice/extensions/DirectedDafnyPythonLocalServiceCodegen.java b/codegen/smithy-dafny-codegen/src/main/java/software/amazon/polymorph/smithypython/localservice/extensions/DirectedDafnyPythonLocalServiceCodegen.java index c725597ba..a942a282b 100644 --- a/codegen/smithy-dafny-codegen/src/main/java/software/amazon/polymorph/smithypython/localservice/extensions/DirectedDafnyPythonLocalServiceCodegen.java +++ b/codegen/smithy-dafny-codegen/src/main/java/software/amazon/polymorph/smithypython/localservice/extensions/DirectedDafnyPythonLocalServiceCodegen.java @@ -492,6 +492,7 @@ public void generateService( while(var9.hasNext()) { Shape shapeToGenerate = (Shape)var9.next(); if (unknownShapes.contains(shapeToGenerate)) { + if (shapeToGenerate.isUnionShape()) { if ( shapeToGenerate @@ -518,6 +519,36 @@ public void generateService( ); } } + + if (shapeToGenerate.isStructureShape()) { + if ( + shapeToGenerate + .getId().getNamespace() + .equals(directive.context().settings().getService().getNamespace()) + ) { + System.out.println("doing " + shapeToGenerate.getId()); + directive + .context() + .writerDelegator() + .useShapeWriter( + shapeToGenerate, + writer -> { + DafnyPythonLocalServiceStructureGenerator generator = + new DafnyPythonLocalServiceStructureGenerator( + directive.model(), + directive.settings(), + directive.symbolProvider(), + writer, + shapeToGenerate.asStructureShape().get(), + topologicalIndex.getRecursiveShapes() + ); + generator.run(); + } + ); + } + } + + } } From fb1047347db1613702e6880d90d06cdb403cc156 Mon Sep 17 00:00:00 2001 From: Lucas McDonald Date: Tue, 8 Oct 2024 09:16:32 -0700 Subject: [PATCH 34/76] m --- ...irectedDafnyPythonLocalServiceCodegen.java | 29 +++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/codegen/smithy-dafny-codegen/src/main/java/software/amazon/polymorph/smithypython/localservice/extensions/DirectedDafnyPythonLocalServiceCodegen.java b/codegen/smithy-dafny-codegen/src/main/java/software/amazon/polymorph/smithypython/localservice/extensions/DirectedDafnyPythonLocalServiceCodegen.java index a942a282b..5b2a09b43 100644 --- a/codegen/smithy-dafny-codegen/src/main/java/software/amazon/polymorph/smithypython/localservice/extensions/DirectedDafnyPythonLocalServiceCodegen.java +++ b/codegen/smithy-dafny-codegen/src/main/java/software/amazon/polymorph/smithypython/localservice/extensions/DirectedDafnyPythonLocalServiceCodegen.java @@ -548,6 +548,35 @@ public void generateService( } } + if (shapeToGenerate.isResourceShape()) { + if ( + ReferencesFileWriter.shouldGenerateResourceForShape( + shapeToGenerate.asResourceShape().get(), + directive.context() + ) + ) { + String moduleName = + SmithyNameResolver.getServiceSmithygeneratedDirectoryNameForNamespace( + directive.context().settings().getService().getNamespace() + ); + directive + .context() + .writerDelegator() + .useFileWriter( + moduleName + "/references.py", + "", + writer -> { + new ReferencesFileWriter() + .generateResourceInterfaceAndImplementation( + shapeToGenerate.asResourceShape().get(), + directive.context(), + writer + ); + } + ); + } + } + } } From e79fe41e09dffb30d403599a97e7dec1491eedb7 Mon Sep 17 00:00:00 2001 From: Lucas McDonald Date: Tue, 8 Oct 2024 12:17:18 -0700 Subject: [PATCH 35/76] m --- ...irectedDafnyPythonLocalServiceCodegen.java | 288 +++++++----------- 1 file changed, 117 insertions(+), 171 deletions(-) diff --git a/codegen/smithy-dafny-codegen/src/main/java/software/amazon/polymorph/smithypython/localservice/extensions/DirectedDafnyPythonLocalServiceCodegen.java b/codegen/smithy-dafny-codegen/src/main/java/software/amazon/polymorph/smithypython/localservice/extensions/DirectedDafnyPythonLocalServiceCodegen.java index 5b2a09b43..f9ed9c7f9 100644 --- a/codegen/smithy-dafny-codegen/src/main/java/software/amazon/polymorph/smithypython/localservice/extensions/DirectedDafnyPythonLocalServiceCodegen.java +++ b/codegen/smithy-dafny-codegen/src/main/java/software/amazon/polymorph/smithypython/localservice/extensions/DirectedDafnyPythonLocalServiceCodegen.java @@ -13,14 +13,12 @@ import software.amazon.polymorph.smithypython.common.nameresolver.SmithyNameResolver; import software.amazon.polymorph.smithypython.localservice.DafnyLocalServiceCodegenConstants; import software.amazon.polymorph.smithypython.localservice.customize.ReferencesFileWriter; -import software.amazon.polymorph.traits.LocalServiceTrait; import software.amazon.smithy.build.FileManifest; import software.amazon.smithy.codegen.core.*; import software.amazon.smithy.codegen.core.directed.*; import software.amazon.smithy.model.neighbor.Walker; -import software.amazon.smithy.model.shapes.Shape; -import software.amazon.smithy.model.shapes.ShapeId; -import software.amazon.smithy.model.shapes.StructureShape; +import software.amazon.smithy.model.shapes.*; +import software.amazon.smithy.model.traits.ErrorTrait; import software.amazon.smithy.python.codegen.*; /** @@ -206,18 +204,22 @@ protected void generateServiceErrors( public void generateResource( GenerateResourceDirective directive ) { - if ( - ReferencesFileWriter.shouldGenerateResourceForShape( - directive.shape(), - directive.context() - ) - ) { + writeResourceShape(directive.shape(), directive.context()); + } + + protected void writeResourceShape( + ResourceShape shape, + GenerationContext context + ) { + if (ReferencesFileWriter.shouldGenerateResourceForShape( + shape, + context + )) { String moduleName = SmithyNameResolver.getServiceSmithygeneratedDirectoryNameForNamespace( - directive.context().settings().getService().getNamespace() + context.settings().getService().getNamespace() ); - directive - .context() + context .writerDelegator() .useFileWriter( moduleName + "/references.py", @@ -225,8 +227,8 @@ public void generateResource( writer -> { new ReferencesFileWriter() .generateResourceInterfaceAndImplementation( - directive.shape(), - directive.context(), + shape, + context, writer ); } @@ -242,28 +244,33 @@ public void generateResource( @Override public void generateStructure( GenerateStructureDirective directive + ) { + writeStructureShape(directive.shape(), directive.context()); + } + + protected void writeStructureShape( + StructureShape shape, + GenerationContext context ) { if ( - directive - .shape() + shape .getId() .getNamespace() - .equals(directive.context().settings().getService().getNamespace()) + .equals(context.settings().getService().getNamespace()) ) { - directive - .context() + context .writerDelegator() .useShapeWriter( - directive.shape(), + shape, writer -> { DafnyPythonLocalServiceStructureGenerator generator = new DafnyPythonLocalServiceStructureGenerator( - directive.model(), - directive.settings(), - directive.symbolProvider(), + context.model(), + context.settings(), + context.symbolProvider(), writer, - directive.shape(), - TopologicalIndex.of(directive.model()).getRecursiveShapes() + shape, + TopologicalIndex.of(context.model()).getRecursiveShapes() ); generator.run(); } @@ -279,28 +286,33 @@ public void generateStructure( @Override public void generateError( GenerateErrorDirective directive + ) { + writeStructureShapeWithErrorTrait(directive.shape(), directive.context()); + } + + protected void writeStructureShapeWithErrorTrait( + StructureShape shape, + GenerationContext context ) { if ( - directive - .shape() + shape .getId() .getNamespace() - .equals(directive.context().settings().getService().getNamespace()) + .equals(context.settings().getService().getNamespace()) ) { - directive - .context() + context .writerDelegator() .useShapeWriter( - directive.shape(), + shape, writer -> { DafnyPythonLocalServiceStructureGenerator generator = new DafnyPythonLocalServiceStructureGenerator( - directive.model(), - directive.settings(), - directive.symbolProvider(), + context.model(), + context.settings(), + context.symbolProvider(), writer, - directive.shape(), - TopologicalIndex.of(directive.model()).getRecursiveShapes() + shape, + TopologicalIndex.of(context.model()).getRecursiveShapes() ); generator.run(); } @@ -316,29 +328,30 @@ public void generateError( @Override public void generateEnumShape( GenerateEnumDirective directive + ) { + writeEnumShape(directive.shape().asEnumShape().get(), directive.context()); + } + + protected void writeEnumShape( + EnumShape shape, + GenerationContext context ) { if ( - directive - .shape() + shape .getId() .getNamespace() - .equals(directive.context().settings().getService().getNamespace()) + .equals(context.settings().getService().getNamespace()) ) { - if (!directive.shape().isEnumShape()) { - return; - } - - directive - .context() + context .writerDelegator() .useShapeWriter( - directive.shape(), + shape, writer -> { EnumGenerator generator = new EnumGenerator( - directive.model(), - directive.symbolProvider(), + context.model(), + context.symbolProvider(), writer, - directive.shape().asEnumShape().get() + shape ); generator.run(); } @@ -354,27 +367,32 @@ public void generateEnumShape( @Override public void generateUnion( GenerateUnionDirective directive + ) { + writeUnionShape(directive.shape(), directive.context()); + } + + protected void writeUnionShape( + UnionShape shape, + GenerationContext context ) { if ( - directive - .shape() + shape .getId() .getNamespace() - .equals(directive.context().settings().getService().getNamespace()) + .equals(context.settings().getService().getNamespace()) ) { - directive - .context() + context .writerDelegator() .useShapeWriter( - directive.shape(), + shape, writer -> { DafnyPythonLocalServiceUnionGenerator generator = new DafnyPythonLocalServiceUnionGenerator( - directive.model(), - directive.symbolProvider(), + context.model(), + context.symbolProvider(), writer, - directive.shape(), - TopologicalIndex.of(directive.model()).getRecursiveShapes() + shape, + TopologicalIndex.of(context.model()).getRecursiveShapes() ); generator.run(); } @@ -445,141 +463,69 @@ public void customizeAfterIntegrations( } /** - * Override Smithy-Python's generateService to generate a synchronous client. - * Smithy-Python-generated clients' methods are all async. - * Smithy-Dafny-Python-generated clients' methods are not async. + * This MUST run after code generation for non-orphaned shapes. + * Orphaned shapes may topologically depend on non-orphaned shapes, but not vice versa. * - * @param directive Directive to perform. + * @param directive */ - @Override - public void generateService( + protected void generateOrphanedShapesForService( GenerateServiceDirective directive ) { - new SynchronousClientGenerator(directive.context(), directive.service()) - .run(); - - ShapeId configShapeId = directive.service().getTrait(LocalServiceTrait.class).get().getConfigId(); - StructureShape configShape = directive.model().expectShape(configShapeId).asStructureShape().get(); - + // Copy-paste Smithy-Core's shape discovery mechanism to get a set of "known" shapes to Smithy-Core Set knownShapes = new Walker(directive.model()).walkShapes(directive.service()); Set unknownShapes = directive.model().shapes().collect(Collectors.toSet()); unknownShapes.removeAll(knownShapes); + // Copy-paste Smithy-Core's shape ordering mechanism for topological ordering, + // then touch it up to generate code for unknown shapes + // (This is a topological ordering; Python needs topological ordering to write shapes in order) List orderedShapes = new ArrayList(); TopologicalIndex topologicalIndex = TopologicalIndex.of(directive.model()); - Iterator var7 = topologicalIndex.getOrderedShapes().iterator(); - Shape shape; - while(var7.hasNext()) { - shape = (Shape)var7.next(); + for (Shape shape : topologicalIndex.getOrderedShapes()) { if (unknownShapes.contains(shape)) { orderedShapes.add(shape); } } - - var7 = topologicalIndex.getRecursiveShapes().iterator(); - - while(var7.hasNext()) { - shape = (Shape)var7.next(); + for (Shape shape : topologicalIndex.getRecursiveShapes()) { if (unknownShapes.contains(shape)) { orderedShapes.add(shape); } } - Iterator var9 = orderedShapes.iterator(); - - while(var9.hasNext()) { - Shape shapeToGenerate = (Shape)var9.next(); - if (unknownShapes.contains(shapeToGenerate)) { - - if (shapeToGenerate.isUnionShape()) { - if ( - shapeToGenerate - .getId().getNamespace() - .equals(directive.context().settings().getService().getNamespace()) - ) { - System.out.println("doing " + shapeToGenerate.getId()); - directive - .context() - .writerDelegator() - .useShapeWriter( - shapeToGenerate, - writer -> { - DafnyPythonLocalServiceUnionGenerator generator = - new DafnyPythonLocalServiceUnionGenerator( - directive.model(), - directive.symbolProvider(), - writer, - shapeToGenerate.asUnionShape().get(), - topologicalIndex.getRecursiveShapes() - ); - generator.run(); - } - ); - } - } - - if (shapeToGenerate.isStructureShape()) { - if ( - shapeToGenerate - .getId().getNamespace() - .equals(directive.context().settings().getService().getNamespace()) - ) { - System.out.println("doing " + shapeToGenerate.getId()); - directive - .context() - .writerDelegator() - .useShapeWriter( - shapeToGenerate, - writer -> { - DafnyPythonLocalServiceStructureGenerator generator = - new DafnyPythonLocalServiceStructureGenerator( - directive.model(), - directive.settings(), - directive.symbolProvider(), - writer, - shapeToGenerate.asStructureShape().get(), - topologicalIndex.getRecursiveShapes() - ); - generator.run(); - } - ); - } - } - - if (shapeToGenerate.isResourceShape()) { - if ( - ReferencesFileWriter.shouldGenerateResourceForShape( - shapeToGenerate.asResourceShape().get(), - directive.context() - ) - ) { - String moduleName = - SmithyNameResolver.getServiceSmithygeneratedDirectoryNameForNamespace( - directive.context().settings().getService().getNamespace() - ); - directive - .context() - .writerDelegator() - .useFileWriter( - moduleName + "/references.py", - "", - writer -> { - new ReferencesFileWriter() - .generateResourceInterfaceAndImplementation( - shapeToGenerate.asResourceShape().get(), - directive.context(), - writer - ); - } - ); - } + for (Shape shapeToGenerate : orderedShapes) { + if (shapeToGenerate.isResourceShape()) { + writeResourceShape(shapeToGenerate.asResourceShape().get(), directive.context()); + } else if (shapeToGenerate.isStructureShape()) { + StructureShape structureShape = shapeToGenerate.asStructureShape().get(); + if (structureShape.hasTrait(ErrorTrait.class)) { + writeStructureShapeWithErrorTrait(structureShape, directive.context()); + } else { + writeStructureShape(structureShape, directive.context()); } + } else if (shapeToGenerate.isEnumShape()) { + writeEnumShape(shapeToGenerate.asEnumShape().get(), directive.context()); + } else if (shapeToGenerate.isUnionShape()) { + writeUnionShape(shapeToGenerate.asUnionShape().get(), directive.context()); + } + } + /** + * Override Smithy-Python's generateService to generate a synchronous client. + * Smithy-Python-generated clients' methods are all async. + * Smithy-Dafny-Python-generated clients' methods are not async. + * + * @param directive Directive to perform. + */ + @Override + public void generateService( + GenerateServiceDirective directive + ) { + new SynchronousClientGenerator(directive.context(), directive.service()) + .run(); - } - } + generateOrphanedShapesForService(directive); // // directive From 49cb7061885ca03c0e18fe8cf4ae9b2b4682f9da Mon Sep 17 00:00:00 2001 From: Lucas McDonald Date: Tue, 8 Oct 2024 12:18:08 -0700 Subject: [PATCH 36/76] m --- .../extensions/DirectedDafnyPythonLocalServiceCodegen.java | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/codegen/smithy-dafny-codegen/src/main/java/software/amazon/polymorph/smithypython/localservice/extensions/DirectedDafnyPythonLocalServiceCodegen.java b/codegen/smithy-dafny-codegen/src/main/java/software/amazon/polymorph/smithypython/localservice/extensions/DirectedDafnyPythonLocalServiceCodegen.java index f9ed9c7f9..dfc9df26f 100644 --- a/codegen/smithy-dafny-codegen/src/main/java/software/amazon/polymorph/smithypython/localservice/extensions/DirectedDafnyPythonLocalServiceCodegen.java +++ b/codegen/smithy-dafny-codegen/src/main/java/software/amazon/polymorph/smithypython/localservice/extensions/DirectedDafnyPythonLocalServiceCodegen.java @@ -469,9 +469,9 @@ public void customizeAfterIntegrations( * @param directive */ protected void generateOrphanedShapesForService( - GenerateServiceDirective directive - ) { - // Copy-paste Smithy-Core's shape discovery mechanism to get a set of "known" shapes to Smithy-Core + GenerateServiceDirective directive) { + // Copy-paste Smithy-Core's shape discovery mechanism to get a set of "known" shapes to + // Smithy-Core Set knownShapes = new Walker(directive.model()).walkShapes(directive.service()); Set unknownShapes = directive.model().shapes().collect(Collectors.toSet()); unknownShapes.removeAll(knownShapes); @@ -508,6 +508,7 @@ protected void generateOrphanedShapesForService( writeEnumShape(shapeToGenerate.asEnumShape().get(), directive.context()); } else if (shapeToGenerate.isUnionShape()) { writeUnionShape(shapeToGenerate.asUnionShape().get(), directive.context()); + } } } From e1de790f9d60a3af1d1830967aaae102444d4aa2 Mon Sep 17 00:00:00 2001 From: Lucas McDonald Date: Tue, 8 Oct 2024 12:29:12 -0700 Subject: [PATCH 37/76] m --- ...irectedDafnyPythonLocalServiceCodegen.java | 104 +++--------------- .../amazon/polymorph/utils/ModelUtils.java | 35 ++++++ 2 files changed, 50 insertions(+), 89 deletions(-) diff --git a/codegen/smithy-dafny-codegen/src/main/java/software/amazon/polymorph/smithypython/localservice/extensions/DirectedDafnyPythonLocalServiceCodegen.java b/codegen/smithy-dafny-codegen/src/main/java/software/amazon/polymorph/smithypython/localservice/extensions/DirectedDafnyPythonLocalServiceCodegen.java index dfc9df26f..05bbb5dab 100644 --- a/codegen/smithy-dafny-codegen/src/main/java/software/amazon/polymorph/smithypython/localservice/extensions/DirectedDafnyPythonLocalServiceCodegen.java +++ b/codegen/smithy-dafny-codegen/src/main/java/software/amazon/polymorph/smithypython/localservice/extensions/DirectedDafnyPythonLocalServiceCodegen.java @@ -4,6 +4,7 @@ package software.amazon.polymorph.smithypython.localservice.extensions; import static java.lang.String.format; +import static software.amazon.polymorph.utils.ModelUtils.getTopologicallyOrderedOrphanedShapesForService; import java.nio.file.Path; import java.util.*; @@ -470,29 +471,10 @@ public void customizeAfterIntegrations( */ protected void generateOrphanedShapesForService( GenerateServiceDirective directive) { - // Copy-paste Smithy-Core's shape discovery mechanism to get a set of "known" shapes to - // Smithy-Core - Set knownShapes = new Walker(directive.model()).walkShapes(directive.service()); - Set unknownShapes = directive.model().shapes().collect(Collectors.toSet()); - unknownShapes.removeAll(knownShapes); - - // Copy-paste Smithy-Core's shape ordering mechanism for topological ordering, - // then touch it up to generate code for unknown shapes - // (This is a topological ordering; Python needs topological ordering to write shapes in order) - List orderedShapes = new ArrayList(); - - TopologicalIndex topologicalIndex = TopologicalIndex.of(directive.model()); - - for (Shape shape : topologicalIndex.getOrderedShapes()) { - if (unknownShapes.contains(shape)) { - orderedShapes.add(shape); - } - } - for (Shape shape : topologicalIndex.getRecursiveShapes()) { - if (unknownShapes.contains(shape)) { - orderedShapes.add(shape); - } - } + + List orderedShapes = getTopologicallyOrderedOrphanedShapesForService( + directive.shape(), directive.model() + ); for (Shape shapeToGenerate : orderedShapes) { if (shapeToGenerate.isResourceShape()) { @@ -523,74 +505,18 @@ protected void generateOrphanedShapesForService( public void generateService( GenerateServiceDirective directive ) { - new SynchronousClientGenerator(directive.context(), directive.service()) - .run(); - + // For Python, orphaned shape generation MUST run after + // Smithy-Core's `CodegenDirector.generateShapesInService` executes. + // Orphaned shapes may depend on shapes generated by that method, + // and must be generated after non-orphaned shapes. + // (The reverse is not true; non-orphaned shapes will never depend on orphaned shapes.) + // Smithy-Core currently calls `directedCodegen.generateService` (this method) + // immediately after calling `generateShapesInService`, + // so this is a correct ordering to generate orphaned shapes. generateOrphanedShapesForService(directive); -// -// directive -// .context() -// .writerDelegator() -// .useShapeWriter( -// configShape, -// writer -> { -// DafnyPythonLocalServiceStructureGenerator generator = -// new DafnyPythonLocalServiceStructureGenerator( -// directive.model(), -// directive.settings(), -// directive.symbolProvider(), -// writer, -// configShape, -// TopologicalIndex.of(directive.model()).getRecursiveShapes() -// ); -// generator.run(); -// } -// ); -// -// for (ShapeId shapeId : directive.service().getMixins()) { -// Shape mixinShape = directive.model().expectShape(shapeId); -// if (mixinShape.isStructureShape()) { -// directive -// .context() -// .writerDelegator() -// .useShapeWriter( -// configShape, -// writer -> { -// DafnyPythonLocalServiceStructureGenerator generator = -// new DafnyPythonLocalServiceStructureGenerator( -// directive.model(), -// directive.settings(), -// directive.symbolProvider(), -// writer, -// configShape, -// TopologicalIndex.of(directive.model()).getRecursiveShapes() -// ); -// generator.run(); -// } -// ); -// } else if (mixinShape.isUnionShape()) { -// directive -// .context() -// .writerDelegator() -// .useShapeWriter( -// configShape, -// writer -> { -// DafnyPythonLocalServiceStructureGenerator generator = -// new DafnyPythonLocalServiceStructureGenerator( -// directive.model(), -// directive.settings(), -// directive.symbolProvider(), -// writer, -// configShape, -// TopologicalIndex.of(directive.model()).getRecursiveShapes() -// ); -// generator.run(); -// } -// ); -// } -// -// } + new SynchronousClientGenerator(directive.context(), directive.service()) + .run(); var protocolGenerator = directive.context().protocolGenerator(); if (protocolGenerator == null) { diff --git a/codegen/smithy-dafny-codegen/src/main/java/software/amazon/polymorph/utils/ModelUtils.java b/codegen/smithy-dafny-codegen/src/main/java/software/amazon/polymorph/utils/ModelUtils.java index 331b383d3..5b5995e65 100644 --- a/codegen/smithy-dafny-codegen/src/main/java/software/amazon/polymorph/utils/ModelUtils.java +++ b/codegen/smithy-dafny-codegen/src/main/java/software/amazon/polymorph/utils/ModelUtils.java @@ -17,8 +17,10 @@ import software.amazon.polymorph.traits.MutableLocalStateTrait; import software.amazon.polymorph.traits.PositionalTrait; import software.amazon.polymorph.traits.ReferenceTrait; +import software.amazon.smithy.codegen.core.TopologicalIndex; import software.amazon.smithy.model.Model; import software.amazon.smithy.model.loader.ModelAssembler; +import software.amazon.smithy.model.neighbor.Walker; import software.amazon.smithy.model.shapes.*; import software.amazon.smithy.model.traits.DocumentationTrait; import software.amazon.smithy.model.traits.EnumTrait; @@ -712,4 +714,37 @@ public static Optional getDocumentationOrJavadoc(Shape shape) { .map(StringTrait::getValue) .or(() -> shape.getTrait(JavaDocTrait.class).map(StringTrait::getValue)); } + + public static List getTopologicallyOrderedOrphanedShapesForService( + ServiceShape serviceShape, + Model model + ) { + // Copy-paste Smithy-Core's shape discovery mechanism: + // Walk the model starting from the serviceShape. + // This generates shapes that are "known" to Smithy-Core's `generateShapesInService`. + Set nonOrphanedShapes = new Walker(model).walkShapes(serviceShape); + + // orphanedShapes = (all shapes in model) - (non-orphaned shapes) + Set orphanedShapes = model.shapes().collect(Collectors.toSet()); + orphanedShapes.removeAll(nonOrphanedShapes); + + // Copy-paste Smithy-Core's shape ordering mechanism for topological ordering + // (Python needs topological ordering to write shapes in order; other languages might not matter) + List orderedShapes = new ArrayList(); + + TopologicalIndex topologicalIndex = TopologicalIndex.of(model); + + for (Shape shape : topologicalIndex.getOrderedShapes()) { + if (orphanedShapes.contains(shape)) { + orderedShapes.add(shape); + } + } + for (Shape shape : topologicalIndex.getRecursiveShapes()) { + if (orphanedShapes.contains(shape)) { + orderedShapes.add(shape); + } + } + + return orderedShapes; + } } From 139d5e83614732584a961eefc3e139d97a7a813a Mon Sep 17 00:00:00 2001 From: Lucas McDonald Date: Tue, 8 Oct 2024 12:29:53 -0700 Subject: [PATCH 38/76] m --- .../customize/ConfigFileWriter.java | 194 +++++++++--------- 1 file changed, 98 insertions(+), 96 deletions(-) diff --git a/codegen/smithy-dafny-codegen/src/main/java/software/amazon/polymorph/smithypython/localservice/customize/ConfigFileWriter.java b/codegen/smithy-dafny-codegen/src/main/java/software/amazon/polymorph/smithypython/localservice/customize/ConfigFileWriter.java index c2af75c59..8111fae65 100644 --- a/codegen/smithy-dafny-codegen/src/main/java/software/amazon/polymorph/smithypython/localservice/customize/ConfigFileWriter.java +++ b/codegen/smithy-dafny-codegen/src/main/java/software/amazon/polymorph/smithypython/localservice/customize/ConfigFileWriter.java @@ -33,103 +33,105 @@ public void customizeFileForServiceShape( ServiceShape serviceShape, GenerationContext codegenContext ) { - final LocalServiceTrait localServiceTrait = serviceShape.expectTrait( - LocalServiceTrait.class - ); - final StructureShape configShape = codegenContext - .model() - .expectShape(localServiceTrait.getConfigId(), StructureShape.class); - - String moduleName = - SmithyNameResolver.getServiceSmithygeneratedDirectoryNameForNamespace( - codegenContext.settings().getService().getNamespace() - ); - codegenContext - .writerDelegator() - .useFileWriter( - moduleName + "/config.py", - "", - writer -> { - DafnyNameResolver.importDafnyTypeForShape( - writer, - configShape.getId(), - codegenContext - ); - - writer.write( - """ - class $L(Config): - ""\" - Smithy-modelled localService Config shape for this localService. - ""\" - ${C|} - def __init__( - self, - ${C|} - ): - ${C|} - super().__init__() - ${C|} - - def dafny_config_to_smithy_config(dafny_config) -> $L: - ""\" - Converts the provided Dafny shape for this localService's config - into the corresponding Smithy-modelled shape. - ""\" - ${C|} - - def smithy_config_to_dafny_config(smithy_config) -> $L: - ""\" - Converts the provided Smithy-modelled shape for this localService's config - into the corresponding Dafny shape. - ""\" - ${C|} - """, - configShape.getId().getName(), - writer.consumer(w -> - generateConfigClassFields(configShape, codegenContext, w) - ), - writer.consumer(w -> - generateConfigConstructorParameters( - configShape, - codegenContext, - w - ) - ), - writer.consumer(w -> - generateConfigConstructorDocumentation( - configShape, - codegenContext, - w - ) - ), - writer.consumer(w -> - generateConfigConstructorFieldAssignments( - configShape, - codegenContext, - w - ) - ), - configShape.getId().getName(), - writer.consumer(w -> - generateDafnyConfigToSmithyConfigFunctionBody( - configShape, - codegenContext, - w - ) - ), - DafnyNameResolver.getDafnyTypeForShape(configShape.getId()), - writer.consumer(w -> - generateSmithyConfigToDafnyConfigFunctionBody( - configShape, - codegenContext, - w - ) - ) - ); - } - ); +// +// final LocalServiceTrait localServiceTrait = serviceShape.expectTrait( +// LocalServiceTrait.class +// ); +// final StructureShape configShape = codegenContext +// .model() +// .expectShape(localServiceTrait.getConfigId(), StructureShape.class); +// +// String moduleName = +// SmithyNameResolver.getServiceSmithygeneratedDirectoryNameForNamespace( +// codegenContext.settings().getService().getNamespace() +// ); +// codegenContext +// .writerDelegator() +// .useFileWriter( +// moduleName + "/config.py", +// "", +// writer -> { +// DafnyNameResolver.importDafnyTypeForShape( +// writer, +// configShape.getId(), +// codegenContext +// ); +// +// writer.write( +// """ +// class $L(Config): +// ""\" +// Smithy-modelled localService Config shape for this localService. +// ""\" +// ${C|} +// +// def __init__( +// self, +// ${C|} +// ): +// ${C|} +// super().__init__() +// ${C|} +// +// def dafny_config_to_smithy_config(dafny_config) -> $L: +// ""\" +// Converts the provided Dafny shape for this localService's config +// into the corresponding Smithy-modelled shape. +// ""\" +// ${C|} +// +// def smithy_config_to_dafny_config(smithy_config) -> $L: +// ""\" +// Converts the provided Smithy-modelled shape for this localService's config +// into the corresponding Dafny shape. +// ""\" +// ${C|} +// """, +// configShape.getId().getName(), +// writer.consumer(w -> +// generateConfigClassFields(configShape, codegenContext, w) +// ), +// writer.consumer(w -> +// generateConfigConstructorParameters( +// configShape, +// codegenContext, +// w +// ) +// ), +// writer.consumer(w -> +// generateConfigConstructorDocumentation( +// configShape, +// codegenContext, +// w +// ) +// ), +// writer.consumer(w -> +// generateConfigConstructorFieldAssignments( +// configShape, +// codegenContext, +// w +// ) +// ), +// configShape.getId().getName(), +// writer.consumer(w -> +// generateDafnyConfigToSmithyConfigFunctionBody( +// configShape, +// codegenContext, +// w +// ) +// ), +// DafnyNameResolver.getDafnyTypeForShape(configShape.getId()), +// writer.consumer(w -> +// generateSmithyConfigToDafnyConfigFunctionBody( +// configShape, +// codegenContext, +// w +// ) +// ) +// ); +// } +// ); } /** From 121a71b43bcf9c9582d9e6441bc22dfacacb9278 Mon Sep 17 00:00:00 2001 From: Lucas McDonald Date: Tue, 8 Oct 2024 12:32:14 -0700 Subject: [PATCH 39/76] m --- .../customize/ConfigFileWriter.java | 158 +++++++----------- 1 file changed, 60 insertions(+), 98 deletions(-) diff --git a/codegen/smithy-dafny-codegen/src/main/java/software/amazon/polymorph/smithypython/localservice/customize/ConfigFileWriter.java b/codegen/smithy-dafny-codegen/src/main/java/software/amazon/polymorph/smithypython/localservice/customize/ConfigFileWriter.java index 8111fae65..32625197d 100644 --- a/codegen/smithy-dafny-codegen/src/main/java/software/amazon/polymorph/smithypython/localservice/customize/ConfigFileWriter.java +++ b/codegen/smithy-dafny-codegen/src/main/java/software/amazon/polymorph/smithypython/localservice/customize/ConfigFileWriter.java @@ -34,104 +34,66 @@ public void customizeFileForServiceShape( GenerationContext codegenContext ) { -// -// final LocalServiceTrait localServiceTrait = serviceShape.expectTrait( -// LocalServiceTrait.class -// ); -// final StructureShape configShape = codegenContext -// .model() -// .expectShape(localServiceTrait.getConfigId(), StructureShape.class); -// -// String moduleName = -// SmithyNameResolver.getServiceSmithygeneratedDirectoryNameForNamespace( -// codegenContext.settings().getService().getNamespace() -// ); -// codegenContext -// .writerDelegator() -// .useFileWriter( -// moduleName + "/config.py", -// "", -// writer -> { -// DafnyNameResolver.importDafnyTypeForShape( -// writer, -// configShape.getId(), -// codegenContext -// ); -// -// writer.write( -// """ -// class $L(Config): -// ""\" -// Smithy-modelled localService Config shape for this localService. -// ""\" -// ${C|} -// -// def __init__( -// self, -// ${C|} -// ): -// ${C|} -// super().__init__() -// ${C|} -// -// def dafny_config_to_smithy_config(dafny_config) -> $L: -// ""\" -// Converts the provided Dafny shape for this localService's config -// into the corresponding Smithy-modelled shape. -// ""\" -// ${C|} -// -// def smithy_config_to_dafny_config(smithy_config) -> $L: -// ""\" -// Converts the provided Smithy-modelled shape for this localService's config -// into the corresponding Dafny shape. -// ""\" -// ${C|} -// """, -// configShape.getId().getName(), -// writer.consumer(w -> -// generateConfigClassFields(configShape, codegenContext, w) -// ), -// writer.consumer(w -> -// generateConfigConstructorParameters( -// configShape, -// codegenContext, -// w -// ) -// ), -// writer.consumer(w -> -// generateConfigConstructorDocumentation( -// configShape, -// codegenContext, -// w -// ) -// ), -// writer.consumer(w -> -// generateConfigConstructorFieldAssignments( -// configShape, -// codegenContext, -// w -// ) -// ), -// configShape.getId().getName(), -// writer.consumer(w -> -// generateDafnyConfigToSmithyConfigFunctionBody( -// configShape, -// codegenContext, -// w -// ) -// ), -// DafnyNameResolver.getDafnyTypeForShape(configShape.getId()), -// writer.consumer(w -> -// generateSmithyConfigToDafnyConfigFunctionBody( -// configShape, -// codegenContext, -// w -// ) -// ) -// ); -// } -// ); + return; + + final LocalServiceTrait localServiceTrait = serviceShape.expectTrait( + LocalServiceTrait.class + ); + final StructureShape configShape = codegenContext + .model() + .expectShape(localServiceTrait.getConfigId(), StructureShape.class); + + String moduleName = + SmithyNameResolver.getServiceSmithygeneratedDirectoryNameForNamespace( + codegenContext.settings().getService().getNamespace() + ); + codegenContext + .writerDelegator() + .useFileWriter( + moduleName + "/config.py", + "", + writer -> { + DafnyNameResolver.importDafnyTypeForShape( + writer, + configShape.getId(), + codegenContext + ); + + writer.write( + """ + def dafny_config_to_smithy_config(dafny_config) -> $L: + ""\" + Converts the provided Dafny shape for this localService's config + into the corresponding Smithy-modelled shape. + ""\" + ${C|} + + def smithy_config_to_dafny_config(smithy_config) -> $L: + ""\" + Converts the provided Smithy-modelled shape for this localService's config + into the corresponding Dafny shape. + ""\" + ${C|} + """, + configShape.getId().getName(), + writer.consumer(w -> + generateDafnyConfigToSmithyConfigFunctionBody( + configShape, + codegenContext, + w + ) + ), + DafnyNameResolver.getDafnyTypeForShape(configShape.getId()), + writer.consumer(w -> + generateSmithyConfigToDafnyConfigFunctionBody( + configShape, + codegenContext, + w + ) + ) + ); + } + ); } /** From be0ec9d954ad2213a10187edb33012247a630c47 Mon Sep 17 00:00:00 2001 From: Lucas McDonald Date: Tue, 8 Oct 2024 12:32:37 -0700 Subject: [PATCH 40/76] m --- .../smithypython/localservice/customize/ConfigFileWriter.java | 3 --- 1 file changed, 3 deletions(-) diff --git a/codegen/smithy-dafny-codegen/src/main/java/software/amazon/polymorph/smithypython/localservice/customize/ConfigFileWriter.java b/codegen/smithy-dafny-codegen/src/main/java/software/amazon/polymorph/smithypython/localservice/customize/ConfigFileWriter.java index 32625197d..ac3f09e90 100644 --- a/codegen/smithy-dafny-codegen/src/main/java/software/amazon/polymorph/smithypython/localservice/customize/ConfigFileWriter.java +++ b/codegen/smithy-dafny-codegen/src/main/java/software/amazon/polymorph/smithypython/localservice/customize/ConfigFileWriter.java @@ -33,9 +33,6 @@ public void customizeFileForServiceShape( ServiceShape serviceShape, GenerationContext codegenContext ) { - - return; - final LocalServiceTrait localServiceTrait = serviceShape.expectTrait( LocalServiceTrait.class ); From 67a10e04ac3e5630c8655ab32cdbc11bd895cf26 Mon Sep 17 00:00:00 2001 From: Lucas McDonald Date: Tue, 8 Oct 2024 12:43:56 -0700 Subject: [PATCH 41/76] m --- .../DirectedDafnyPythonLocalServiceCodegen.java | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/codegen/smithy-dafny-codegen/src/main/java/software/amazon/polymorph/smithypython/localservice/extensions/DirectedDafnyPythonLocalServiceCodegen.java b/codegen/smithy-dafny-codegen/src/main/java/software/amazon/polymorph/smithypython/localservice/extensions/DirectedDafnyPythonLocalServiceCodegen.java index 05bbb5dab..b4f69f46e 100644 --- a/codegen/smithy-dafny-codegen/src/main/java/software/amazon/polymorph/smithypython/localservice/extensions/DirectedDafnyPythonLocalServiceCodegen.java +++ b/codegen/smithy-dafny-codegen/src/main/java/software/amazon/polymorph/smithypython/localservice/extensions/DirectedDafnyPythonLocalServiceCodegen.java @@ -19,6 +19,7 @@ import software.amazon.smithy.codegen.core.directed.*; import software.amazon.smithy.model.neighbor.Walker; import software.amazon.smithy.model.shapes.*; +import software.amazon.smithy.model.traits.EnumTrait; import software.amazon.smithy.model.traits.ErrorTrait; import software.amazon.smithy.python.codegen.*; @@ -330,11 +331,11 @@ protected void writeStructureShapeWithErrorTrait( public void generateEnumShape( GenerateEnumDirective directive ) { - writeEnumShape(directive.shape().asEnumShape().get(), directive.context()); + writeEnumShape(directive.shape(), directive.context()); } protected void writeEnumShape( - EnumShape shape, + Shape shape, GenerationContext context ) { if ( @@ -343,6 +344,15 @@ protected void writeEnumShape( .getNamespace() .equals(context.settings().getService().getNamespace()) ) { + EnumShape enumShape; + if (shape.isEnumShape()) { + enumShape = shape.asEnumShape().get(); + } else if (shape.isStringShape()) { + enumShape = EnumShape.fromStringShape(shape.asStringShape().get()).get(); + } else { + throw new IllegalArgumentException("Shape cannot be interpreted as EnumShape: " + shape.getId()); + } + context .writerDelegator() .useShapeWriter( @@ -352,7 +362,7 @@ protected void writeEnumShape( context.model(), context.symbolProvider(), writer, - shape + enumShape ); generator.run(); } From 24c14a986669ceb36c7b039d1c03d6374f0f2866 Mon Sep 17 00:00:00 2001 From: Lucas McDonald Date: Tue, 8 Oct 2024 12:44:03 -0700 Subject: [PATCH 42/76] m --- .../extensions/DirectedDafnyPythonLocalServiceCodegen.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/codegen/smithy-dafny-codegen/src/main/java/software/amazon/polymorph/smithypython/localservice/extensions/DirectedDafnyPythonLocalServiceCodegen.java b/codegen/smithy-dafny-codegen/src/main/java/software/amazon/polymorph/smithypython/localservice/extensions/DirectedDafnyPythonLocalServiceCodegen.java index b4f69f46e..db0e44cea 100644 --- a/codegen/smithy-dafny-codegen/src/main/java/software/amazon/polymorph/smithypython/localservice/extensions/DirectedDafnyPythonLocalServiceCodegen.java +++ b/codegen/smithy-dafny-codegen/src/main/java/software/amazon/polymorph/smithypython/localservice/extensions/DirectedDafnyPythonLocalServiceCodegen.java @@ -356,7 +356,7 @@ protected void writeEnumShape( context .writerDelegator() .useShapeWriter( - shape, + enumShape, writer -> { EnumGenerator generator = new EnumGenerator( context.model(), From 6a3e83381d6084f19b4aa241e05bc59c8cf55643 Mon Sep 17 00:00:00 2001 From: Lucas McDonald Date: Tue, 8 Oct 2024 12:46:11 -0700 Subject: [PATCH 43/76] m --- .../extensions/DirectedDafnyPythonLocalServiceCodegen.java | 1 + 1 file changed, 1 insertion(+) diff --git a/codegen/smithy-dafny-codegen/src/main/java/software/amazon/polymorph/smithypython/localservice/extensions/DirectedDafnyPythonLocalServiceCodegen.java b/codegen/smithy-dafny-codegen/src/main/java/software/amazon/polymorph/smithypython/localservice/extensions/DirectedDafnyPythonLocalServiceCodegen.java index db0e44cea..321976e19 100644 --- a/codegen/smithy-dafny-codegen/src/main/java/software/amazon/polymorph/smithypython/localservice/extensions/DirectedDafnyPythonLocalServiceCodegen.java +++ b/codegen/smithy-dafny-codegen/src/main/java/software/amazon/polymorph/smithypython/localservice/extensions/DirectedDafnyPythonLocalServiceCodegen.java @@ -345,6 +345,7 @@ protected void writeEnumShape( .equals(context.settings().getService().getNamespace()) ) { EnumShape enumShape; + System.out.println("maybe enum " + shape.getId()); if (shape.isEnumShape()) { enumShape = shape.asEnumShape().get(); } else if (shape.isStringShape()) { From ef3040ebe7aa49008daf757c5f9cb9a4d0f18db9 Mon Sep 17 00:00:00 2001 From: Lucas McDonald Date: Tue, 8 Oct 2024 12:50:41 -0700 Subject: [PATCH 44/76] m --- ...PythonLocalServiceClientCodegenPlugin.java | 59 ------------------- ...rappedLocalServiceClientCodegenPlugin.java | 22 ++++++- 2 files changed, 21 insertions(+), 60 deletions(-) diff --git a/codegen/smithy-dafny-codegen/src/main/java/software/amazon/polymorph/smithypython/localservice/extensions/DafnyPythonLocalServiceClientCodegenPlugin.java b/codegen/smithy-dafny-codegen/src/main/java/software/amazon/polymorph/smithypython/localservice/extensions/DafnyPythonLocalServiceClientCodegenPlugin.java index fbd9667d2..f0178dd69 100644 --- a/codegen/smithy-dafny-codegen/src/main/java/software/amazon/polymorph/smithypython/localservice/extensions/DafnyPythonLocalServiceClientCodegenPlugin.java +++ b/codegen/smithy-dafny-codegen/src/main/java/software/amazon/polymorph/smithypython/localservice/extensions/DafnyPythonLocalServiceClientCodegenPlugin.java @@ -109,7 +109,6 @@ public static Model transformModelForLocalService( serviceShape ); transformedModel = transformStringEnumShapesToEnumShapes(transformedModel); - transformedModel = transformServiceShapeToAddOrphanedShapes(transformedModel, serviceShape); return transformedModel; } @@ -212,64 +211,6 @@ public static Model transformServiceShapeToAddReferenceResources( ); } - /** - * Smithy plugins require that resource shapes are attached to a ServiceShape. - * Smithy plugins also do not understand Polymorph's {@link ReferenceTrait} and will not - * discover the linked shape. - * This parses Polymorph's ReferenceTrait to attach any referenced resources to the {@param serviceShape} - * so the Smithy plugin's shape discovery can find the shape. - * @param model - * @return - */ - public static Model transformServiceShapeToAddOrphanedShapes( - Model model, - ServiceShape serviceShape - ) { - return model; -// ServiceShape.Builder transformedServiceShapeBuilder = -// serviceShape.toBuilder(); -// -// Shape configShape = model.expectShape(serviceShape.getTrait(LocalServiceTrait.class).get().getConfigId()); -// -// transformedServiceShapeBuilder.addMixin( -// MemberShape.builder() -// .target(configShape.getId()) -// .id(ShapeId.from(serviceShape.getId() + "$" + configShape.getId().getName())) -// .build() -// ); - -// ModelTransformer -// .create() -// .mapShapes( -// model, -// shape -> { -// if (!knownShapes.contains(shape) -// && shape.getId().getNamespace().equals(serviceShape.getId().getNamespace()) -// && (shape.isStructureShape() || shape.isUnionShape()) -// && !serviceShape.getOperations().contains(shape.getId()) -// ) { -// System.out.println("not in: " + shape.getId()); -// } -// return shape; -// } -// ); -// -// System.out.println("size = " + TopologicalIndex.of(model).getRecursiveShapes().size()); -// -// return ModelTransformer -// .create() -// .mapShapes( -// model, -// shape -> { -// if (shape.getId().equals(serviceShape.getId())) { -// return transformedServiceShapeBuilder.build(); -// } else { -// return shape; -// } -// } -// ); - } - /** * Replace any StringShapes with EnumTraits * with StringShapes. diff --git a/codegen/smithy-dafny-codegen/src/main/java/software/amazon/polymorph/smithypython/wrappedlocalservice/extensions/DafnyPythonWrappedLocalServiceClientCodegenPlugin.java b/codegen/smithy-dafny-codegen/src/main/java/software/amazon/polymorph/smithypython/wrappedlocalservice/extensions/DafnyPythonWrappedLocalServiceClientCodegenPlugin.java index 9a3605d52..f4c7d178c 100644 --- a/codegen/smithy-dafny-codegen/src/main/java/software/amazon/polymorph/smithypython/wrappedlocalservice/extensions/DafnyPythonWrappedLocalServiceClientCodegenPlugin.java +++ b/codegen/smithy-dafny-codegen/src/main/java/software/amazon/polymorph/smithypython/wrappedlocalservice/extensions/DafnyPythonWrappedLocalServiceClientCodegenPlugin.java @@ -19,6 +19,8 @@ import software.amazon.smithy.python.codegen.integration.PythonIntegration; import software.amazon.smithy.utils.SmithyUnstableApi; +import static software.amazon.polymorph.smithypython.localservice.extensions.DafnyPythonLocalServiceClientCodegenPlugin.transformStringEnumShapesToEnumShapes; + /** * Plugin to trigger Smithy-Dafny Python code generation for a wrapped localService. * This differs from the PythonClientCodegenPlugin by not calling `runner.performDefaultCodegenTransforms()` @@ -41,6 +43,24 @@ public DafnyPythonWrappedLocalServiceClientCodegenPlugin( ); } + /** + * Perform all transformations on the model before running localService codegen. + * @param model + * @param serviceShape + * @return + */ + public static Model transformModelForWrappedLocalService( + Model model, + ServiceShape serviceShape + ) { + Model transformedModel = model; + transformedModel = + addWrappedLocalServiceTrait(transformedModel, serviceShape); + transformedModel = + transformStringEnumShapesToEnumShapes(transformedModel); + return transformedModel; + } + /** * Add the {@link WrappedLocalServiceTrait} to the serviceShape in the model. This is required to * allow Smithy-Python to function correctly. @@ -105,7 +125,7 @@ public void execute(PluginContext context) { .expectShape(settings.getService()) .asServiceShape() .get(); - Model transformedModel = addWrappedLocalServiceTrait( + Model transformedModel = transformModelForWrappedLocalService( context.getModel(), serviceShape ); From a2672bb44f06f11519993f2a0c16dc69b5e21192 Mon Sep 17 00:00:00 2001 From: Lucas McDonald Date: Tue, 8 Oct 2024 15:40:46 -0700 Subject: [PATCH 45/76] m --- .../python/codegen/StructureGenerator.java | 2 +- .../customize/ConfigFileWriter.java | 17 +++++ ...yPythonLocalServiceStructureGenerator.java | 63 ++++++++++++++++++- 3 files changed, 79 insertions(+), 3 deletions(-) diff --git a/codegen/smithy-dafny-codegen-modules/smithy-python/codegen/smithy-python-codegen/src/main/java/software/amazon/smithy/python/codegen/StructureGenerator.java b/codegen/smithy-dafny-codegen-modules/smithy-python/codegen/smithy-python-codegen/src/main/java/software/amazon/smithy/python/codegen/StructureGenerator.java index e0b5bdf33..cb70b8980 100644 --- a/codegen/smithy-dafny-codegen-modules/smithy-python/codegen/smithy-python-codegen/src/main/java/software/amazon/smithy/python/codegen/StructureGenerator.java +++ b/codegen/smithy-dafny-codegen-modules/smithy-python/codegen/smithy-python-codegen/src/main/java/software/amazon/smithy/python/codegen/StructureGenerator.java @@ -252,7 +252,7 @@ protected boolean isOptionalDefault(MemberShape member) { && (target.isDocumentShape() || target.isListShape() || target.isMapShape()); } - private void writeClassDocs(boolean isError) { + protected void writeClassDocs(boolean isError) { if (hasDocs()) { writer.writeDocs(() -> { shape.getTrait(DocumentationTrait.class).ifPresent(trait -> { diff --git a/codegen/smithy-dafny-codegen/src/main/java/software/amazon/polymorph/smithypython/localservice/customize/ConfigFileWriter.java b/codegen/smithy-dafny-codegen/src/main/java/software/amazon/polymorph/smithypython/localservice/customize/ConfigFileWriter.java index ac3f09e90..b6ab410a2 100644 --- a/codegen/smithy-dafny-codegen/src/main/java/software/amazon/polymorph/smithypython/localservice/customize/ConfigFileWriter.java +++ b/codegen/smithy-dafny-codegen/src/main/java/software/amazon/polymorph/smithypython/localservice/customize/ConfigFileWriter.java @@ -33,6 +33,9 @@ public void customizeFileForServiceShape( ServiceShape serviceShape, GenerationContext codegenContext ) { + + return; + final LocalServiceTrait localServiceTrait = serviceShape.expectTrait( LocalServiceTrait.class ); @@ -58,6 +61,20 @@ public void customizeFileForServiceShape( writer.write( """ + class $L(Config): + ""\" + Smithy-modelled localService Config shape for this localService. + ""\" + ${C|} + + def __init__( + self, + ${C|} + ): + ${C|} + super().__init__() + ${C|} + def dafny_config_to_smithy_config(dafny_config) -> $L: ""\" Converts the provided Dafny shape for this localService's config diff --git a/codegen/smithy-dafny-codegen/src/main/java/software/amazon/polymorph/smithypython/localservice/extensions/DafnyPythonLocalServiceStructureGenerator.java b/codegen/smithy-dafny-codegen/src/main/java/software/amazon/polymorph/smithypython/localservice/extensions/DafnyPythonLocalServiceStructureGenerator.java index 1730b1de5..6ad4ea6f8 100644 --- a/codegen/smithy-dafny-codegen/src/main/java/software/amazon/polymorph/smithypython/localservice/extensions/DafnyPythonLocalServiceStructureGenerator.java +++ b/codegen/smithy-dafny-codegen/src/main/java/software/amazon/polymorph/smithypython/localservice/extensions/DafnyPythonLocalServiceStructureGenerator.java @@ -5,8 +5,11 @@ import static software.amazon.smithy.utils.StringUtils.capitalize; import java.util.Set; +import java.util.stream.Stream; + import software.amazon.polymorph.smithypython.common.nameresolver.SmithyNameResolver; import software.amazon.polymorph.smithypython.localservice.ConstraintUtils; +import software.amazon.polymorph.traits.LocalServiceTrait; import software.amazon.polymorph.traits.PositionalTrait; import software.amazon.polymorph.traits.ReferenceTrait; import software.amazon.polymorph.utils.ConstrainTraitUtils; @@ -16,6 +19,7 @@ import software.amazon.smithy.model.knowledge.NullableIndex; import software.amazon.smithy.model.shapes.MemberShape; import software.amazon.smithy.model.shapes.Shape; +import software.amazon.smithy.model.shapes.ShapeId; import software.amazon.smithy.model.shapes.StructureShape; import software.amazon.smithy.model.traits.*; import software.amazon.smithy.python.codegen.PythonSettings; @@ -45,17 +49,72 @@ public DafnyPythonLocalServiceStructureGenerator( @Override public void run() { + Set localServiceConfigShapes = + SmithyNameResolver.getLocalServiceConfigShapes(model); + if (shape.hasTrait(PositionalTrait.class)) { // Do not need to render shapes with positional trait, their linked shapes are rendered return; - } - if (!shape.hasTrait(ErrorTrait.class)) { + } else if (localServiceConfigShapes.contains(shape.getId())) { + renderLocalServiceConfigShape(); + } else if (!shape.hasTrait(ErrorTrait.class)) { renderStructure(); } else { renderError(); } } + /** + * Renders a normal, non-error structure. + */ + protected void renderLocalServiceConfigShape() { + writer.addStdlibImport("typing", "Dict"); + writer.addStdlibImport("typing", "Any"); + var symbol = symbolProvider.toSymbol(shape); + writer.openBlock("class $L(Config):", "", symbol.getName(), () -> { + writeProperties(false); + writeLocalServiceInit(false); + writeAsDict(false); + writeFromDict(false); + writeRepr(false); + writeEq(false); + }); + writer.write(""); + } + + + protected void writeLocalServiceInit() { + + writer.openBlock("def __init__(", "):", () -> { + writer.write("self,"); + if (!shape.members().isEmpty()) { + // Adding this star to the front prevents the use of positional arguments. + writer.write("*,"); + } + for (MemberShape member : requiredMembers) { + writeInitMethodParameterForRequiredMember(false, member); + } + for (MemberShape member : optionalMembers) { + writeInitMethodParameterForOptionalMember(false, member); + } + }); + + writer.indent(); + writer.write("super().__init__(message)"); + + + Stream.concat(requiredMembers.stream(), optionalMembers.stream()).forEach(member -> { + String memberName = symbolProvider.toMemberName(member); + if (isOptionalDefault(member)) { + writeInitMethodAssignerForOptionalMember(member, memberName); + } else { + writeInitMethodAssignerForRequiredMember(member, memberName); + } + }); + writer.dedent(); + writer.write(""); + } + /** * Override Smithy-Python renderError to use the correct namespace via * getPythonModuleSmithygeneratedPathForSmithyNamespace. From 91cc5356af3f4de4c3dca0041d41f4bcb2f2e956 Mon Sep 17 00:00:00 2001 From: Lucas McDonald Date: Tue, 8 Oct 2024 15:41:55 -0700 Subject: [PATCH 46/76] m --- .../extensions/DafnyPythonLocalServiceStructureGenerator.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/codegen/smithy-dafny-codegen/src/main/java/software/amazon/polymorph/smithypython/localservice/extensions/DafnyPythonLocalServiceStructureGenerator.java b/codegen/smithy-dafny-codegen/src/main/java/software/amazon/polymorph/smithypython/localservice/extensions/DafnyPythonLocalServiceStructureGenerator.java index 6ad4ea6f8..9f9a8c02d 100644 --- a/codegen/smithy-dafny-codegen/src/main/java/software/amazon/polymorph/smithypython/localservice/extensions/DafnyPythonLocalServiceStructureGenerator.java +++ b/codegen/smithy-dafny-codegen/src/main/java/software/amazon/polymorph/smithypython/localservice/extensions/DafnyPythonLocalServiceStructureGenerator.java @@ -73,7 +73,7 @@ protected void renderLocalServiceConfigShape() { var symbol = symbolProvider.toSymbol(shape); writer.openBlock("class $L(Config):", "", symbol.getName(), () -> { writeProperties(false); - writeLocalServiceInit(false); + writeLocalServiceInit(); writeAsDict(false); writeFromDict(false); writeRepr(false); From e7a024aebe46d5f53824f2af91c5dd9eacaf4c74 Mon Sep 17 00:00:00 2001 From: Lucas McDonald Date: Tue, 8 Oct 2024 15:42:18 -0700 Subject: [PATCH 47/76] m --- .../localservice/customize/ConfigFileWriter.java | 15 --------------- 1 file changed, 15 deletions(-) diff --git a/codegen/smithy-dafny-codegen/src/main/java/software/amazon/polymorph/smithypython/localservice/customize/ConfigFileWriter.java b/codegen/smithy-dafny-codegen/src/main/java/software/amazon/polymorph/smithypython/localservice/customize/ConfigFileWriter.java index b6ab410a2..1629386c0 100644 --- a/codegen/smithy-dafny-codegen/src/main/java/software/amazon/polymorph/smithypython/localservice/customize/ConfigFileWriter.java +++ b/codegen/smithy-dafny-codegen/src/main/java/software/amazon/polymorph/smithypython/localservice/customize/ConfigFileWriter.java @@ -34,7 +34,6 @@ public void customizeFileForServiceShape( GenerationContext codegenContext ) { - return; final LocalServiceTrait localServiceTrait = serviceShape.expectTrait( LocalServiceTrait.class @@ -61,20 +60,6 @@ public void customizeFileForServiceShape( writer.write( """ - class $L(Config): - ""\" - Smithy-modelled localService Config shape for this localService. - ""\" - ${C|} - - def __init__( - self, - ${C|} - ): - ${C|} - super().__init__() - ${C|} - def dafny_config_to_smithy_config(dafny_config) -> $L: ""\" Converts the provided Dafny shape for this localService's config From 8d720614e6fa67c2f6b32e505d85a8671d6218a0 Mon Sep 17 00:00:00 2001 From: Lucas McDonald Date: Tue, 8 Oct 2024 15:52:42 -0700 Subject: [PATCH 48/76] m --- ...yPythonLocalServiceStructureGenerator.java | 24 ++++++++++++------- 1 file changed, 16 insertions(+), 8 deletions(-) diff --git a/codegen/smithy-dafny-codegen/src/main/java/software/amazon/polymorph/smithypython/localservice/extensions/DafnyPythonLocalServiceStructureGenerator.java b/codegen/smithy-dafny-codegen/src/main/java/software/amazon/polymorph/smithypython/localservice/extensions/DafnyPythonLocalServiceStructureGenerator.java index 9f9a8c02d..d4ab27bfe 100644 --- a/codegen/smithy-dafny-codegen/src/main/java/software/amazon/polymorph/smithypython/localservice/extensions/DafnyPythonLocalServiceStructureGenerator.java +++ b/codegen/smithy-dafny-codegen/src/main/java/software/amazon/polymorph/smithypython/localservice/extensions/DafnyPythonLocalServiceStructureGenerator.java @@ -7,6 +7,7 @@ import java.util.Set; import java.util.stream.Stream; +import software.amazon.polymorph.smithypython.awssdk.nameresolver.AwsSdkNameResolver; import software.amazon.polymorph.smithypython.common.nameresolver.SmithyNameResolver; import software.amazon.polymorph.smithypython.localservice.ConstraintUtils; import software.amazon.polymorph.traits.LocalServiceTrait; @@ -100,8 +101,9 @@ protected void writeLocalServiceInit() { }); writer.indent(); - writer.write("super().__init__(message)"); + writeClassDocs(false); + writer.write("super().__init__()"); Stream.concat(requiredMembers.stream(), optionalMembers.stream()).forEach(member -> { String memberName = symbolProvider.toMemberName(member); @@ -262,7 +264,10 @@ protected void writePropertyForMember( ); } - if (target.hasTrait(ReferenceTrait.class)) { + // Reference shapes require forward reference to avoid circular import, + // but AWS SDKs don't + if (target.hasTrait(ReferenceTrait.class) + && !AwsSdkNameResolver.isAwsSdkShape(target)) { Shape referentShape = model.expectShape( target.expectTrait(ReferenceTrait.class).getReferentId() ); @@ -446,12 +451,15 @@ protected void writeFromDict(boolean isError) { for (MemberShape memberShape : shape.members()) { var target = model.expectShape(memberShape.getTarget()); if (target.hasTrait(ReferenceTrait.class)) { - Symbol targetSymbol = symbolProvider.toSymbol(target); - writer.write( - "from $L import $L", - targetSymbol.getNamespace(), - targetSymbol.getName() - ); + // Don't need to import boto3 BaseClient + if (!AwsSdkNameResolver.isAwsSdkShape(target)) { + Symbol targetSymbol = symbolProvider.toSymbol(target); + writer.write( + "from $L import $L", + targetSymbol.getNamespace(), + targetSymbol.getName() + ); + } } } From f088d985268dc01e1ce3ae9a6942bcfa5860feb2 Mon Sep 17 00:00:00 2001 From: Lucas McDonald Date: Tue, 8 Oct 2024 15:56:36 -0700 Subject: [PATCH 49/76] m --- .../extensions/DafnyPythonLocalServiceStructureGenerator.java | 1 + 1 file changed, 1 insertion(+) diff --git a/codegen/smithy-dafny-codegen/src/main/java/software/amazon/polymorph/smithypython/localservice/extensions/DafnyPythonLocalServiceStructureGenerator.java b/codegen/smithy-dafny-codegen/src/main/java/software/amazon/polymorph/smithypython/localservice/extensions/DafnyPythonLocalServiceStructureGenerator.java index d4ab27bfe..73c805422 100644 --- a/codegen/smithy-dafny-codegen/src/main/java/software/amazon/polymorph/smithypython/localservice/extensions/DafnyPythonLocalServiceStructureGenerator.java +++ b/codegen/smithy-dafny-codegen/src/main/java/software/amazon/polymorph/smithypython/localservice/extensions/DafnyPythonLocalServiceStructureGenerator.java @@ -453,6 +453,7 @@ protected void writeFromDict(boolean isError) { if (target.hasTrait(ReferenceTrait.class)) { // Don't need to import boto3 BaseClient if (!AwsSdkNameResolver.isAwsSdkShape(target)) { + System.out.println("boto3 target: " + target); Symbol targetSymbol = symbolProvider.toSymbol(target); writer.write( "from $L import $L", From cfb9c4252eed1cd9781da8bcd0672cd28d1f2241 Mon Sep 17 00:00:00 2001 From: Lucas McDonald Date: Tue, 8 Oct 2024 15:58:56 -0700 Subject: [PATCH 50/76] m --- ...yPythonLocalServiceStructureGenerator.java | 224 ++++++++---------- 1 file changed, 99 insertions(+), 125 deletions(-) diff --git a/codegen/smithy-dafny-codegen/src/main/java/software/amazon/polymorph/smithypython/localservice/extensions/DafnyPythonLocalServiceStructureGenerator.java b/codegen/smithy-dafny-codegen/src/main/java/software/amazon/polymorph/smithypython/localservice/extensions/DafnyPythonLocalServiceStructureGenerator.java index 73c805422..76dd44e25 100644 --- a/codegen/smithy-dafny-codegen/src/main/java/software/amazon/polymorph/smithypython/localservice/extensions/DafnyPythonLocalServiceStructureGenerator.java +++ b/codegen/smithy-dafny-codegen/src/main/java/software/amazon/polymorph/smithypython/localservice/extensions/DafnyPythonLocalServiceStructureGenerator.java @@ -267,7 +267,7 @@ protected void writePropertyForMember( // Reference shapes require forward reference to avoid circular import, // but AWS SDKs don't if (target.hasTrait(ReferenceTrait.class) - && !AwsSdkNameResolver.isAwsSdkShape(target)) { + && !AwsSdkNameResolver.isAwsSdkShape(target.expectTrait(ReferenceTrait.class).getReferentId())) { Shape referentShape = model.expectShape( target.expectTrait(ReferenceTrait.class).getReferentId() ); @@ -432,138 +432,112 @@ protected void writeFromDict(boolean isError) { writer.write("@staticmethod"); var shapeName = symbolProvider.toSymbol(shape).getName(); writer.openBlock( - "def from_dict(d: Dict[str, Any]) -> $S:", - "", - shapeName, - () -> { - writer.writeDocs(() -> { - writer.write("Creates a $L from a dictionary.\n", shapeName); - }); - - if (shape.members().isEmpty() && !isError) { - writer.write("return $L()", shapeName); - return; - } + "def from_dict(d: Dict[str, Any]) -> $S:", + "", + shapeName, + () -> { + writer.writeDocs( + () -> { + writer.write("Creates a $L from a dictionary.\n", shapeName); + }); - // Block below is changed from Smithy-Python. - // Import any modules required for reference shapes to convert from_dict. - // Import within function to avoid circular imports from top-level imports - for (MemberShape memberShape : shape.members()) { - var target = model.expectShape(memberShape.getTarget()); - if (target.hasTrait(ReferenceTrait.class)) { - // Don't need to import boto3 BaseClient - if (!AwsSdkNameResolver.isAwsSdkShape(target)) { - System.out.println("boto3 target: " + target); - Symbol targetSymbol = symbolProvider.toSymbol(target); - writer.write( - "from $L import $L", - targetSymbol.getNamespace(), - targetSymbol.getName() - ); - } + if (shape.members().isEmpty() && !isError) { + writer.write("return $L()", shapeName); + return; } - } - if (requiredMembers.isEmpty() && !isError) { - writer.write("kwargs: Dict[str, Any] = {}"); - } else { - writer.openBlock( - "kwargs: Dict[str, Any] = {", - "}", - () -> { - if (isError) { - writer.write("'message': d['message'],"); - } - for (MemberShape member : requiredMembers) { - var memberName = symbolProvider.toMemberName(member); - var target = model.expectShape(member.getTarget()); + // Block below is changed from Smithy-Python. + // Import any modules required for reference shapes to convert from_dict. + // Import within function to avoid circular imports from top-level imports + for (MemberShape memberShape : shape.members()) { + var target = model.expectShape(memberShape.getTarget()); + if (target.hasTrait(ReferenceTrait.class)) { + // Don't need to import boto3 BaseClient + if (!AwsSdkNameResolver.isAwsSdkShape( + target.getTrait(ReferenceTrait.class).get().getReferentId())) { + System.out.println("boto3 target: " + target); Symbol targetSymbol = symbolProvider.toSymbol(target); - // Block below is changed from Smithy-Python. - // If passing a boto3 client, just pass the client. - // Also, use snakecase member name inside the dictionary. - if ( - target.hasTrait(ReferenceTrait.class) && - target.expectTrait(ReferenceTrait.class).isService() && - isAwsSdkShape( - target.expectTrait(ReferenceTrait.class).getReferentId() - ) - ) { - writer.write("$S: d[$S],", memberName, memberName); - } else if (target.isStructureShape()) { - writer.write( - "$S: $L.from_dict(d[$S]),", - memberName, - targetSymbol.getName(), - memberName - ); - } else if (targetSymbol.getProperty("fromDict").isPresent()) { - var targetFromDictSymbol = targetSymbol.expectProperty( - "fromDict", - Symbol.class - ); - writer.write( - "$S: $T(d[$S]),", - memberName, - targetFromDictSymbol, - memberName - ); - } else { - writer.write("$S: d[$S],", memberName, memberName); - } - } - } - ); - } - writer.write(""); - - for (MemberShape member : optionalMembers) { - var memberName = symbolProvider.toMemberName(member); - var target = model.expectShape(member.getTarget()); - writer.openBlock( - "if $S in d:", - "", - memberName, - () -> { - var targetSymbol = symbolProvider.toSymbol(target); - // Block below is changed from Smithy-Python. - // If passing a boto3 client, just pass the client. - // Also, use snakecase member name inside the dictionary. - if ( - target.hasTrait(ReferenceTrait.class) && - target.expectTrait(ReferenceTrait.class).isService() && - isAwsSdkShape( - target.expectTrait(ReferenceTrait.class).getReferentId() - ) - ) { - writer.write("kwargs[$S] = d[$S]", memberName, memberName); - } else if (target.isStructureShape()) { - writer.write( - "kwargs[$S] = $L.from_dict(d[$S])", - memberName, - targetSymbol.getName(), - memberName - ); - } else if (targetSymbol.getProperty("fromDict").isPresent()) { - var targetFromDictSymbol = targetSymbol.expectProperty( - "fromDict", - Symbol.class - ); writer.write( - "kwargs[$S] = $T(d[$S]),", - memberName, - targetFromDictSymbol, - memberName - ); - } else { - writer.write("kwargs[$S] = d[$S]", memberName, memberName); + "from $L import $L", targetSymbol.getNamespace(), targetSymbol.getName()); } } - ); - } + } - writer.write("return $L(**kwargs)", shapeName); - } - ); + if (requiredMembers.isEmpty() && !isError) { + writer.write("kwargs: Dict[str, Any] = {}"); + } else { + writer.openBlock( + "kwargs: Dict[str, Any] = {", + "}", + () -> { + if (isError) { + writer.write("'message': d['message'],"); + } + for (MemberShape member : requiredMembers) { + var memberName = symbolProvider.toMemberName(member); + var target = model.expectShape(member.getTarget()); + Symbol targetSymbol = symbolProvider.toSymbol(target); + // Block below is changed from Smithy-Python. + // If passing a boto3 client, just pass the client. + // Also, use snakecase member name inside the dictionary. + if (target.hasTrait(ReferenceTrait.class) + && target.expectTrait(ReferenceTrait.class).isService() + && isAwsSdkShape( + target.expectTrait(ReferenceTrait.class).getReferentId())) { + writer.write("$S: d[$S],", memberName, memberName); + } else if (target.isStructureShape()) { + writer.write( + "$S: $L.from_dict(d[$S]),", + memberName, + targetSymbol.getName(), + memberName); + } else if (targetSymbol.getProperty("fromDict").isPresent()) { + var targetFromDictSymbol = + targetSymbol.expectProperty("fromDict", Symbol.class); + writer.write("$S: $T(d[$S]),", memberName, targetFromDictSymbol, memberName); + } else { + writer.write("$S: d[$S],", memberName, memberName); + } + } + }); + } + writer.write(""); + + for (MemberShape member : optionalMembers) { + var memberName = symbolProvider.toMemberName(member); + var target = model.expectShape(member.getTarget()); + writer.openBlock( + "if $S in d:", + "", + memberName, + () -> { + var targetSymbol = symbolProvider.toSymbol(target); + // Block below is changed from Smithy-Python. + // If passing a boto3 client, just pass the client. + // Also, use snakecase member name inside the dictionary. + if (target.hasTrait(ReferenceTrait.class) + && target.expectTrait(ReferenceTrait.class).isService() + && isAwsSdkShape(target.expectTrait(ReferenceTrait.class).getReferentId())) { + writer.write("kwargs[$S] = d[$S]", memberName, memberName); + } else if (target.isStructureShape()) { + writer.write( + "kwargs[$S] = $L.from_dict(d[$S])", + memberName, + targetSymbol.getName(), + memberName); + } else if (targetSymbol.getProperty("fromDict").isPresent()) { + var targetFromDictSymbol = + targetSymbol.expectProperty("fromDict", Symbol.class); + writer.write( + "kwargs[$S] = $T(d[$S]),", memberName, targetFromDictSymbol, memberName); + } else { + writer.write("kwargs[$S] = d[$S]", memberName, memberName); + } + }); + } + + writer.write("return $L(**kwargs)", shapeName); + }); writer.write(""); } From bf8b764f1fa1a9ab9e24ab4756362e80d939e0d4 Mon Sep 17 00:00:00 2001 From: Lucas McDonald Date: Tue, 8 Oct 2024 16:01:56 -0700 Subject: [PATCH 51/76] m --- ...yPythonLocalServiceStructureGenerator.java | 22 +++++++++++-------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/codegen/smithy-dafny-codegen/src/main/java/software/amazon/polymorph/smithypython/localservice/extensions/DafnyPythonLocalServiceStructureGenerator.java b/codegen/smithy-dafny-codegen/src/main/java/software/amazon/polymorph/smithypython/localservice/extensions/DafnyPythonLocalServiceStructureGenerator.java index 76dd44e25..5aeb1b367 100644 --- a/codegen/smithy-dafny-codegen/src/main/java/software/amazon/polymorph/smithypython/localservice/extensions/DafnyPythonLocalServiceStructureGenerator.java +++ b/codegen/smithy-dafny-codegen/src/main/java/software/amazon/polymorph/smithypython/localservice/extensions/DafnyPythonLocalServiceStructureGenerator.java @@ -265,7 +265,7 @@ protected void writePropertyForMember( } // Reference shapes require forward reference to avoid circular import, - // but AWS SDKs don't + // but references to AWS SDKs don't if (target.hasTrait(ReferenceTrait.class) && !AwsSdkNameResolver.isAwsSdkShape(target.expectTrait(ReferenceTrait.class).getReferentId())) { Shape referentShape = model.expectShape( @@ -361,7 +361,10 @@ protected void writeInitMethodParameterForRequiredMember( ); } - if (target.hasTrait(ReferenceTrait.class)) { + // Reference shapes require forward reference to avoid circular import, + // but references to AWS SDKs don't + if (target.hasTrait(ReferenceTrait.class) + && !AwsSdkNameResolver.isAwsSdkShape(target.expectTrait(ReferenceTrait.class).getReferentId())) { Shape referentShape = model.expectShape( target.expectTrait(ReferenceTrait.class).getReferentId() ); @@ -397,7 +400,10 @@ protected void writeInitMethodParameterForOptionalMember( ) { Shape target = model.expectShape(memberShape.getTarget()); - if (target.hasTrait(ReferenceTrait.class)) { + // Reference shapes require forward reference to avoid circular import, + // but references to AWS SDKs don't + if (target.hasTrait(ReferenceTrait.class) + && !AwsSdkNameResolver.isAwsSdkShape(target.expectTrait(ReferenceTrait.class).getReferentId())) { Shape referentShape = model.expectShape( target.expectTrait(ReferenceTrait.class).getReferentId() ); @@ -451,15 +457,13 @@ protected void writeFromDict(boolean isError) { // Import within function to avoid circular imports from top-level imports for (MemberShape memberShape : shape.members()) { var target = model.expectShape(memberShape.getTarget()); - if (target.hasTrait(ReferenceTrait.class)) { - // Don't need to import boto3 BaseClient - if (!AwsSdkNameResolver.isAwsSdkShape( - target.getTrait(ReferenceTrait.class).get().getReferentId())) { - System.out.println("boto3 target: " + target); + // Reference shapes require forward reference to avoid circular import, + // but references to AWS SDKs don't + if (target.hasTrait(ReferenceTrait.class) + && !AwsSdkNameResolver.isAwsSdkShape(target.getTrait(ReferenceTrait.class).get().getReferentId())) { Symbol targetSymbol = symbolProvider.toSymbol(target); writer.write( "from $L import $L", targetSymbol.getNamespace(), targetSymbol.getName()); - } } } From 1596a4b41241c33208dc9f6753e76dd5eaf9dc6e Mon Sep 17 00:00:00 2001 From: Lucas McDonald Date: Tue, 8 Oct 2024 16:12:08 -0700 Subject: [PATCH 52/76] m --- .../customize/ConfigFileWriter.java | 2 -- ...PythonLocalServiceClientCodegenPlugin.java | 11 ++++------ ...yPythonLocalServiceStructureGenerator.java | 20 ++++++++++++++++--- 3 files changed, 21 insertions(+), 12 deletions(-) diff --git a/codegen/smithy-dafny-codegen/src/main/java/software/amazon/polymorph/smithypython/localservice/customize/ConfigFileWriter.java b/codegen/smithy-dafny-codegen/src/main/java/software/amazon/polymorph/smithypython/localservice/customize/ConfigFileWriter.java index 1629386c0..ac3f09e90 100644 --- a/codegen/smithy-dafny-codegen/src/main/java/software/amazon/polymorph/smithypython/localservice/customize/ConfigFileWriter.java +++ b/codegen/smithy-dafny-codegen/src/main/java/software/amazon/polymorph/smithypython/localservice/customize/ConfigFileWriter.java @@ -33,8 +33,6 @@ public void customizeFileForServiceShape( ServiceShape serviceShape, GenerationContext codegenContext ) { - - final LocalServiceTrait localServiceTrait = serviceShape.expectTrait( LocalServiceTrait.class ); diff --git a/codegen/smithy-dafny-codegen/src/main/java/software/amazon/polymorph/smithypython/localservice/extensions/DafnyPythonLocalServiceClientCodegenPlugin.java b/codegen/smithy-dafny-codegen/src/main/java/software/amazon/polymorph/smithypython/localservice/extensions/DafnyPythonLocalServiceClientCodegenPlugin.java index f0178dd69..c99824b2c 100644 --- a/codegen/smithy-dafny-codegen/src/main/java/software/amazon/polymorph/smithypython/localservice/extensions/DafnyPythonLocalServiceClientCodegenPlugin.java +++ b/codegen/smithy-dafny-codegen/src/main/java/software/amazon/polymorph/smithypython/localservice/extensions/DafnyPythonLocalServiceClientCodegenPlugin.java @@ -4,21 +4,18 @@ package software.amazon.polymorph.smithypython.localservice.extensions; import java.util.Map; -import java.util.Set; -import java.util.stream.Collectors; - import software.amazon.polymorph.smithypython.common.nameresolver.SmithyNameResolver; import software.amazon.polymorph.traits.JavaDocTrait; -import software.amazon.polymorph.traits.LocalServiceTrait; import software.amazon.polymorph.traits.ReferenceTrait; import software.amazon.polymorph.utils.ModelUtils; import software.amazon.smithy.build.PluginContext; import software.amazon.smithy.build.SmithyBuildPlugin; -import software.amazon.smithy.codegen.core.TopologicalIndex; import software.amazon.smithy.codegen.core.directed.CodegenDirector; import software.amazon.smithy.model.Model; -import software.amazon.smithy.model.neighbor.Walker; -import software.amazon.smithy.model.shapes.*; +import software.amazon.smithy.model.shapes.AbstractShapeBuilder; +import software.amazon.smithy.model.shapes.EnumShape; +import software.amazon.smithy.model.shapes.ServiceShape; +import software.amazon.smithy.model.shapes.ShapeId; import software.amazon.smithy.model.traits.DocumentationTrait; import software.amazon.smithy.model.traits.EnumTrait; import software.amazon.smithy.model.transform.ModelTransformer; diff --git a/codegen/smithy-dafny-codegen/src/main/java/software/amazon/polymorph/smithypython/localservice/extensions/DafnyPythonLocalServiceStructureGenerator.java b/codegen/smithy-dafny-codegen/src/main/java/software/amazon/polymorph/smithypython/localservice/extensions/DafnyPythonLocalServiceStructureGenerator.java index 5aeb1b367..884862dc1 100644 --- a/codegen/smithy-dafny-codegen/src/main/java/software/amazon/polymorph/smithypython/localservice/extensions/DafnyPythonLocalServiceStructureGenerator.java +++ b/codegen/smithy-dafny-codegen/src/main/java/software/amazon/polymorph/smithypython/localservice/extensions/DafnyPythonLocalServiceStructureGenerator.java @@ -66,14 +66,23 @@ public void run() { } /** - * Renders a normal, non-error structure. + * Renders a LocalService's Config shape in config.py. + * LocalService Config shapes are special: + * - They extend the default Smithy-Python Config + * - Their __init__ methods call super.__init__() to init Smithy-Python Config. + * Most of this is lifted directly from Smithy-Python; the changed components are + * called out with comments saying "Component below is changed from Smithy-Python." */ protected void renderLocalServiceConfigShape() { writer.addStdlibImport("typing", "Dict"); writer.addStdlibImport("typing", "Any"); var symbol = symbolProvider.toSymbol(shape); + // Component below is changed from Smithy-Python. + // Write special class that extends parent class. writer.openBlock("class $L(Config):", "", symbol.getName(), () -> { writeProperties(false); + // Component below is changed from Smithy-Python. + // Write special __init__ that initializes parent class. writeLocalServiceInit(); writeAsDict(false); writeFromDict(false); @@ -83,9 +92,12 @@ protected void renderLocalServiceConfigShape() { writer.write(""); } - + /** + * Writes an __init__ method for a LocalService Config shape. + * Most of this is lifted directly from Smithy-Python; the changed components are + * called out with comments saying "Component below is changed from Smithy-Python." + */ protected void writeLocalServiceInit() { - writer.openBlock("def __init__(", "):", () -> { writer.write("self,"); if (!shape.members().isEmpty()) { @@ -103,6 +115,8 @@ protected void writeLocalServiceInit() { writer.indent(); writeClassDocs(false); + // Component below is changed from Smithy-Python. + // Initialize parent Config. writer.write("super().__init__()"); Stream.concat(requiredMembers.stream(), optionalMembers.stream()).forEach(member -> { From bae78c4e9be258c54e073477b4aab5a66cdb9b24 Mon Sep 17 00:00:00 2001 From: Lucas McDonald Date: Tue, 8 Oct 2024 16:15:22 -0700 Subject: [PATCH 53/76] m --- ...yPythonLocalServiceStructureGenerator.java | 321 ++++++++++-------- ...irectedDafnyPythonLocalServiceCodegen.java | 61 ++-- ...rappedLocalServiceClientCodegenPlugin.java | 7 +- 3 files changed, 222 insertions(+), 167 deletions(-) diff --git a/codegen/smithy-dafny-codegen/src/main/java/software/amazon/polymorph/smithypython/localservice/extensions/DafnyPythonLocalServiceStructureGenerator.java b/codegen/smithy-dafny-codegen/src/main/java/software/amazon/polymorph/smithypython/localservice/extensions/DafnyPythonLocalServiceStructureGenerator.java index 884862dc1..bb47328e0 100644 --- a/codegen/smithy-dafny-codegen/src/main/java/software/amazon/polymorph/smithypython/localservice/extensions/DafnyPythonLocalServiceStructureGenerator.java +++ b/codegen/smithy-dafny-codegen/src/main/java/software/amazon/polymorph/smithypython/localservice/extensions/DafnyPythonLocalServiceStructureGenerator.java @@ -6,7 +6,6 @@ import java.util.Set; import java.util.stream.Stream; - import software.amazon.polymorph.smithypython.awssdk.nameresolver.AwsSdkNameResolver; import software.amazon.polymorph.smithypython.common.nameresolver.SmithyNameResolver; import software.amazon.polymorph.smithypython.localservice.ConstraintUtils; @@ -79,16 +78,21 @@ protected void renderLocalServiceConfigShape() { var symbol = symbolProvider.toSymbol(shape); // Component below is changed from Smithy-Python. // Write special class that extends parent class. - writer.openBlock("class $L(Config):", "", symbol.getName(), () -> { - writeProperties(false); - // Component below is changed from Smithy-Python. - // Write special __init__ that initializes parent class. - writeLocalServiceInit(); - writeAsDict(false); - writeFromDict(false); - writeRepr(false); - writeEq(false); - }); + writer.openBlock( + "class $L(Config):", + "", + symbol.getName(), + () -> { + writeProperties(false); + // Component below is changed from Smithy-Python. + // Write special __init__ that initializes parent class. + writeLocalServiceInit(); + writeAsDict(false); + writeFromDict(false); + writeRepr(false); + writeEq(false); + } + ); writer.write(""); } @@ -98,19 +102,23 @@ protected void renderLocalServiceConfigShape() { * called out with comments saying "Component below is changed from Smithy-Python." */ protected void writeLocalServiceInit() { - writer.openBlock("def __init__(", "):", () -> { - writer.write("self,"); - if (!shape.members().isEmpty()) { - // Adding this star to the front prevents the use of positional arguments. - writer.write("*,"); - } - for (MemberShape member : requiredMembers) { - writeInitMethodParameterForRequiredMember(false, member); - } - for (MemberShape member : optionalMembers) { - writeInitMethodParameterForOptionalMember(false, member); + writer.openBlock( + "def __init__(", + "):", + () -> { + writer.write("self,"); + if (!shape.members().isEmpty()) { + // Adding this star to the front prevents the use of positional arguments. + writer.write("*,"); + } + for (MemberShape member : requiredMembers) { + writeInitMethodParameterForRequiredMember(false, member); + } + for (MemberShape member : optionalMembers) { + writeInitMethodParameterForOptionalMember(false, member); + } } - }); + ); writer.indent(); @@ -119,14 +127,16 @@ protected void writeLocalServiceInit() { // Initialize parent Config. writer.write("super().__init__()"); - Stream.concat(requiredMembers.stream(), optionalMembers.stream()).forEach(member -> { - String memberName = symbolProvider.toMemberName(member); - if (isOptionalDefault(member)) { - writeInitMethodAssignerForOptionalMember(member, memberName); - } else { - writeInitMethodAssignerForRequiredMember(member, memberName); - } - }); + Stream + .concat(requiredMembers.stream(), optionalMembers.stream()) + .forEach(member -> { + String memberName = symbolProvider.toMemberName(member); + if (isOptionalDefault(member)) { + writeInitMethodAssignerForOptionalMember(member, memberName); + } else { + writeInitMethodAssignerForRequiredMember(member, memberName); + } + }); writer.dedent(); writer.write(""); } @@ -280,8 +290,12 @@ protected void writePropertyForMember( // Reference shapes require forward reference to avoid circular import, // but references to AWS SDKs don't - if (target.hasTrait(ReferenceTrait.class) - && !AwsSdkNameResolver.isAwsSdkShape(target.expectTrait(ReferenceTrait.class).getReferentId())) { + if ( + target.hasTrait(ReferenceTrait.class) && + !AwsSdkNameResolver.isAwsSdkShape( + target.expectTrait(ReferenceTrait.class).getReferentId() + ) + ) { Shape referentShape = model.expectShape( target.expectTrait(ReferenceTrait.class).getReferentId() ); @@ -377,8 +391,12 @@ protected void writeInitMethodParameterForRequiredMember( // Reference shapes require forward reference to avoid circular import, // but references to AWS SDKs don't - if (target.hasTrait(ReferenceTrait.class) - && !AwsSdkNameResolver.isAwsSdkShape(target.expectTrait(ReferenceTrait.class).getReferentId())) { + if ( + target.hasTrait(ReferenceTrait.class) && + !AwsSdkNameResolver.isAwsSdkShape( + target.expectTrait(ReferenceTrait.class).getReferentId() + ) + ) { Shape referentShape = model.expectShape( target.expectTrait(ReferenceTrait.class).getReferentId() ); @@ -416,8 +434,12 @@ protected void writeInitMethodParameterForOptionalMember( // Reference shapes require forward reference to avoid circular import, // but references to AWS SDKs don't - if (target.hasTrait(ReferenceTrait.class) - && !AwsSdkNameResolver.isAwsSdkShape(target.expectTrait(ReferenceTrait.class).getReferentId())) { + if ( + target.hasTrait(ReferenceTrait.class) && + !AwsSdkNameResolver.isAwsSdkShape( + target.expectTrait(ReferenceTrait.class).getReferentId() + ) + ) { Shape referentShape = model.expectShape( target.expectTrait(ReferenceTrait.class).getReferentId() ); @@ -452,110 +474,141 @@ protected void writeFromDict(boolean isError) { writer.write("@staticmethod"); var shapeName = symbolProvider.toSymbol(shape).getName(); writer.openBlock( - "def from_dict(d: Dict[str, Any]) -> $S:", - "", - shapeName, - () -> { - writer.writeDocs( - () -> { - writer.write("Creates a $L from a dictionary.\n", shapeName); - }); + "def from_dict(d: Dict[str, Any]) -> $S:", + "", + shapeName, + () -> { + writer.writeDocs(() -> { + writer.write("Creates a $L from a dictionary.\n", shapeName); + }); + + if (shape.members().isEmpty() && !isError) { + writer.write("return $L()", shapeName); + return; + } - if (shape.members().isEmpty() && !isError) { - writer.write("return $L()", shapeName); - return; + // Block below is changed from Smithy-Python. + // Import any modules required for reference shapes to convert from_dict. + // Import within function to avoid circular imports from top-level imports + for (MemberShape memberShape : shape.members()) { + var target = model.expectShape(memberShape.getTarget()); + // Reference shapes require forward reference to avoid circular import, + // but references to AWS SDKs don't + if ( + target.hasTrait(ReferenceTrait.class) && + !AwsSdkNameResolver.isAwsSdkShape( + target.getTrait(ReferenceTrait.class).get().getReferentId() + ) + ) { + Symbol targetSymbol = symbolProvider.toSymbol(target); + writer.write( + "from $L import $L", + targetSymbol.getNamespace(), + targetSymbol.getName() + ); } + } - // Block below is changed from Smithy-Python. - // Import any modules required for reference shapes to convert from_dict. - // Import within function to avoid circular imports from top-level imports - for (MemberShape memberShape : shape.members()) { - var target = model.expectShape(memberShape.getTarget()); - // Reference shapes require forward reference to avoid circular import, - // but references to AWS SDKs don't - if (target.hasTrait(ReferenceTrait.class) - && !AwsSdkNameResolver.isAwsSdkShape(target.getTrait(ReferenceTrait.class).get().getReferentId())) { + if (requiredMembers.isEmpty() && !isError) { + writer.write("kwargs: Dict[str, Any] = {}"); + } else { + writer.openBlock( + "kwargs: Dict[str, Any] = {", + "}", + () -> { + if (isError) { + writer.write("'message': d['message'],"); + } + for (MemberShape member : requiredMembers) { + var memberName = symbolProvider.toMemberName(member); + var target = model.expectShape(member.getTarget()); Symbol targetSymbol = symbolProvider.toSymbol(target); - writer.write( - "from $L import $L", targetSymbol.getNamespace(), targetSymbol.getName()); + // Block below is changed from Smithy-Python. + // If passing a boto3 client, just pass the client. + // Also, use snakecase member name inside the dictionary. + if ( + target.hasTrait(ReferenceTrait.class) && + target.expectTrait(ReferenceTrait.class).isService() && + isAwsSdkShape( + target.expectTrait(ReferenceTrait.class).getReferentId() + ) + ) { + writer.write("$S: d[$S],", memberName, memberName); + } else if (target.isStructureShape()) { + writer.write( + "$S: $L.from_dict(d[$S]),", + memberName, + targetSymbol.getName(), + memberName + ); + } else if (targetSymbol.getProperty("fromDict").isPresent()) { + var targetFromDictSymbol = targetSymbol.expectProperty( + "fromDict", + Symbol.class + ); + writer.write( + "$S: $T(d[$S]),", + memberName, + targetFromDictSymbol, + memberName + ); + } else { + writer.write("$S: d[$S],", memberName, memberName); + } + } } - } - - if (requiredMembers.isEmpty() && !isError) { - writer.write("kwargs: Dict[str, Any] = {}"); - } else { - writer.openBlock( - "kwargs: Dict[str, Any] = {", - "}", - () -> { - if (isError) { - writer.write("'message': d['message'],"); - } - for (MemberShape member : requiredMembers) { - var memberName = symbolProvider.toMemberName(member); - var target = model.expectShape(member.getTarget()); - Symbol targetSymbol = symbolProvider.toSymbol(target); - // Block below is changed from Smithy-Python. - // If passing a boto3 client, just pass the client. - // Also, use snakecase member name inside the dictionary. - if (target.hasTrait(ReferenceTrait.class) - && target.expectTrait(ReferenceTrait.class).isService() - && isAwsSdkShape( - target.expectTrait(ReferenceTrait.class).getReferentId())) { - writer.write("$S: d[$S],", memberName, memberName); - } else if (target.isStructureShape()) { - writer.write( - "$S: $L.from_dict(d[$S]),", - memberName, - targetSymbol.getName(), - memberName); - } else if (targetSymbol.getProperty("fromDict").isPresent()) { - var targetFromDictSymbol = - targetSymbol.expectProperty("fromDict", Symbol.class); - writer.write("$S: $T(d[$S]),", memberName, targetFromDictSymbol, memberName); - } else { - writer.write("$S: d[$S],", memberName, memberName); - } - } - }); - } - writer.write(""); + ); + } + writer.write(""); - for (MemberShape member : optionalMembers) { - var memberName = symbolProvider.toMemberName(member); - var target = model.expectShape(member.getTarget()); - writer.openBlock( - "if $S in d:", - "", - memberName, - () -> { - var targetSymbol = symbolProvider.toSymbol(target); - // Block below is changed from Smithy-Python. - // If passing a boto3 client, just pass the client. - // Also, use snakecase member name inside the dictionary. - if (target.hasTrait(ReferenceTrait.class) - && target.expectTrait(ReferenceTrait.class).isService() - && isAwsSdkShape(target.expectTrait(ReferenceTrait.class).getReferentId())) { - writer.write("kwargs[$S] = d[$S]", memberName, memberName); - } else if (target.isStructureShape()) { - writer.write( - "kwargs[$S] = $L.from_dict(d[$S])", - memberName, - targetSymbol.getName(), - memberName); - } else if (targetSymbol.getProperty("fromDict").isPresent()) { - var targetFromDictSymbol = - targetSymbol.expectProperty("fromDict", Symbol.class); - writer.write( - "kwargs[$S] = $T(d[$S]),", memberName, targetFromDictSymbol, memberName); - } else { - writer.write("kwargs[$S] = d[$S]", memberName, memberName); - } - }); - } + for (MemberShape member : optionalMembers) { + var memberName = symbolProvider.toMemberName(member); + var target = model.expectShape(member.getTarget()); + writer.openBlock( + "if $S in d:", + "", + memberName, + () -> { + var targetSymbol = symbolProvider.toSymbol(target); + // Block below is changed from Smithy-Python. + // If passing a boto3 client, just pass the client. + // Also, use snakecase member name inside the dictionary. + if ( + target.hasTrait(ReferenceTrait.class) && + target.expectTrait(ReferenceTrait.class).isService() && + isAwsSdkShape( + target.expectTrait(ReferenceTrait.class).getReferentId() + ) + ) { + writer.write("kwargs[$S] = d[$S]", memberName, memberName); + } else if (target.isStructureShape()) { + writer.write( + "kwargs[$S] = $L.from_dict(d[$S])", + memberName, + targetSymbol.getName(), + memberName + ); + } else if (targetSymbol.getProperty("fromDict").isPresent()) { + var targetFromDictSymbol = targetSymbol.expectProperty( + "fromDict", + Symbol.class + ); + writer.write( + "kwargs[$S] = $T(d[$S]),", + memberName, + targetFromDictSymbol, + memberName + ); + } else { + writer.write("kwargs[$S] = d[$S]", memberName, memberName); + } + } + ); + } - writer.write("return $L(**kwargs)", shapeName); - }); + writer.write("return $L(**kwargs)", shapeName); + } + ); writer.write(""); } diff --git a/codegen/smithy-dafny-codegen/src/main/java/software/amazon/polymorph/smithypython/localservice/extensions/DirectedDafnyPythonLocalServiceCodegen.java b/codegen/smithy-dafny-codegen/src/main/java/software/amazon/polymorph/smithypython/localservice/extensions/DirectedDafnyPythonLocalServiceCodegen.java index 321976e19..b152675de 100644 --- a/codegen/smithy-dafny-codegen/src/main/java/software/amazon/polymorph/smithypython/localservice/extensions/DirectedDafnyPythonLocalServiceCodegen.java +++ b/codegen/smithy-dafny-codegen/src/main/java/software/amazon/polymorph/smithypython/localservice/extensions/DirectedDafnyPythonLocalServiceCodegen.java @@ -7,19 +7,14 @@ import static software.amazon.polymorph.utils.ModelUtils.getTopologicallyOrderedOrphanedShapesForService; import java.nio.file.Path; -import java.util.*; import java.util.logging.Logger; -import java.util.stream.Collectors; - import software.amazon.polymorph.smithypython.common.nameresolver.SmithyNameResolver; import software.amazon.polymorph.smithypython.localservice.DafnyLocalServiceCodegenConstants; import software.amazon.polymorph.smithypython.localservice.customize.ReferencesFileWriter; import software.amazon.smithy.build.FileManifest; import software.amazon.smithy.codegen.core.*; import software.amazon.smithy.codegen.core.directed.*; -import software.amazon.smithy.model.neighbor.Walker; import software.amazon.smithy.model.shapes.*; -import software.amazon.smithy.model.traits.EnumTrait; import software.amazon.smithy.model.traits.ErrorTrait; import software.amazon.smithy.python.codegen.*; @@ -213,10 +208,7 @@ protected void writeResourceShape( ResourceShape shape, GenerationContext context ) { - if (ReferencesFileWriter.shouldGenerateResourceForShape( - shape, - context - )) { + if (ReferencesFileWriter.shouldGenerateResourceForShape(shape, context)) { String moduleName = SmithyNameResolver.getServiceSmithygeneratedDirectoryNameForNamespace( context.settings().getService().getNamespace() @@ -297,7 +289,7 @@ protected void writeStructureShapeWithErrorTrait( GenerationContext context ) { if ( - shape + shape .getId() .getNamespace() .equals(context.settings().getService().getNamespace()) @@ -334,10 +326,7 @@ public void generateEnumShape( writeEnumShape(directive.shape(), directive.context()); } - protected void writeEnumShape( - Shape shape, - GenerationContext context - ) { + protected void writeEnumShape(Shape shape, GenerationContext context) { if ( shape .getId() @@ -345,13 +334,15 @@ protected void writeEnumShape( .equals(context.settings().getService().getNamespace()) ) { EnumShape enumShape; - System.out.println("maybe enum " + shape.getId()); if (shape.isEnumShape()) { enumShape = shape.asEnumShape().get(); } else if (shape.isStringShape()) { - enumShape = EnumShape.fromStringShape(shape.asStringShape().get()).get(); + enumShape = + EnumShape.fromStringShape(shape.asStringShape().get()).get(); } else { - throw new IllegalArgumentException("Shape cannot be interpreted as EnumShape: " + shape.getId()); + throw new IllegalArgumentException( + "Shape cannot be interpreted as EnumShape: " + shape.getId() + ); } context @@ -383,10 +374,7 @@ public void generateUnion( writeUnionShape(directive.shape(), directive.context()); } - protected void writeUnionShape( - UnionShape shape, - GenerationContext context - ) { + protected void writeUnionShape(UnionShape shape, GenerationContext context) { if ( shape .getId() @@ -481,26 +469,41 @@ public void customizeAfterIntegrations( * @param directive */ protected void generateOrphanedShapesForService( - GenerateServiceDirective directive) { - + GenerateServiceDirective directive + ) { List orderedShapes = getTopologicallyOrderedOrphanedShapesForService( - directive.shape(), directive.model() + directive.shape(), + directive.model() ); for (Shape shapeToGenerate : orderedShapes) { if (shapeToGenerate.isResourceShape()) { - writeResourceShape(shapeToGenerate.asResourceShape().get(), directive.context()); + writeResourceShape( + shapeToGenerate.asResourceShape().get(), + directive.context() + ); } else if (shapeToGenerate.isStructureShape()) { - StructureShape structureShape = shapeToGenerate.asStructureShape().get(); + StructureShape structureShape = shapeToGenerate + .asStructureShape() + .get(); if (structureShape.hasTrait(ErrorTrait.class)) { - writeStructureShapeWithErrorTrait(structureShape, directive.context()); + writeStructureShapeWithErrorTrait( + structureShape, + directive.context() + ); } else { writeStructureShape(structureShape, directive.context()); } } else if (shapeToGenerate.isEnumShape()) { - writeEnumShape(shapeToGenerate.asEnumShape().get(), directive.context()); + writeEnumShape( + shapeToGenerate.asEnumShape().get(), + directive.context() + ); } else if (shapeToGenerate.isUnionShape()) { - writeUnionShape(shapeToGenerate.asUnionShape().get(), directive.context()); + writeUnionShape( + shapeToGenerate.asUnionShape().get(), + directive.context() + ); } } } diff --git a/codegen/smithy-dafny-codegen/src/main/java/software/amazon/polymorph/smithypython/wrappedlocalservice/extensions/DafnyPythonWrappedLocalServiceClientCodegenPlugin.java b/codegen/smithy-dafny-codegen/src/main/java/software/amazon/polymorph/smithypython/wrappedlocalservice/extensions/DafnyPythonWrappedLocalServiceClientCodegenPlugin.java index f4c7d178c..7cbf1a70c 100644 --- a/codegen/smithy-dafny-codegen/src/main/java/software/amazon/polymorph/smithypython/wrappedlocalservice/extensions/DafnyPythonWrappedLocalServiceClientCodegenPlugin.java +++ b/codegen/smithy-dafny-codegen/src/main/java/software/amazon/polymorph/smithypython/wrappedlocalservice/extensions/DafnyPythonWrappedLocalServiceClientCodegenPlugin.java @@ -3,6 +3,8 @@ package software.amazon.polymorph.smithypython.wrappedlocalservice.extensions; +import static software.amazon.polymorph.smithypython.localservice.extensions.DafnyPythonLocalServiceClientCodegenPlugin.transformStringEnumShapesToEnumShapes; + import java.util.Map; import software.amazon.polymorph.smithypython.common.nameresolver.SmithyNameResolver; import software.amazon.polymorph.traits.LocalServiceTrait; @@ -19,8 +21,6 @@ import software.amazon.smithy.python.codegen.integration.PythonIntegration; import software.amazon.smithy.utils.SmithyUnstableApi; -import static software.amazon.polymorph.smithypython.localservice.extensions.DafnyPythonLocalServiceClientCodegenPlugin.transformStringEnumShapesToEnumShapes; - /** * Plugin to trigger Smithy-Dafny Python code generation for a wrapped localService. * This differs from the PythonClientCodegenPlugin by not calling `runner.performDefaultCodegenTransforms()` @@ -56,8 +56,7 @@ public static Model transformModelForWrappedLocalService( Model transformedModel = model; transformedModel = addWrappedLocalServiceTrait(transformedModel, serviceShape); - transformedModel = - transformStringEnumShapesToEnumShapes(transformedModel); + transformedModel = transformStringEnumShapesToEnumShapes(transformedModel); return transformedModel; } From 8ced3e8600c1a75c79f1a13b1754e50c7cebded9 Mon Sep 17 00:00:00 2001 From: Lucas McDonald Date: Tue, 8 Oct 2024 16:17:06 -0700 Subject: [PATCH 54/76] m --- .../extensions/DirectedDafnyPythonLocalServiceCodegen.java | 2 ++ 1 file changed, 2 insertions(+) diff --git a/codegen/smithy-dafny-codegen/src/main/java/software/amazon/polymorph/smithypython/localservice/extensions/DirectedDafnyPythonLocalServiceCodegen.java b/codegen/smithy-dafny-codegen/src/main/java/software/amazon/polymorph/smithypython/localservice/extensions/DirectedDafnyPythonLocalServiceCodegen.java index b152675de..54d487694 100644 --- a/codegen/smithy-dafny-codegen/src/main/java/software/amazon/polymorph/smithypython/localservice/extensions/DirectedDafnyPythonLocalServiceCodegen.java +++ b/codegen/smithy-dafny-codegen/src/main/java/software/amazon/polymorph/smithypython/localservice/extensions/DirectedDafnyPythonLocalServiceCodegen.java @@ -504,6 +504,8 @@ protected void generateOrphanedShapesForService( shapeToGenerate.asUnionShape().get(), directive.context() ); + } else { + throw new ClassCastException("Unsupported class for orphaned shape " + shapeToGenerate); } } } From 697d509c0d554974973639affc30bc996c84030f Mon Sep 17 00:00:00 2001 From: Lucas McDonald Date: Tue, 8 Oct 2024 16:17:18 -0700 Subject: [PATCH 55/76] m --- .../extensions/DirectedDafnyPythonLocalServiceCodegen.java | 1 + 1 file changed, 1 insertion(+) diff --git a/codegen/smithy-dafny-codegen/src/main/java/software/amazon/polymorph/smithypython/localservice/extensions/DirectedDafnyPythonLocalServiceCodegen.java b/codegen/smithy-dafny-codegen/src/main/java/software/amazon/polymorph/smithypython/localservice/extensions/DirectedDafnyPythonLocalServiceCodegen.java index 54d487694..1bd19f30d 100644 --- a/codegen/smithy-dafny-codegen/src/main/java/software/amazon/polymorph/smithypython/localservice/extensions/DirectedDafnyPythonLocalServiceCodegen.java +++ b/codegen/smithy-dafny-codegen/src/main/java/software/amazon/polymorph/smithypython/localservice/extensions/DirectedDafnyPythonLocalServiceCodegen.java @@ -505,6 +505,7 @@ protected void generateOrphanedShapesForService( directive.context() ); } else { + // Add more as needed... throw new ClassCastException("Unsupported class for orphaned shape " + shapeToGenerate); } } From f81785d9d90ae4e178fb3c9b5f4865dade2746ac Mon Sep 17 00:00:00 2001 From: Lucas McDonald Date: Tue, 8 Oct 2024 16:21:11 -0700 Subject: [PATCH 56/76] m --- .../extensions/DirectedDafnyPythonLocalServiceCodegen.java | 4 +++- .../DafnyPythonWrappedLocalServiceClientCodegenPlugin.java | 2 +- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/codegen/smithy-dafny-codegen/src/main/java/software/amazon/polymorph/smithypython/localservice/extensions/DirectedDafnyPythonLocalServiceCodegen.java b/codegen/smithy-dafny-codegen/src/main/java/software/amazon/polymorph/smithypython/localservice/extensions/DirectedDafnyPythonLocalServiceCodegen.java index 1bd19f30d..c081e7666 100644 --- a/codegen/smithy-dafny-codegen/src/main/java/software/amazon/polymorph/smithypython/localservice/extensions/DirectedDafnyPythonLocalServiceCodegen.java +++ b/codegen/smithy-dafny-codegen/src/main/java/software/amazon/polymorph/smithypython/localservice/extensions/DirectedDafnyPythonLocalServiceCodegen.java @@ -506,7 +506,9 @@ protected void generateOrphanedShapesForService( ); } else { // Add more as needed... - throw new ClassCastException("Unsupported class for orphaned shape " + shapeToGenerate); + throw new ClassCastException( + "Unsupported class for orphaned shape " + shapeToGenerate + ); } } } diff --git a/codegen/smithy-dafny-codegen/src/main/java/software/amazon/polymorph/smithypython/wrappedlocalservice/extensions/DafnyPythonWrappedLocalServiceClientCodegenPlugin.java b/codegen/smithy-dafny-codegen/src/main/java/software/amazon/polymorph/smithypython/wrappedlocalservice/extensions/DafnyPythonWrappedLocalServiceClientCodegenPlugin.java index 7cbf1a70c..8c1d713c0 100644 --- a/codegen/smithy-dafny-codegen/src/main/java/software/amazon/polymorph/smithypython/wrappedlocalservice/extensions/DafnyPythonWrappedLocalServiceClientCodegenPlugin.java +++ b/codegen/smithy-dafny-codegen/src/main/java/software/amazon/polymorph/smithypython/wrappedlocalservice/extensions/DafnyPythonWrappedLocalServiceClientCodegenPlugin.java @@ -44,7 +44,7 @@ public DafnyPythonWrappedLocalServiceClientCodegenPlugin( } /** - * Perform all transformations on the model before running localService codegen. + * Perform all transformations on the model before running wrapped localService codegen. * @param model * @param serviceShape * @return From d52c026a85b12eb7765f7346c7f074b385a5eb7e Mon Sep 17 00:00:00 2001 From: Lucas McDonald Date: Tue, 8 Oct 2024 16:21:47 -0700 Subject: [PATCH 57/76] m --- .../extensions/DirectedDafnyPythonLocalServiceCodegen.java | 1 + 1 file changed, 1 insertion(+) diff --git a/codegen/smithy-dafny-codegen/src/main/java/software/amazon/polymorph/smithypython/localservice/extensions/DirectedDafnyPythonLocalServiceCodegen.java b/codegen/smithy-dafny-codegen/src/main/java/software/amazon/polymorph/smithypython/localservice/extensions/DirectedDafnyPythonLocalServiceCodegen.java index c081e7666..8e759e8d6 100644 --- a/codegen/smithy-dafny-codegen/src/main/java/software/amazon/polymorph/smithypython/localservice/extensions/DirectedDafnyPythonLocalServiceCodegen.java +++ b/codegen/smithy-dafny-codegen/src/main/java/software/amazon/polymorph/smithypython/localservice/extensions/DirectedDafnyPythonLocalServiceCodegen.java @@ -7,6 +7,7 @@ import static software.amazon.polymorph.utils.ModelUtils.getTopologicallyOrderedOrphanedShapesForService; import java.nio.file.Path; +import java.util.List; import java.util.logging.Logger; import software.amazon.polymorph.smithypython.common.nameresolver.SmithyNameResolver; import software.amazon.polymorph.smithypython.localservice.DafnyLocalServiceCodegenConstants; From adb8ea8a0abac12958e76ac5088783c0d0cd9f70 Mon Sep 17 00:00:00 2001 From: Lucas McDonald Date: Tue, 8 Oct 2024 16:23:06 -0700 Subject: [PATCH 58/76] m --- .../java/software/amazon/polymorph/utils/ModelUtils.java | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/codegen/smithy-dafny-codegen/src/main/java/software/amazon/polymorph/utils/ModelUtils.java b/codegen/smithy-dafny-codegen/src/main/java/software/amazon/polymorph/utils/ModelUtils.java index 5b5995e65..feff25405 100644 --- a/codegen/smithy-dafny-codegen/src/main/java/software/amazon/polymorph/utils/ModelUtils.java +++ b/codegen/smithy-dafny-codegen/src/main/java/software/amazon/polymorph/utils/ModelUtils.java @@ -735,12 +735,14 @@ public static List getTopologicallyOrderedOrphanedShapesForService( TopologicalIndex topologicalIndex = TopologicalIndex.of(model); for (Shape shape : topologicalIndex.getOrderedShapes()) { - if (orphanedShapes.contains(shape)) { + if (orphanedShapes.contains(shape) + && shape.getId().getNamespace().equals(serviceShape.getId().getNamespace())) { orderedShapes.add(shape); } } for (Shape shape : topologicalIndex.getRecursiveShapes()) { - if (orphanedShapes.contains(shape)) { + if (orphanedShapes.contains(shape) + && shape.getId().getNamespace().equals(serviceShape.getId().getNamespace())) { orderedShapes.add(shape); } } From 2e68fdc97848104ab3381a416e1eb7cbf03b335e Mon Sep 17 00:00:00 2001 From: Lucas McDonald Date: Tue, 8 Oct 2024 16:24:08 -0700 Subject: [PATCH 59/76] m --- .../java/software/amazon/polymorph/utils/ModelUtils.java | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/codegen/smithy-dafny-codegen/src/main/java/software/amazon/polymorph/utils/ModelUtils.java b/codegen/smithy-dafny-codegen/src/main/java/software/amazon/polymorph/utils/ModelUtils.java index feff25405..74068e168 100644 --- a/codegen/smithy-dafny-codegen/src/main/java/software/amazon/polymorph/utils/ModelUtils.java +++ b/codegen/smithy-dafny-codegen/src/main/java/software/amazon/polymorph/utils/ModelUtils.java @@ -736,13 +736,15 @@ public static List getTopologicallyOrderedOrphanedShapesForService( for (Shape shape : topologicalIndex.getOrderedShapes()) { if (orphanedShapes.contains(shape) - && shape.getId().getNamespace().equals(serviceShape.getId().getNamespace())) { + && shape.getId().getNamespace().equals(serviceShape.getId().getNamespace()) + && !shape.isMemberShape()) { orderedShapes.add(shape); } } for (Shape shape : topologicalIndex.getRecursiveShapes()) { if (orphanedShapes.contains(shape) - && shape.getId().getNamespace().equals(serviceShape.getId().getNamespace())) { + && shape.getId().getNamespace().equals(serviceShape.getId().getNamespace()) + && !shape.isMemberShape()) { orderedShapes.add(shape); } } From 458a5b9d76cf4e5586deb5f3153a422528adeb83 Mon Sep 17 00:00:00 2001 From: Lucas McDonald Date: Tue, 8 Oct 2024 16:44:24 -0700 Subject: [PATCH 60/76] m --- .../extensions/DirectedDafnyPythonLocalServiceCodegen.java | 2 ++ .../main/java/software/amazon/polymorph/utils/ModelUtils.java | 3 +++ 2 files changed, 5 insertions(+) diff --git a/codegen/smithy-dafny-codegen/src/main/java/software/amazon/polymorph/smithypython/localservice/extensions/DirectedDafnyPythonLocalServiceCodegen.java b/codegen/smithy-dafny-codegen/src/main/java/software/amazon/polymorph/smithypython/localservice/extensions/DirectedDafnyPythonLocalServiceCodegen.java index 8e759e8d6..e067a865e 100644 --- a/codegen/smithy-dafny-codegen/src/main/java/software/amazon/polymorph/smithypython/localservice/extensions/DirectedDafnyPythonLocalServiceCodegen.java +++ b/codegen/smithy-dafny-codegen/src/main/java/software/amazon/polymorph/smithypython/localservice/extensions/DirectedDafnyPythonLocalServiceCodegen.java @@ -505,6 +505,8 @@ protected void generateOrphanedShapesForService( shapeToGenerate.asUnionShape().get(), directive.context() ); + } else if (shapeToGenerate.isStringShape()) { + // Orphaned strings are apparently not generated for .NET/Java } else { // Add more as needed... throw new ClassCastException( diff --git a/codegen/smithy-dafny-codegen/src/main/java/software/amazon/polymorph/utils/ModelUtils.java b/codegen/smithy-dafny-codegen/src/main/java/software/amazon/polymorph/utils/ModelUtils.java index 74068e168..069bc9705 100644 --- a/codegen/smithy-dafny-codegen/src/main/java/software/amazon/polymorph/utils/ModelUtils.java +++ b/codegen/smithy-dafny-codegen/src/main/java/software/amazon/polymorph/utils/ModelUtils.java @@ -734,6 +734,9 @@ public static List getTopologicallyOrderedOrphanedShapesForService( TopologicalIndex topologicalIndex = TopologicalIndex.of(model); + // Get orphaned shapes under the following conditions: + // 1. In the same namespace as the service. (Should only generate shapes in this service.) + // 2. Not a member shape. (Member shapes don't have their own shapes generated for them.) for (Shape shape : topologicalIndex.getOrderedShapes()) { if (orphanedShapes.contains(shape) && shape.getId().getNamespace().equals(serviceShape.getId().getNamespace()) From 09c3cab40f16354680caa5fa27bbdbf16d4de718 Mon Sep 17 00:00:00 2001 From: Lucas McDonald Date: Tue, 8 Oct 2024 16:47:35 -0700 Subject: [PATCH 61/76] m --- .../amazon/polymorph/utils/ModelUtils.java | 22 ++++++++++++++----- 1 file changed, 16 insertions(+), 6 deletions(-) diff --git a/codegen/smithy-dafny-codegen/src/main/java/software/amazon/polymorph/utils/ModelUtils.java b/codegen/smithy-dafny-codegen/src/main/java/software/amazon/polymorph/utils/ModelUtils.java index 069bc9705..da226d3c6 100644 --- a/codegen/smithy-dafny-codegen/src/main/java/software/amazon/polymorph/utils/ModelUtils.java +++ b/codegen/smithy-dafny-codegen/src/main/java/software/amazon/polymorph/utils/ModelUtils.java @@ -738,16 +738,26 @@ public static List getTopologicallyOrderedOrphanedShapesForService( // 1. In the same namespace as the service. (Should only generate shapes in this service.) // 2. Not a member shape. (Member shapes don't have their own shapes generated for them.) for (Shape shape : topologicalIndex.getOrderedShapes()) { - if (orphanedShapes.contains(shape) - && shape.getId().getNamespace().equals(serviceShape.getId().getNamespace()) - && !shape.isMemberShape()) { + if ( + orphanedShapes.contains(shape) && + shape + .getId() + .getNamespace() + .equals(serviceShape.getId().getNamespace()) && + !shape.isMemberShape() + ) { orderedShapes.add(shape); } } for (Shape shape : topologicalIndex.getRecursiveShapes()) { - if (orphanedShapes.contains(shape) - && shape.getId().getNamespace().equals(serviceShape.getId().getNamespace()) - && !shape.isMemberShape()) { + if ( + orphanedShapes.contains(shape) && + shape + .getId() + .getNamespace() + .equals(serviceShape.getId().getNamespace()) && + !shape.isMemberShape() + ) { orderedShapes.add(shape); } } From d97fdd86e3d4d5fad1f31bbfdde15d94987a8572 Mon Sep 17 00:00:00 2001 From: Lucas McDonald Date: Wed, 9 Oct 2024 09:59:29 -0700 Subject: [PATCH 62/76] m --- .../python/codegen/StructureGenerator.java | 2 +- ...yPythonLocalServiceStructureGenerator.java | 27 ++++++++++++++----- 2 files changed, 22 insertions(+), 7 deletions(-) diff --git a/codegen/smithy-dafny-codegen-modules/smithy-python/codegen/smithy-python-codegen/src/main/java/software/amazon/smithy/python/codegen/StructureGenerator.java b/codegen/smithy-dafny-codegen-modules/smithy-python/codegen/smithy-python-codegen/src/main/java/software/amazon/smithy/python/codegen/StructureGenerator.java index cb70b8980..cb19ffe75 100644 --- a/codegen/smithy-dafny-codegen-modules/smithy-python/codegen/smithy-python-codegen/src/main/java/software/amazon/smithy/python/codegen/StructureGenerator.java +++ b/codegen/smithy-dafny-codegen-modules/smithy-python/codegen/smithy-python-codegen/src/main/java/software/amazon/smithy/python/codegen/StructureGenerator.java @@ -326,7 +326,7 @@ private boolean hasDocs() { return false; } - private void writeMemberDocs(MemberShape member) { + protected void writeMemberDocs(MemberShape member) { member.getMemberTrait(model, DocumentationTrait.class).ifPresent(trait -> { String memberName = symbolProvider.toMemberName(member); String docs = writer.formatDocs(String.format(":param %s: %s", memberName, trait.getValue())); diff --git a/codegen/smithy-dafny-codegen/src/main/java/software/amazon/polymorph/smithypython/localservice/extensions/DafnyPythonLocalServiceStructureGenerator.java b/codegen/smithy-dafny-codegen/src/main/java/software/amazon/polymorph/smithypython/localservice/extensions/DafnyPythonLocalServiceStructureGenerator.java index bb47328e0..d1013acf3 100644 --- a/codegen/smithy-dafny-codegen/src/main/java/software/amazon/polymorph/smithypython/localservice/extensions/DafnyPythonLocalServiceStructureGenerator.java +++ b/codegen/smithy-dafny-codegen/src/main/java/software/amazon/polymorph/smithypython/localservice/extensions/DafnyPythonLocalServiceStructureGenerator.java @@ -2,17 +2,14 @@ import static java.lang.String.format; import static software.amazon.polymorph.smithypython.awssdk.nameresolver.AwsSdkNameResolver.isAwsSdkShape; -import static software.amazon.smithy.utils.StringUtils.capitalize; import java.util.Set; import java.util.stream.Stream; import software.amazon.polymorph.smithypython.awssdk.nameresolver.AwsSdkNameResolver; import software.amazon.polymorph.smithypython.common.nameresolver.SmithyNameResolver; import software.amazon.polymorph.smithypython.localservice.ConstraintUtils; -import software.amazon.polymorph.traits.LocalServiceTrait; import software.amazon.polymorph.traits.PositionalTrait; import software.amazon.polymorph.traits.ReferenceTrait; -import software.amazon.polymorph.utils.ConstrainTraitUtils; import software.amazon.smithy.codegen.core.Symbol; import software.amazon.smithy.codegen.core.SymbolProvider; import software.amazon.smithy.model.Model; @@ -86,7 +83,7 @@ protected void renderLocalServiceConfigShape() { writeProperties(false); // Component below is changed from Smithy-Python. // Write special __init__ that initializes parent class. - writeLocalServiceInit(); + writeLocalServiceConfigShapeInit(); writeAsDict(false); writeFromDict(false); writeRepr(false); @@ -101,7 +98,7 @@ protected void renderLocalServiceConfigShape() { * Most of this is lifted directly from Smithy-Python; the changed components are * called out with comments saying "Component below is changed from Smithy-Python." */ - protected void writeLocalServiceInit() { + protected void writeLocalServiceConfigShapeInit() { writer.openBlock( "def __init__(", "):", @@ -122,7 +119,25 @@ protected void writeLocalServiceInit() { writer.indent(); - writeClassDocs(false); + // This is Smithy-Python's writeClassDocs modified for LocalService Config shapes. + this.writer.writeDocs(() -> { + if (shape.hasTrait(DocumentationTrait.class)) { + this.shape.getTrait(DocumentationTrait.class).ifPresent((trait) -> { + this.writer.write(this.writer.formatDocs(trait.getValue()), new Object[0]); + }); + } else { + // Component below is changed from Smithy-Python. + // Write default docstring for LocalService Config shape constructor + this.writer.write("Constructor for $L", symbolProvider.toSymbol(shape)); + } + + if (!this.shape.members().isEmpty()) { + this.writer.write("", new Object[0]); + this.requiredMembers.forEach(this::writeMemberDocs); + this.optionalMembers.forEach(this::writeMemberDocs); + } + + }); // Component below is changed from Smithy-Python. // Initialize parent Config. writer.write("super().__init__()"); From c8129ea743f031c0b3fad954b57a255dc506b6f7 Mon Sep 17 00:00:00 2001 From: Lucas McDonald Date: Wed, 9 Oct 2024 10:02:44 -0700 Subject: [PATCH 63/76] m --- .../customize/ConfigFileWriter.java | 143 ------------------ 1 file changed, 143 deletions(-) diff --git a/codegen/smithy-dafny-codegen/src/main/java/software/amazon/polymorph/smithypython/localservice/customize/ConfigFileWriter.java b/codegen/smithy-dafny-codegen/src/main/java/software/amazon/polymorph/smithypython/localservice/customize/ConfigFileWriter.java index ac3f09e90..5e815b9e8 100644 --- a/codegen/smithy-dafny-codegen/src/main/java/software/amazon/polymorph/smithypython/localservice/customize/ConfigFileWriter.java +++ b/codegen/smithy-dafny-codegen/src/main/java/software/amazon/polymorph/smithypython/localservice/customize/ConfigFileWriter.java @@ -93,149 +93,6 @@ def smithy_config_to_dafny_config(smithy_config) -> $L: ); } - /** - * Generates the members of the Smithy-modelled localService Config shape's class. Called when - * writing the class. - * - * @param configShape - * @param codegenContext - * @param writer - */ - private void generateConfigClassFields( - StructureShape configShape, - GenerationContext codegenContext, - PythonWriter writer - ) { - Map memberShapeSet = configShape.getAllMembers(); - NullableIndex index = NullableIndex.of(codegenContext.model()); - for (Entry< - String, - MemberShape - > memberShapeEntry : memberShapeSet.entrySet()) { - MemberShape memberShape = memberShapeEntry.getValue(); - final Shape targetShape = codegenContext - .model() - .expectShape(memberShape.getTarget()); - Symbol targetShapeSymbol = codegenContext - .symbolProvider() - .toSymbol(targetShape); - if (index.isMemberNullable(memberShape)) { - writer.addStdlibImport("typing", "Optional"); - writer.write( - "$L: Optional[$T]", - CaseUtils.toSnakeCase(memberShape.getMemberName()), - targetShapeSymbol - ); - } else { - writer.write( - "$L: $T", - CaseUtils.toSnakeCase(memberShape.getMemberName()), - targetShapeSymbol - ); - } - } - } - - /** - * Generates constructor parameters for the localService's Config class. Called when writing - * parameters for the Config class' constructor (__init__ method). - * - * @param configShape - * @param codegenContext - * @param writer - */ - private void generateConfigConstructorParameters( - StructureShape configShape, - GenerationContext codegenContext, - PythonWriter writer - ) { - Map memberShapeSet = configShape.getAllMembers(); - NullableIndex index = NullableIndex.of(codegenContext.model()); - for (MemberShape memberShape : memberShapeSet.values()) { - final Shape targetShape = codegenContext - .model() - .expectShape(memberShape.getTarget()); - Symbol targetShapeSymbol = codegenContext - .symbolProvider() - .toSymbol(targetShape); - if (index.isMemberNullable(memberShape)) { - writer.addStdlibImport("typing", "Optional"); - writer.write( - "$L: Optional[$T] = None,", - CaseUtils.toSnakeCase(memberShape.getMemberName()), - targetShapeSymbol - ); - } else { - writer.write( - "$L: $T,", - CaseUtils.toSnakeCase(memberShape.getMemberName()), - targetShapeSymbol - ); - } - } - } - - /** - * Generates constructor documentation for the localService's Config class. Called when writing - * parameters for the Config class' constructor (__init__ method). - * - * @param configShape - * @param codegenContext - * @param writer - */ - private void generateConfigConstructorDocumentation( - StructureShape configShape, - GenerationContext codegenContext, - PythonWriter writer - ) { - Map memberShapeSet = configShape.getAllMembers(); - writer.writeDocs(() -> { - var constructorDocs = configShape - .getTrait(DocumentationTrait.class) - .map(StringTrait::getValue) - .orElse( - String.format("Constructor for %s.", configShape.getId().getName()) - ); - writer.write(constructorDocs + "\n"); - for (MemberShape memberShape : memberShapeSet.values()) { - memberShape - .getMemberTrait(codegenContext.model(), DocumentationTrait.class) - .ifPresent(trait -> { - String memberName = codegenContext - .symbolProvider() - .toMemberName(memberShape); - String memberDocs = writer.formatDocs( - String.format(":param %s: %s", memberName, trait.getValue()) - ); - writer.write(memberDocs); - }); - } - }); - } - - /** - * Generates assignments to fields for the localService's Config class. Called when writing the - * Config class' constructor. - * - * @param configShape - * @param codegenContext - * @param writer - */ - private void generateConfigConstructorFieldAssignments( - StructureShape configShape, - GenerationContext codegenContext, - PythonWriter writer - ) { - Map memberShapeSet = configShape.getAllMembers(); - for (String memberName : memberShapeSet.keySet()) { - writer.write( - "self.$L = $L", - CaseUtils.toSnakeCase(memberName), - CaseUtils.toSnakeCase(memberName) - ); - } - } - /** * Generates the body converting the Dafny Config class (from internaldafny code) to the * Smithy-modelled Config class defined in this file. From 02c7c7282dbc369b0c275824ff581faf12ff5435 Mon Sep 17 00:00:00 2001 From: Lucas McDonald Date: Wed, 9 Oct 2024 10:54:05 -0700 Subject: [PATCH 64/76] m --- ...yPythonLocalServiceStructureGenerator.java | 38 +++++++++++-------- 1 file changed, 22 insertions(+), 16 deletions(-) diff --git a/codegen/smithy-dafny-codegen/src/main/java/software/amazon/polymorph/smithypython/localservice/extensions/DafnyPythonLocalServiceStructureGenerator.java b/codegen/smithy-dafny-codegen/src/main/java/software/amazon/polymorph/smithypython/localservice/extensions/DafnyPythonLocalServiceStructureGenerator.java index d1013acf3..7b6c1730f 100644 --- a/codegen/smithy-dafny-codegen/src/main/java/software/amazon/polymorph/smithypython/localservice/extensions/DafnyPythonLocalServiceStructureGenerator.java +++ b/codegen/smithy-dafny-codegen/src/main/java/software/amazon/polymorph/smithypython/localservice/extensions/DafnyPythonLocalServiceStructureGenerator.java @@ -121,23 +121,29 @@ protected void writeLocalServiceConfigShapeInit() { // This is Smithy-Python's writeClassDocs modified for LocalService Config shapes. this.writer.writeDocs(() -> { - if (shape.hasTrait(DocumentationTrait.class)) { - this.shape.getTrait(DocumentationTrait.class).ifPresent((trait) -> { - this.writer.write(this.writer.formatDocs(trait.getValue()), new Object[0]); - }); - } else { - // Component below is changed from Smithy-Python. - // Write default docstring for LocalService Config shape constructor - this.writer.write("Constructor for $L", symbolProvider.toSymbol(shape)); - } - - if (!this.shape.members().isEmpty()) { - this.writer.write("", new Object[0]); - this.requiredMembers.forEach(this::writeMemberDocs); - this.optionalMembers.forEach(this::writeMemberDocs); - } + if (shape.hasTrait(DocumentationTrait.class)) { + this.shape.getTrait(DocumentationTrait.class) + .ifPresent(trait -> { + this.writer.write( + this.writer.formatDocs(trait.getValue()), + new Object[0] + ); + }); + } else { + // Component below is changed from Smithy-Python. + // Write default docstring for LocalService Config shape constructor + this.writer.write( + "Constructor for $L", + symbolProvider.toSymbol(shape) + ); + } - }); + if (!this.shape.members().isEmpty()) { + this.writer.write("", new Object[0]); + this.requiredMembers.forEach(this::writeMemberDocs); + this.optionalMembers.forEach(this::writeMemberDocs); + } + }); // Component below is changed from Smithy-Python. // Initialize parent Config. writer.write("super().__init__()"); From 6d4d90bb44978e7848c724572cda6027c8a12012 Mon Sep 17 00:00:00 2001 From: Lucas McDonald Date: Wed, 9 Oct 2024 10:58:04 -0700 Subject: [PATCH 65/76] m --- .../extensions/DafnyPythonLocalServiceStructureGenerator.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/codegen/smithy-dafny-codegen/src/main/java/software/amazon/polymorph/smithypython/localservice/extensions/DafnyPythonLocalServiceStructureGenerator.java b/codegen/smithy-dafny-codegen/src/main/java/software/amazon/polymorph/smithypython/localservice/extensions/DafnyPythonLocalServiceStructureGenerator.java index 7b6c1730f..a046419ab 100644 --- a/codegen/smithy-dafny-codegen/src/main/java/software/amazon/polymorph/smithypython/localservice/extensions/DafnyPythonLocalServiceStructureGenerator.java +++ b/codegen/smithy-dafny-codegen/src/main/java/software/amazon/polymorph/smithypython/localservice/extensions/DafnyPythonLocalServiceStructureGenerator.java @@ -134,7 +134,7 @@ protected void writeLocalServiceConfigShapeInit() { // Write default docstring for LocalService Config shape constructor this.writer.write( "Constructor for $L", - symbolProvider.toSymbol(shape) + symbolProvider.toSymbol(shape).getName() ); } From d62d4b2dfbdb59022e24f53b97f5e25c7a7f7439 Mon Sep 17 00:00:00 2001 From: Lucas McDonald Date: Wed, 9 Oct 2024 12:13:38 -0700 Subject: [PATCH 66/76] m --- .../smithy/python/codegen/MapGenerator.java | 2 +- ...irectedDafnyPythonLocalServiceCodegen.java | 27 +++++++++++++++++++ 2 files changed, 28 insertions(+), 1 deletion(-) diff --git a/codegen/smithy-dafny-codegen-modules/smithy-python/codegen/smithy-python-codegen/src/main/java/software/amazon/smithy/python/codegen/MapGenerator.java b/codegen/smithy-dafny-codegen-modules/smithy-python/codegen/smithy-python-codegen/src/main/java/software/amazon/smithy/python/codegen/MapGenerator.java index 652d70b11..3d1fda594 100644 --- a/codegen/smithy-dafny-codegen-modules/smithy-python/codegen/smithy-python-codegen/src/main/java/software/amazon/smithy/python/codegen/MapGenerator.java +++ b/codegen/smithy-dafny-codegen-modules/smithy-python/codegen/smithy-python-codegen/src/main/java/software/amazon/smithy/python/codegen/MapGenerator.java @@ -25,7 +25,7 @@ /** * Generates private helper methods for maps. */ -final class MapGenerator implements Runnable { +public class MapGenerator implements Runnable { private final Model model; private final SymbolProvider symbolProvider; diff --git a/codegen/smithy-dafny-codegen/src/main/java/software/amazon/polymorph/smithypython/localservice/extensions/DirectedDafnyPythonLocalServiceCodegen.java b/codegen/smithy-dafny-codegen/src/main/java/software/amazon/polymorph/smithypython/localservice/extensions/DirectedDafnyPythonLocalServiceCodegen.java index e067a865e..d7436d771 100644 --- a/codegen/smithy-dafny-codegen/src/main/java/software/amazon/polymorph/smithypython/localservice/extensions/DirectedDafnyPythonLocalServiceCodegen.java +++ b/codegen/smithy-dafny-codegen/src/main/java/software/amazon/polymorph/smithypython/localservice/extensions/DirectedDafnyPythonLocalServiceCodegen.java @@ -401,6 +401,31 @@ protected void writeUnionShape(UnionShape shape, GenerationContext context) { } } + protected void writeMapShape(MapShape shape, GenerationContext context) { + if ( + shape + .getId() + .getNamespace() + .equals(context.settings().getService().getNamespace()) + ) { + context + .writerDelegator() + .useShapeWriter( + shape, + writer -> { + MapGenerator generator = + new MapGenerator( + context.model(), + context.symbolProvider(), + writer, + shape + ); + generator.run(); + } + ); + } + } + /** * Call `DirectedPythonCodegen.customizeAfterIntegrations`, then remove * `localservice_codegen_todelete.py`. The CodegenDirector will invoke this method after shape @@ -507,6 +532,8 @@ protected void generateOrphanedShapesForService( ); } else if (shapeToGenerate.isStringShape()) { // Orphaned strings are apparently not generated for .NET/Java + } else if (shapeToGenerate.isMapShape()) { + writeMapShape } else { // Add more as needed... throw new ClassCastException( From f1944b7ecbd40b07c993009a2b7372d3eff4c67f Mon Sep 17 00:00:00 2001 From: Lucas McDonald Date: Wed, 9 Oct 2024 12:14:20 -0700 Subject: [PATCH 67/76] m --- .../software/amazon/smithy/python/codegen/MapGenerator.java | 2 +- .../extensions/DirectedDafnyPythonLocalServiceCodegen.java | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/codegen/smithy-dafny-codegen-modules/smithy-python/codegen/smithy-python-codegen/src/main/java/software/amazon/smithy/python/codegen/MapGenerator.java b/codegen/smithy-dafny-codegen-modules/smithy-python/codegen/smithy-python-codegen/src/main/java/software/amazon/smithy/python/codegen/MapGenerator.java index 3d1fda594..9e8611f23 100644 --- a/codegen/smithy-dafny-codegen-modules/smithy-python/codegen/smithy-python-codegen/src/main/java/software/amazon/smithy/python/codegen/MapGenerator.java +++ b/codegen/smithy-dafny-codegen-modules/smithy-python/codegen/smithy-python-codegen/src/main/java/software/amazon/smithy/python/codegen/MapGenerator.java @@ -32,7 +32,7 @@ public class MapGenerator implements Runnable { private final PythonWriter writer; private final MapShape shape; - MapGenerator( + public MapGenerator( Model model, SymbolProvider symbolProvider, PythonWriter writer, diff --git a/codegen/smithy-dafny-codegen/src/main/java/software/amazon/polymorph/smithypython/localservice/extensions/DirectedDafnyPythonLocalServiceCodegen.java b/codegen/smithy-dafny-codegen/src/main/java/software/amazon/polymorph/smithypython/localservice/extensions/DirectedDafnyPythonLocalServiceCodegen.java index d7436d771..05034e8de 100644 --- a/codegen/smithy-dafny-codegen/src/main/java/software/amazon/polymorph/smithypython/localservice/extensions/DirectedDafnyPythonLocalServiceCodegen.java +++ b/codegen/smithy-dafny-codegen/src/main/java/software/amazon/polymorph/smithypython/localservice/extensions/DirectedDafnyPythonLocalServiceCodegen.java @@ -533,7 +533,7 @@ protected void generateOrphanedShapesForService( } else if (shapeToGenerate.isStringShape()) { // Orphaned strings are apparently not generated for .NET/Java } else if (shapeToGenerate.isMapShape()) { - writeMapShape + writeMapShape(shapeToGenerate.asMapShape().get(), directive.context()); } else { // Add more as needed... throw new ClassCastException( From 435f6bcb604aae490090985f659a077b252b50ed Mon Sep 17 00:00:00 2001 From: Lucas McDonald Date: Wed, 9 Oct 2024 12:22:02 -0700 Subject: [PATCH 68/76] m --- .../extensions/DirectedDafnyPythonLocalServiceCodegen.java | 2 ++ 1 file changed, 2 insertions(+) diff --git a/codegen/smithy-dafny-codegen/src/main/java/software/amazon/polymorph/smithypython/localservice/extensions/DirectedDafnyPythonLocalServiceCodegen.java b/codegen/smithy-dafny-codegen/src/main/java/software/amazon/polymorph/smithypython/localservice/extensions/DirectedDafnyPythonLocalServiceCodegen.java index 05034e8de..1aab4167f 100644 --- a/codegen/smithy-dafny-codegen/src/main/java/software/amazon/polymorph/smithypython/localservice/extensions/DirectedDafnyPythonLocalServiceCodegen.java +++ b/codegen/smithy-dafny-codegen/src/main/java/software/amazon/polymorph/smithypython/localservice/extensions/DirectedDafnyPythonLocalServiceCodegen.java @@ -532,6 +532,8 @@ protected void generateOrphanedShapesForService( ); } else if (shapeToGenerate.isStringShape()) { // Orphaned strings are apparently not generated for .NET/Java + } else if (shapeToGenerate.isIntegerShape()) { + // Orphaned strings are apparently not generated for .NET/Java } else if (shapeToGenerate.isMapShape()) { writeMapShape(shapeToGenerate.asMapShape().get(), directive.context()); } else { From aaf7703fbdf250c0b1b5b91c83d604584cee8f97 Mon Sep 17 00:00:00 2001 From: Lucas McDonald Date: Wed, 9 Oct 2024 12:22:28 -0700 Subject: [PATCH 69/76] m --- .../extensions/DirectedDafnyPythonLocalServiceCodegen.java | 2 ++ 1 file changed, 2 insertions(+) diff --git a/codegen/smithy-dafny-codegen/src/main/java/software/amazon/polymorph/smithypython/localservice/extensions/DirectedDafnyPythonLocalServiceCodegen.java b/codegen/smithy-dafny-codegen/src/main/java/software/amazon/polymorph/smithypython/localservice/extensions/DirectedDafnyPythonLocalServiceCodegen.java index 1aab4167f..86b7c34c7 100644 --- a/codegen/smithy-dafny-codegen/src/main/java/software/amazon/polymorph/smithypython/localservice/extensions/DirectedDafnyPythonLocalServiceCodegen.java +++ b/codegen/smithy-dafny-codegen/src/main/java/software/amazon/polymorph/smithypython/localservice/extensions/DirectedDafnyPythonLocalServiceCodegen.java @@ -534,6 +534,8 @@ protected void generateOrphanedShapesForService( // Orphaned strings are apparently not generated for .NET/Java } else if (shapeToGenerate.isIntegerShape()) { // Orphaned strings are apparently not generated for .NET/Java + } else if (shapeToGenerate.isListShape()) { + // Orphaned strings are apparently not generated for .NET/Java } else if (shapeToGenerate.isMapShape()) { writeMapShape(shapeToGenerate.asMapShape().get(), directive.context()); } else { From aa3f39cc25e0b6f1edb5fa87dbc95e831316bf2f Mon Sep 17 00:00:00 2001 From: Lucas McDonald Date: Wed, 9 Oct 2024 12:27:09 -0700 Subject: [PATCH 70/76] m --- .../amazon/smithy/python/codegen/DirectedPythonCodegen.java | 1 + 1 file changed, 1 insertion(+) diff --git a/codegen/smithy-dafny-codegen-modules/smithy-python/codegen/smithy-python-codegen/src/main/java/software/amazon/smithy/python/codegen/DirectedPythonCodegen.java b/codegen/smithy-dafny-codegen-modules/smithy-python/codegen/smithy-python-codegen/src/main/java/software/amazon/smithy/python/codegen/DirectedPythonCodegen.java index 9d03c56e6..cfbef1882 100644 --- a/codegen/smithy-dafny-codegen-modules/smithy-python/codegen/smithy-python-codegen/src/main/java/software/amazon/smithy/python/codegen/DirectedPythonCodegen.java +++ b/codegen/smithy-dafny-codegen-modules/smithy-python/codegen/smithy-python-codegen/src/main/java/software/amazon/smithy/python/codegen/DirectedPythonCodegen.java @@ -286,6 +286,7 @@ private void generateInits(CustomizeDirective var directories = directive.context().writerDelegator().getWriters().keySet().stream() .map(Paths::get) .filter(path -> !path.getParent().equals(directive.fileManifest().getBaseDir())) + .filter(path -> !path.getParent().equals(null)) .collect(Collectors.groupingBy(Path::getParent, Collectors.toSet())); for (var entry : directories.entrySet()) { var initPath = entry.getKey().resolve("__init__.py"); From aca1d18ce9aef3802d2160ea4098f592562dd644 Mon Sep 17 00:00:00 2001 From: Lucas McDonald Date: Wed, 9 Oct 2024 12:29:50 -0700 Subject: [PATCH 71/76] m --- .../amazon/smithy/python/codegen/DirectedPythonCodegen.java | 1 - .../extensions/DirectedDafnyPythonLocalServiceCodegen.java | 2 +- 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/codegen/smithy-dafny-codegen-modules/smithy-python/codegen/smithy-python-codegen/src/main/java/software/amazon/smithy/python/codegen/DirectedPythonCodegen.java b/codegen/smithy-dafny-codegen-modules/smithy-python/codegen/smithy-python-codegen/src/main/java/software/amazon/smithy/python/codegen/DirectedPythonCodegen.java index cfbef1882..9d03c56e6 100644 --- a/codegen/smithy-dafny-codegen-modules/smithy-python/codegen/smithy-python-codegen/src/main/java/software/amazon/smithy/python/codegen/DirectedPythonCodegen.java +++ b/codegen/smithy-dafny-codegen-modules/smithy-python/codegen/smithy-python-codegen/src/main/java/software/amazon/smithy/python/codegen/DirectedPythonCodegen.java @@ -286,7 +286,6 @@ private void generateInits(CustomizeDirective var directories = directive.context().writerDelegator().getWriters().keySet().stream() .map(Paths::get) .filter(path -> !path.getParent().equals(directive.fileManifest().getBaseDir())) - .filter(path -> !path.getParent().equals(null)) .collect(Collectors.groupingBy(Path::getParent, Collectors.toSet())); for (var entry : directories.entrySet()) { var initPath = entry.getKey().resolve("__init__.py"); diff --git a/codegen/smithy-dafny-codegen/src/main/java/software/amazon/polymorph/smithypython/localservice/extensions/DirectedDafnyPythonLocalServiceCodegen.java b/codegen/smithy-dafny-codegen/src/main/java/software/amazon/polymorph/smithypython/localservice/extensions/DirectedDafnyPythonLocalServiceCodegen.java index 86b7c34c7..3fcd92bef 100644 --- a/codegen/smithy-dafny-codegen/src/main/java/software/amazon/polymorph/smithypython/localservice/extensions/DirectedDafnyPythonLocalServiceCodegen.java +++ b/codegen/smithy-dafny-codegen/src/main/java/software/amazon/polymorph/smithypython/localservice/extensions/DirectedDafnyPythonLocalServiceCodegen.java @@ -537,7 +537,7 @@ protected void generateOrphanedShapesForService( } else if (shapeToGenerate.isListShape()) { // Orphaned strings are apparently not generated for .NET/Java } else if (shapeToGenerate.isMapShape()) { - writeMapShape(shapeToGenerate.asMapShape().get(), directive.context()); +// writeMapShape(shapeToGenerate.asMapShape().get(), directive.context()); } else { // Add more as needed... throw new ClassCastException( From 8cc1633332b1a8d1a630fbd58f04ce9fc0263455 Mon Sep 17 00:00:00 2001 From: Lucas McDonald Date: Wed, 9 Oct 2024 12:35:00 -0700 Subject: [PATCH 72/76] m --- ...irectedDafnyPythonLocalServiceCodegen.java | 21 +++++++++---------- 1 file changed, 10 insertions(+), 11 deletions(-) diff --git a/codegen/smithy-dafny-codegen/src/main/java/software/amazon/polymorph/smithypython/localservice/extensions/DirectedDafnyPythonLocalServiceCodegen.java b/codegen/smithy-dafny-codegen/src/main/java/software/amazon/polymorph/smithypython/localservice/extensions/DirectedDafnyPythonLocalServiceCodegen.java index 3fcd92bef..42576a75e 100644 --- a/codegen/smithy-dafny-codegen/src/main/java/software/amazon/polymorph/smithypython/localservice/extensions/DirectedDafnyPythonLocalServiceCodegen.java +++ b/codegen/smithy-dafny-codegen/src/main/java/software/amazon/polymorph/smithypython/localservice/extensions/DirectedDafnyPythonLocalServiceCodegen.java @@ -413,13 +413,12 @@ protected void writeMapShape(MapShape shape, GenerationContext context) { .useShapeWriter( shape, writer -> { - MapGenerator generator = - new MapGenerator( - context.model(), - context.symbolProvider(), - writer, - shape - ); + MapGenerator generator = new MapGenerator( + context.model(), + context.symbolProvider(), + writer, + shape + ); generator.run(); } ); @@ -531,13 +530,13 @@ protected void generateOrphanedShapesForService( directive.context() ); } else if (shapeToGenerate.isStringShape()) { - // Orphaned strings are apparently not generated for .NET/Java + // Classes are not generated for strings } else if (shapeToGenerate.isIntegerShape()) { - // Orphaned strings are apparently not generated for .NET/Java + // Classes are not generated for ints } else if (shapeToGenerate.isListShape()) { - // Orphaned strings are apparently not generated for .NET/Java + // Classes are not generated for lists } else if (shapeToGenerate.isMapShape()) { -// writeMapShape(shapeToGenerate.asMapShape().get(), directive.context()); + // Classes are not generated for maps } else { // Add more as needed... throw new ClassCastException( From a79d9738da4fd232c3d3ef88a5842ca68bc0491a Mon Sep 17 00:00:00 2001 From: Lucas McDonald Date: Wed, 9 Oct 2024 12:36:13 -0700 Subject: [PATCH 73/76] m --- .../software/amazon/smithy/python/codegen/MapGenerator.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/codegen/smithy-dafny-codegen-modules/smithy-python/codegen/smithy-python-codegen/src/main/java/software/amazon/smithy/python/codegen/MapGenerator.java b/codegen/smithy-dafny-codegen-modules/smithy-python/codegen/smithy-python-codegen/src/main/java/software/amazon/smithy/python/codegen/MapGenerator.java index 9e8611f23..652d70b11 100644 --- a/codegen/smithy-dafny-codegen-modules/smithy-python/codegen/smithy-python-codegen/src/main/java/software/amazon/smithy/python/codegen/MapGenerator.java +++ b/codegen/smithy-dafny-codegen-modules/smithy-python/codegen/smithy-python-codegen/src/main/java/software/amazon/smithy/python/codegen/MapGenerator.java @@ -25,14 +25,14 @@ /** * Generates private helper methods for maps. */ -public class MapGenerator implements Runnable { +final class MapGenerator implements Runnable { private final Model model; private final SymbolProvider symbolProvider; private final PythonWriter writer; private final MapShape shape; - public MapGenerator( + MapGenerator( Model model, SymbolProvider symbolProvider, PythonWriter writer, From 288d6ff7882713d30769e80ea3872f081801339e Mon Sep 17 00:00:00 2001 From: Lucas McDonald Date: Wed, 9 Oct 2024 12:50:18 -0700 Subject: [PATCH 74/76] m --- ...irectedDafnyPythonLocalServiceCodegen.java | 24 ------------------- 1 file changed, 24 deletions(-) diff --git a/codegen/smithy-dafny-codegen/src/main/java/software/amazon/polymorph/smithypython/localservice/extensions/DirectedDafnyPythonLocalServiceCodegen.java b/codegen/smithy-dafny-codegen/src/main/java/software/amazon/polymorph/smithypython/localservice/extensions/DirectedDafnyPythonLocalServiceCodegen.java index 42576a75e..8b3f157f5 100644 --- a/codegen/smithy-dafny-codegen/src/main/java/software/amazon/polymorph/smithypython/localservice/extensions/DirectedDafnyPythonLocalServiceCodegen.java +++ b/codegen/smithy-dafny-codegen/src/main/java/software/amazon/polymorph/smithypython/localservice/extensions/DirectedDafnyPythonLocalServiceCodegen.java @@ -401,30 +401,6 @@ protected void writeUnionShape(UnionShape shape, GenerationContext context) { } } - protected void writeMapShape(MapShape shape, GenerationContext context) { - if ( - shape - .getId() - .getNamespace() - .equals(context.settings().getService().getNamespace()) - ) { - context - .writerDelegator() - .useShapeWriter( - shape, - writer -> { - MapGenerator generator = new MapGenerator( - context.model(), - context.symbolProvider(), - writer, - shape - ); - generator.run(); - } - ); - } - } - /** * Call `DirectedPythonCodegen.customizeAfterIntegrations`, then remove * `localservice_codegen_todelete.py`. The CodegenDirector will invoke this method after shape From d3dc8b1bfe7d258e89bd1b9ba82f561ffec40fe4 Mon Sep 17 00:00:00 2001 From: Lucas McDonald Date: Wed, 9 Oct 2024 15:45:46 -0700 Subject: [PATCH 75/76] m --- SmithyDafnyMakefile.mk | 9 +++++++++ .../software/amazon/polymorph/utils/ModelUtils.java | 10 ++-------- 2 files changed, 11 insertions(+), 8 deletions(-) diff --git a/SmithyDafnyMakefile.mk b/SmithyDafnyMakefile.mk index 18fe6614e..2eb530d1c 100644 --- a/SmithyDafnyMakefile.mk +++ b/SmithyDafnyMakefile.mk @@ -259,6 +259,9 @@ transpile_dependencies_test: ########################## Code-Gen targets +mvn_local_deploy_polymorph_dependencies: + $(MAKE) -C $(SMITHY_DAFNY_ROOT) mvn_local_deploy_polymorph_dependencies + # The OUTPUT variables are created this way # so that it is possible to run _parts_ of polymorph. # Otherwise it is difficult to run/test only a Dafny change. @@ -327,6 +330,7 @@ _polymorph_dependencies: # Generates all target runtime code for all namespaces in this project. # Not including Rust until is it more fully implemented. .PHONY: polymorph_code_gen +polymorph_code_gen: mvn_local_deploy_polymorph_dependencies polymorph_code_gen: POLYMORPH_LANGUAGE_TARGET=code_gen polymorph_code_gen: _polymorph_dependencies polymorph_code_gen: @@ -352,6 +356,7 @@ check_polymorph_diff: # Generates dafny code for all namespaces in this project .PHONY: polymorph_dafny +polymorph_dafny: mvn_local_deploy_polymorph_dependencies polymorph_dafny: POLYMORPH_LANGUAGE_TARGET=dafny polymorph_dafny: _polymorph_dependencies polymorph_dafny: @@ -370,6 +375,7 @@ _polymorph_dafny: _polymorph # Generates dotnet code for all namespaces in this project .PHONY: polymorph_dotnet +polymorph_dotnet: mvn_local_deploy_polymorph_dependencies polymorph_dotnet: POLYMORPH_LANGUAGE_TARGET=dotnet polymorph_dotnet: _polymorph_dependencies polymorph_dotnet: @@ -388,6 +394,7 @@ _polymorph_dotnet: _polymorph # Generates java code for all namespaces in this project .PHONY: polymorph_java +polymorph_java: mvn_local_deploy_polymorph_dependencies polymorph_java: POLYMORPH_LANGUAGE_TARGET=java polymorph_java: _polymorph_dependencies polymorph_java: @@ -406,6 +413,7 @@ _polymorph_java: _polymorph # Generates python code for all namespaces in this project .PHONY: polymorph_python +polymorph_python: mvn_local_deploy_polymorph_dependencies polymorph_python: POLYMORPH_LANGUAGE_TARGET=python polymorph_python: _polymorph_dependencies polymorph_python: @@ -432,6 +440,7 @@ setup_prettier: # to also patch the results of transpile_rust, # so we assume that is run first! .PHONY: polymorph_rust +polymorph_rust: mvn_local_deploy_polymorph_dependencies polymorph_rust: POLYMORPH_LANGUAGE_TARGET=rust polymorph_rust: _polymorph_dependencies polymorph_rust: diff --git a/codegen/smithy-dafny-codegen/src/main/java/software/amazon/polymorph/utils/ModelUtils.java b/codegen/smithy-dafny-codegen/src/main/java/software/amazon/polymorph/utils/ModelUtils.java index da226d3c6..29e0b3106 100644 --- a/codegen/smithy-dafny-codegen/src/main/java/software/amazon/polymorph/utils/ModelUtils.java +++ b/codegen/smithy-dafny-codegen/src/main/java/software/amazon/polymorph/utils/ModelUtils.java @@ -740,10 +740,7 @@ public static List getTopologicallyOrderedOrphanedShapesForService( for (Shape shape : topologicalIndex.getOrderedShapes()) { if ( orphanedShapes.contains(shape) && - shape - .getId() - .getNamespace() - .equals(serviceShape.getId().getNamespace()) && + ModelUtils.isInServiceNamespace(shape, serviceShape) && !shape.isMemberShape() ) { orderedShapes.add(shape); @@ -752,10 +749,7 @@ public static List getTopologicallyOrderedOrphanedShapesForService( for (Shape shape : topologicalIndex.getRecursiveShapes()) { if ( orphanedShapes.contains(shape) && - shape - .getId() - .getNamespace() - .equals(serviceShape.getId().getNamespace()) && + ModelUtils.isInServiceNamespace(shape, serviceShape) && !shape.isMemberShape() ) { orderedShapes.add(shape); From b288469dd2f4f596ed5790b5d23570aa9fd690c3 Mon Sep 17 00:00:00 2001 From: Lucas McDonald Date: Wed, 9 Oct 2024 15:53:09 -0700 Subject: [PATCH 76/76] m --- SmithyDafnyMakefile.mk | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/SmithyDafnyMakefile.mk b/SmithyDafnyMakefile.mk index 2eb530d1c..b41feed69 100644 --- a/SmithyDafnyMakefile.mk +++ b/SmithyDafnyMakefile.mk @@ -272,6 +272,7 @@ mvn_local_deploy_polymorph_dependencies: # make polymorph_code_gen CODEGEN_CLI_ROOT=/path/to/smithy-dafny/codegen/smithy-dafny-codegen-cli # StandardLibrary is filtered out from dependent-model patsubst list; # Its model is contained in $(LIBRARY_ROOT)/model, not $(LIBRARY_ROOT)/../StandardLibrary/Model. +_polymorph: mvn_local_deploy_polymorph_dependencies _polymorph: cd $(CODEGEN_CLI_ROOT); \ ./../gradlew run --args="\ @@ -297,6 +298,7 @@ _polymorph: $(POLYMORPH_OPTIONS) \ "; +_polymorph_wrapped: mvn_local_deploy_polymorph_dependencies _polymorph_wrapped: @: $(if ${CODEGEN_CLI_ROOT},,$(error You must pass the path CODEGEN_CLI_ROOT: CODEGEN_CLI_ROOT=/path/to/smithy-dafny/codegen/smithy-dafny-codegen-cli)); cd $(CODEGEN_CLI_ROOT); \ @@ -330,7 +332,6 @@ _polymorph_dependencies: # Generates all target runtime code for all namespaces in this project. # Not including Rust until is it more fully implemented. .PHONY: polymorph_code_gen -polymorph_code_gen: mvn_local_deploy_polymorph_dependencies polymorph_code_gen: POLYMORPH_LANGUAGE_TARGET=code_gen polymorph_code_gen: _polymorph_dependencies polymorph_code_gen: @@ -356,7 +357,6 @@ check_polymorph_diff: # Generates dafny code for all namespaces in this project .PHONY: polymorph_dafny -polymorph_dafny: mvn_local_deploy_polymorph_dependencies polymorph_dafny: POLYMORPH_LANGUAGE_TARGET=dafny polymorph_dafny: _polymorph_dependencies polymorph_dafny: @@ -375,7 +375,6 @@ _polymorph_dafny: _polymorph # Generates dotnet code for all namespaces in this project .PHONY: polymorph_dotnet -polymorph_dotnet: mvn_local_deploy_polymorph_dependencies polymorph_dotnet: POLYMORPH_LANGUAGE_TARGET=dotnet polymorph_dotnet: _polymorph_dependencies polymorph_dotnet: @@ -394,7 +393,6 @@ _polymorph_dotnet: _polymorph # Generates java code for all namespaces in this project .PHONY: polymorph_java -polymorph_java: mvn_local_deploy_polymorph_dependencies polymorph_java: POLYMORPH_LANGUAGE_TARGET=java polymorph_java: _polymorph_dependencies polymorph_java: @@ -413,7 +411,6 @@ _polymorph_java: _polymorph # Generates python code for all namespaces in this project .PHONY: polymorph_python -polymorph_python: mvn_local_deploy_polymorph_dependencies polymorph_python: POLYMORPH_LANGUAGE_TARGET=python polymorph_python: _polymorph_dependencies polymorph_python: @@ -440,7 +437,6 @@ setup_prettier: # to also patch the results of transpile_rust, # so we assume that is run first! .PHONY: polymorph_rust -polymorph_rust: mvn_local_deploy_polymorph_dependencies polymorph_rust: POLYMORPH_LANGUAGE_TARGET=rust polymorph_rust: _polymorph_dependencies polymorph_rust: