Skip to content

Commit 080f98d

Browse files
committed
Merge branch 'develop' into regional_endpoints_2
2 parents f7fef40 + 4579c2b commit 080f98d

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

48 files changed

+5247
-228
lines changed

.github/workflows/ci.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ jobs:
1414
strategy:
1515
fail-fast: false
1616
matrix:
17-
python-version: ["3.12"]
17+
python-version: ["3.12", "3.13"]
1818

1919
steps:
2020
- name: Checkout Repository

README.md

Lines changed: 144 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ This repository does *not* contain any generated clients, such as for S3 or othe
2828
AWS services. Rather, these are the tools that facilitate the generation of those
2929
clients and non-AWS Smithy clients.
3030

31-
### How do I use this?
31+
### How do I use this to create a client?
3232

3333
The first step is to create a Smithy package. If this is your first time working
3434
with Smithy, follow [this quickstart guide](https://smithy.io/2.0/quickstart.html)
@@ -82,9 +82,9 @@ this file, see the
8282
"sources": ["model"],
8383
"maven": {
8484
"dependencies": [
85-
"software.amazon.smithy:smithy-model:[1.34.0,2.0)",
86-
"software.amazon.smithy:smithy-aws-traits:[1.34.0,2.0)",
87-
"software.amazon.smithy.python:smithy-python-codegen:0.1.0"
85+
"software.amazon.smithy:smithy-model:[1.54.0,2.0)",
86+
"software.amazon.smithy:smithy-aws-traits:[1.54.0,2.0)",
87+
"software.amazon.smithy.python.codegen:core:0.0.1"
8888
]
8989
},
9090
"projections": {
@@ -175,6 +175,146 @@ Only for now. Once the generator has been published, the Smithy CLI will be able
175175
to run it without a separate Java installation. Similarly, once the python
176176
helper libraries have been published you won't need to install them locally.
177177

178+
### How do I generate types for shapes without a client?
179+
180+
If all you want are concrete Python classes for the shapes in your Smithy model,
181+
all you need to do is replace `python-client-codegen` with
182+
`python-type-codegen` when following the steps above. Your `smithy-build.json`
183+
would now look like:
184+
185+
```json
186+
{
187+
"version": "1.0",
188+
"sources": ["model"],
189+
"maven": {
190+
"dependencies": [
191+
"software.amazon.smithy:smithy-model:[1.54.0,2.0)",
192+
"software.amazon.smithy.python.codegen.plugins:types:0.0.1"
193+
]
194+
},
195+
"projections": {
196+
"shapes": {
197+
"plugins": {
198+
"python-type-codegen": {
199+
"service": "com.example#EchoService",
200+
"module": "echo",
201+
"moduleVersion": "0.0.1"
202+
}
203+
}
204+
}
205+
}
206+
}
207+
```
208+
209+
The module with the generated shape classes can be found in
210+
`build/smithy/client/python-type-codegen` after you run `smithy-build`.
211+
212+
Unlike when generating a client, a service shape is not required for shape
213+
generation. If a service is not provided then every shape found in the model
214+
will be generated. Any naming conflicts may be resolved by using the
215+
[`renameShapes` transform](https://smithy.io/2.0/guides/smithy-build-json.html#renameshapes)
216+
(or renaming the shapes in the model of course).
217+
218+
The set of shapes generated can also be constrained by using the
219+
[`includeShapesBySelector` transform](https://smithy.io/2.0/guides/smithy-build-json.html#includeshapesbyselector).
220+
For example, to generate only shapes within the `com.example` namespace:
221+
222+
```json
223+
{
224+
"version": "1.0",
225+
"sources": ["model"],
226+
"maven": {
227+
"dependencies": [
228+
"software.amazon.smithy:smithy-model:[1.54.0,2.0)",
229+
"software.amazon.smithy.python.codegen.plugins:types:0.0.1"
230+
]
231+
},
232+
"projections": {
233+
"shapes": {
234+
"transforms": [
235+
{
236+
"name": "includeShapesBySelector",
237+
"args": {
238+
"selector": "[id|namespace = 'com.example']"
239+
}
240+
}
241+
],
242+
"plugins": {
243+
"python-type-codegen": {
244+
"module": "echo",
245+
"moduleVersion": "0.0.1"
246+
}
247+
}
248+
}
249+
}
250+
}
251+
```
252+
253+
Input and output shapes (shapes with the `@input` or `@output` traits and
254+
operation inputs / outputs created as part of an operation definition) are not
255+
generated by default. To generate these shapes anyway, set the
256+
`generateInputsAndOutputs` property to `true`.
257+
258+
```json
259+
{
260+
"version": "1.0",
261+
"sources": ["model"],
262+
"maven": {
263+
"dependencies": [
264+
"software.amazon.smithy:smithy-model:[1.54.0,2.0)",
265+
"software.amazon.smithy.python.codegen.plugins:types:0.0.1"
266+
]
267+
},
268+
"projections": {
269+
"shapes": {
270+
"plugins": {
271+
"python-type-codegen": {
272+
"module": "echo",
273+
"moduleVersion": "0.0.1",
274+
"generateInputsAndOutputs": true
275+
}
276+
}
277+
}
278+
}
279+
}
280+
```
281+
282+
You can also generate both a client package and a shape package in one build,
283+
but they won't depend on each other. To do this, just add both plugins in the
284+
projection, or create a projection for each plugin. Below is an example showing
285+
both plugins in one projection:
286+
287+
```json
288+
{
289+
"version": "1.0",
290+
"sources": ["model"],
291+
"maven": {
292+
"dependencies": [
293+
"software.amazon.smithy:smithy-model:[1.54.0,2.0)",
294+
"software.amazon.smithy:smithy-aws-traits:[1.54.0,2.0)",
295+
"software.amazon.smithy.python.codegen:core:0.0.1",
296+
"software.amazon.smithy.python.codegen.plugins:types:0.0.1"
297+
]
298+
},
299+
"projections": {
300+
"client": {
301+
"plugins": {
302+
"python-client-codegen": {
303+
"service": "com.example#EchoService",
304+
"module": "echo",
305+
"moduleVersion": "0.0.1"
306+
},
307+
"python-type-codegen": {
308+
"service": "com.example#EchoService",
309+
"module": "echo",
310+
"moduleVersion": "0.0.1"
311+
}
312+
}
313+
}
314+
}
315+
}
316+
```
317+
178318
### Core Modules and Interfaces
179319

180320
* `smithy-core` provides transport-agnostic core modules and interfaces

codegen/build.gradle.kts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,5 +15,5 @@
1515

1616
allprojects {
1717
group = "software.amazon.smithy.python"
18-
version = "0.1.0"
18+
version = "0.0.1"
1919
}
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
import org.gradle.api.Project
2+
3+
plugins {
4+
id("smithy-python.module-conventions")
5+
id("smithy-python.integ-test-conventions")
6+
}
7+
8+
// Workaround per: https://github.com/gradle/gradle/issues/15383
9+
val Project.libs get() = the<org.gradle.accessors.dm.LibrariesForLibs>()
10+
11+
group = "software.amazon.smithy.python.codegen.plugins"
12+
13+
dependencies {
14+
implementation(libs.smithy.codegen)
15+
implementation(project(":core"))
16+
17+
// Avoid circular dependency in codegen core
18+
if (project.name != "core") {
19+
api(project(":core"))
20+
}
21+
}
22+
23+
val generatedSrcDir = layout.buildDirectory.dir("generated-src").get()
24+
25+
// Add generated sources to integration test sources
26+
sourceSets {
27+
named("it") {
28+
java {
29+
srcDir(generatedSrcDir)
30+
}
31+
}
32+
}
33+
34+
// Ensure integ tests are executed as part of test suite
35+
tasks["test"].finalizedBy("integ")

0 commit comments

Comments
 (0)