-
Notifications
You must be signed in to change notification settings - Fork 201
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Server] Implement Gradle subprojects and scaffolding for the Python server. #1366
Merged
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
be8e740
Add Python subproject scaffolding
crisidev d3025b0
Add codegen-server-python CI actions
crisidev 68b3423
Add CI script for python subproject
crisidev 9d0ee50
Remove empty line from ci.mk
crisidev ce7360f
Cleanup dependencies from Grandle build scripts of server-codegen
crisidev 5a20d5b
Configure codegen-server-test-python smithy-cli output directory. Fix…
crisidev fa5b446
Add decriptions to codegen-server-test projects
crisidev d77d479
Merge branch 'main' into oxipy
crisidev 4a249c6
Merge branch 'main' into oxipy
crisidev aad9ed4
Fix python RustCodegenServerPlugin license header
crisidev 26c6d0b
Fix multiple license headers
crisidev File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,107 @@ | ||
/* | ||
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
description = "Generates Rust/Python code from Smithy models and runs the protocol tests" | ||
extra["displayName"] = "Smithy :: Rust :: Codegen :: Server :: Python :: Test" | ||
extra["moduleName"] = "software.amazon.smithy.rust.kotlin.codegen.server.python.test" | ||
|
||
tasks["jar"].enabled = false | ||
|
||
plugins { id("software.amazon.smithy") } | ||
|
||
val smithyVersion: String by project | ||
val defaultRustFlags: String by project | ||
val defaultRustDocFlags: String by project | ||
val properties = PropertyRetriever(rootProject, project) | ||
|
||
val pluginName = "rust-server-codegen" | ||
val workingDirUnderBuildDir = "smithyprojections/codegen-server-test-python/" | ||
|
||
configure<software.amazon.smithy.gradle.SmithyExtension> { | ||
outputDirectory = file("$buildDir/$workingDirUnderBuildDir") | ||
} | ||
|
||
buildscript { | ||
val smithyVersion: String by project | ||
dependencies { | ||
classpath("software.amazon.smithy:smithy-cli:$smithyVersion") | ||
} | ||
} | ||
|
||
dependencies { | ||
implementation(project(":codegen-server:python")) | ||
implementation("software.amazon.smithy:smithy-aws-protocol-tests:$smithyVersion") | ||
implementation("software.amazon.smithy:smithy-protocol-test-traits:$smithyVersion") | ||
implementation("software.amazon.smithy:smithy-aws-traits:$smithyVersion") | ||
} | ||
|
||
val allCodegenTests = listOf( | ||
CodegenTest("com.amazonaws.simple#SimpleService", "simple"), | ||
CodegenTest("aws.protocoltests.restjson#RestJson", "rest_json"), | ||
CodegenTest("aws.protocoltests.restjson.validation#RestJsonValidation", "rest_json_validation"), | ||
CodegenTest("aws.protocoltests.json10#JsonRpc10", "json_rpc10"), | ||
CodegenTest("aws.protocoltests.json#JsonProtocol", "json_rpc11"), | ||
CodegenTest("aws.protocoltests.misc#MiscService", "misc"), | ||
CodegenTest("com.amazonaws.ebs#Ebs", "ebs"), | ||
CodegenTest("com.amazonaws.s3#AmazonS3", "s3"), | ||
CodegenTest("com.aws.example#PokemonService", "pokemon_service_sdk") | ||
) | ||
|
||
task("generateSmithyBuild") { | ||
description = "generate smithy-build.json" | ||
doFirst { | ||
projectDir.resolve("smithy-build.json") | ||
.writeText( | ||
generateSmithyBuild( | ||
rootProject.projectDir.absolutePath, | ||
pluginName, | ||
codegenTests(properties, allCodegenTests) | ||
) | ||
) | ||
} | ||
} | ||
|
||
task("generateCargoWorkspace") { | ||
description = "generate Cargo.toml workspace file" | ||
doFirst { | ||
buildDir.resolve("$workingDirUnderBuildDir/Cargo.toml") | ||
.writeText(generateCargoWorkspace(pluginName, codegenTests(properties, allCodegenTests))) | ||
} | ||
} | ||
|
||
tasks["smithyBuildJar"].dependsOn("generateSmithyBuild") | ||
tasks["assemble"].finalizedBy("generateCargoWorkspace") | ||
|
||
tasks.register<Exec>(Cargo.CHECK.toString) { | ||
workingDir("$buildDir/$workingDirUnderBuildDir") | ||
environment("RUSTFLAGS", defaultRustFlags) | ||
commandLine("cargo", "check") | ||
dependsOn("assemble") | ||
} | ||
|
||
tasks.register<Exec>(Cargo.TEST.toString) { | ||
workingDir("$buildDir/$workingDirUnderBuildDir") | ||
environment("RUSTFLAGS", defaultRustFlags) | ||
commandLine("cargo", "test") | ||
dependsOn("assemble") | ||
} | ||
|
||
tasks.register<Exec>(Cargo.DOCS.toString) { | ||
workingDir("$buildDir/$workingDirUnderBuildDir") | ||
environment("RUSTDOCFLAGS", defaultRustDocFlags) | ||
commandLine("cargo", "doc", "--no-deps") | ||
dependsOn("assemble") | ||
} | ||
|
||
tasks.register<Exec>(Cargo.CLIPPY.toString) { | ||
workingDir("$buildDir/$workingDirUnderBuildDir") | ||
environment("RUSTFLAGS", defaultRustFlags) | ||
commandLine("cargo", "clippy") | ||
dependsOn("assemble") | ||
} | ||
|
||
tasks["test"].finalizedBy(cargoCommands(properties).map { it.toString }) | ||
|
||
tasks["clean"].doFirst { delete("smithy-build.json") } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
../model |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
/* | ||
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
import org.gradle.api.tasks.testing.logging.TestExceptionFormat | ||
|
||
plugins { | ||
kotlin("jvm") | ||
maven | ||
`maven-publish` | ||
} | ||
|
||
description = "Generates Rust/Python server-side code from Smithy models" | ||
|
||
extra["displayName"] = "Smithy :: Rust :: Codegen :: Server :: Python" | ||
|
||
extra["moduleName"] = "software.amazon.smithy.rust.codegen.server.python" | ||
|
||
group = "software.amazon.smithy.rust.codegen.server.python.smithy" | ||
|
||
version = "0.1.0" | ||
|
||
val smithyVersion: String by project | ||
val kotestVersion: String by project | ||
|
||
dependencies { | ||
implementation(project(":codegen")) | ||
implementation(project(":codegen-server")) | ||
implementation("software.amazon.smithy:smithy-aws-traits:$smithyVersion") | ||
implementation("software.amazon.smithy:smithy-protocol-test-traits:$smithyVersion") | ||
testImplementation("org.junit.jupiter:junit-jupiter:5.6.1") | ||
testImplementation("io.kotest:kotest-assertions-core-jvm:$kotestVersion") | ||
} | ||
|
||
tasks.compileKotlin { kotlinOptions.jvmTarget = "1.8" } | ||
tasks.compileTestKotlin { kotlinOptions.jvmTarget = "1.8" } | ||
|
||
// Reusable license copySpec | ||
val licenseSpec = copySpec { | ||
from("${project.rootDir}/LICENSE") | ||
from("${project.rootDir}/NOTICE") | ||
} | ||
|
||
// Configure jars to include license related info | ||
tasks.jar { | ||
metaInf.with(licenseSpec) | ||
inputs.property("moduleName", project.name) | ||
manifest { attributes["Automatic-Module-Name"] = project.name } | ||
} | ||
|
||
val sourcesJar by tasks.creating(Jar::class) { | ||
group = "publishing" | ||
description = "Assembles Kotlin sources jar" | ||
classifier = "sources" | ||
from(sourceSets.getByName("main").allSource) | ||
} | ||
|
||
tasks.test { | ||
useJUnitPlatform() | ||
testLogging { | ||
events("passed", "skipped", "failed") | ||
exceptionFormat = TestExceptionFormat.FULL | ||
showCauses = true | ||
showExceptions = true | ||
showStackTraces = true | ||
showStandardStreams = true | ||
} | ||
} | ||
|
||
publishing { | ||
publications { | ||
create<MavenPublication>("default") { | ||
from(components["java"]) | ||
artifact(sourcesJar) | ||
} | ||
} | ||
repositories { maven { url = uri("$buildDir/repository") } } | ||
} | ||
crisidev marked this conversation as resolved.
Show resolved
Hide resolved
|
78 changes: 78 additions & 0 deletions
78
...otlin/software/amazon/smithy/rust/codegen/server/python/smithy/RustCodegenServerPlugin.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
/* | ||
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
package software.amazon.smithy.rust.codegen.server.python.smithy | ||
|
||
import software.amazon.smithy.build.PluginContext | ||
import software.amazon.smithy.build.SmithyBuildPlugin | ||
import software.amazon.smithy.codegen.core.ReservedWordSymbolProvider | ||
import software.amazon.smithy.model.Model | ||
import software.amazon.smithy.model.shapes.ServiceShape | ||
import software.amazon.smithy.rust.codegen.rustlang.RustReservedWordSymbolProvider | ||
import software.amazon.smithy.rust.codegen.server.smithy.ServerCodegenVisitor | ||
import software.amazon.smithy.rust.codegen.smithy.BaseSymbolMetadataProvider | ||
import software.amazon.smithy.rust.codegen.smithy.DefaultConfig | ||
import software.amazon.smithy.rust.codegen.smithy.EventStreamSymbolProvider | ||
import software.amazon.smithy.rust.codegen.smithy.StreamingShapeMetadataProvider | ||
import software.amazon.smithy.rust.codegen.smithy.StreamingShapeSymbolProvider | ||
import software.amazon.smithy.rust.codegen.smithy.SymbolVisitor | ||
import software.amazon.smithy.rust.codegen.smithy.SymbolVisitorConfig | ||
import software.amazon.smithy.rust.codegen.smithy.customize.CombinedCodegenDecorator | ||
import java.util.logging.Level | ||
import java.util.logging.Logger | ||
|
||
/** Rust with Python bindings Codegen Plugin. | ||
* This is the entrypoint for code generation, triggered by the smithy-build plugin. | ||
* `resources/META-INF.services/software.amazon.smithy.build.SmithyBuildPlugin` refers to this class by name which | ||
* enables the smithy-build plugin to invoke `execute` with all of the Smithy plugin context + models. | ||
*/ | ||
class RustCodegenServerPlugin : SmithyBuildPlugin { | ||
private val logger = Logger.getLogger(javaClass.name) | ||
|
||
override fun getName(): String = "rust-server-codegen-python" | ||
|
||
override fun execute(context: PluginContext) { | ||
// Suppress extremely noisy logs about reserved words | ||
Logger.getLogger(ReservedWordSymbolProvider::class.java.name).level = Level.OFF | ||
// Discover [RustCodegenDecorators] on the classpath. [RustCodegenDectorator] return different types of | ||
// customization. A customization is a function of: | ||
// - location (e.g. the mutate section of an operation) | ||
// - context (e.g. the of the operation) | ||
// - writer: The active RustWriter at the given location | ||
val codegenDecorator = CombinedCodegenDecorator.fromClasspath(context) | ||
|
||
// ServerCodegenVisitor is the main driver of code generation that traverses the model and generates code | ||
logger.info("Loaded plugin to generate Rust/Python bindings for the server SSDK") | ||
ServerCodegenVisitor(context, codegenDecorator).execute() | ||
} | ||
|
||
companion object { | ||
/** SymbolProvider | ||
* When generating code, smithy types need to be converted into Rust types—that is the core role of the symbol provider | ||
* | ||
* The Symbol provider is composed of a base [SymbolVisitor] which handles the core functionality, then is layered | ||
* with other symbol providers, documented inline, to handle the full scope of Smithy types. | ||
*/ | ||
fun baseSymbolProvider( | ||
model: Model, | ||
serviceShape: ServiceShape, | ||
symbolVisitorConfig: SymbolVisitorConfig = DefaultConfig | ||
) = | ||
SymbolVisitor(model, serviceShape = serviceShape, config = symbolVisitorConfig) | ||
// Generate different types for EventStream shapes (e.g. transcribe streaming) | ||
.let { | ||
EventStreamSymbolProvider(symbolVisitorConfig.runtimeConfig, it, model) | ||
} | ||
// Generate [ByteStream] instead of `Blob` for streaming binary shapes (e.g. S3 GetObject) | ||
.let { StreamingShapeSymbolProvider(it, model) } | ||
// Add Rust attributes (like `#[derive(PartialEq)]`) to generated shapes | ||
.let { BaseSymbolMetadataProvider(it, additionalAttributes = listOf()) } | ||
// Streaming shapes need different derives (e.g. they cannot derive Eq) | ||
.let { StreamingShapeMetadataProvider(it, model) } | ||
// Rename shapes that clash with Rust reserved words & and other SDK specific features e.g. `send()` cannot | ||
// be the name of an operation input | ||
.let { RustReservedWordSymbolProvider(it, model) } | ||
} | ||
} |
5 changes: 5 additions & 0 deletions
5
...ython/src/main/resources/META-INF/services/software.amazon.smithy.build.SmithyBuildPlugin
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
# | ||
# Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
# SPDX-License-Identifier: Apache-2.0 | ||
# | ||
software.amazon.smithy.rust.codegen.server.python.smithy.RustCodegenServerPlugin |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
9 changes: 9 additions & 0 deletions
9
tools/ci-build/scripts/check-server-codegen-integration-tests-python
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
#!/bin/bash | ||
# | ||
# Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
# SPDX-License-Identifier: Apache-2.0 | ||
# | ||
|
||
set -eux | ||
cd smithy-rs | ||
./gradlew codegen-server-test:python:test |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
there's actually a way to share these between projects—I think the smithy project does it
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was wondering about this.. I'll figure out how to do it. Thanks.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I tried many things, but we really need the working dir which is defined in the build.gradle.kt, so I don't see how this can be shared between projects. Any pointers?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If this is not a blocker for this PR, I have created #1378 to track this issue and solve it once I figure out how :)