Skip to content

Commit

Permalink
Python: Link stubgen.{py,sh} to resources/ and read them using `g…
Browse files Browse the repository at this point in the history
…etResource()` (#2692)

## Motivation and Context
Currently, we're relying on `runtimeConfig.runtimeCratesPath()` to read
`stubgen.{py,sh}` files, but that function only returns a path if we're
using `relativePath` for our runtime crates:
```
"runtimeConfig": {
      "relativePath": "../rust-runtime"
},
```
otherwise it returns `null` and in that case our code generator fails
with:
```
Projection pokemon-service failed: java.io.FileNotFoundException: null/aws-smithy-http-server-python/stubgen.py (No such file or directory)
java.io.FileNotFoundException: null/aws-smithy-http-server-python/stubgen.py (No such file or directory)
```

With this PR we're linking `stubgen.{py,sh}` to `resources/` folder and
reading them using `getResource()` function.

## Checklist
<!--- If a checkbox below is not applicable, then please DELETE it
rather than leaving it unchecked -->
- [ ] I have updated `CHANGELOG.next.toml` if I made changes to the
smithy-rs codegen or runtime crates
- [ ] I have updated `CHANGELOG.next.toml` if I made changes to the AWS
SDK, generated SDK code, or SDK runtime crates

----

_By submitting this pull request, I confirm that you can use, modify,
copy, and redistribute this contribution, under the terms of your
choice._
  • Loading branch information
unexge authored May 12, 2023
1 parent c2da4cf commit 85433ce
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ import software.amazon.smithy.rust.codegen.server.python.smithy.generators.Pytho
import software.amazon.smithy.rust.codegen.server.smithy.ServerCodegenContext
import software.amazon.smithy.rust.codegen.server.smithy.customizations.AddInternalServerErrorToAllOperationsDecorator
import software.amazon.smithy.rust.codegen.server.smithy.customize.ServerCodegenDecorator
import java.io.File

/**
* Configure the [lib] section of `Cargo.toml`.
Expand Down Expand Up @@ -206,14 +205,11 @@ class AddStubgenScriptDecorator : ServerCodegenDecorator {
override val order: Byte = 0

override fun extras(codegenContext: ServerCodegenContext, rustCrate: RustCrate) {
val runtimeCratesPath = codegenContext.runtimeConfig.runtimeCratesPath()
val stubgenPythonLocation = "$runtimeCratesPath/aws-smithy-http-server-python/stubgen.py"
val stubgenPythonContent = File(stubgenPythonLocation).readText(Charsets.UTF_8)
val stubgenPythonContent = this::class.java.getResource("/stubgen.py").readText()
rustCrate.withFile("stubgen.py") {
writeWithNoFormatting("$stubgenPythonContent")
}
val stubgenShellLocation = "$runtimeCratesPath/aws-smithy-http-server-python/stubgen.sh"
val stubgenShellContent = File(stubgenShellLocation).readText(Charsets.UTF_8)
val stubgenShellContent = this::class.java.getResource("/stubgen.sh").readText()
rustCrate.withFile("stubgen.sh") {
writeWithNoFormatting("$stubgenShellContent")
}
Expand Down
1 change: 1 addition & 0 deletions codegen-server/python/src/main/resources/stubgen.py
1 change: 1 addition & 0 deletions codegen-server/python/src/main/resources/stubgen.sh

0 comments on commit 85433ce

Please sign in to comment.