Unverified Commit 5312ff11 authored by Matteo Bigoi's avatar Matteo Bigoi Committed by GitHub
Browse files

Export a usable Python implementation via shared library (#1476)

This PR add several functionalities to the Python/Rust code-generation, making it usable for models that are not using Streaming and Union shapes.

    * Export codegenerated shapes as shared library that can be imported by the Python interpreter.
    * Add complete end-to-end testing running in CI.
    * Register signals and handle workers processes lifecycle.
    * Use a custom SymbolProvider to override non-primitive types that are exposed to Python.
    * Implement support for DateTime.
    * Cast Python exception into Rust error types.
    * End to end testing suite with a Rust client calling a real Python server.
parent eb1cb074
Loading
Loading
Loading
Loading
+5 −2
Original line number Diff line number Diff line
@@ -67,6 +67,7 @@ jobs:
        - action: check-server-codegen-integration-tests-python
        - action: check-server-codegen-unit-tests-python
        - action: check-server-e2e-test
        - action: check-server-python-e2e-test
        - action: check-style-and-lints
    steps:
    - uses: actions/checkout@v3
@@ -129,8 +130,10 @@ jobs:
      run: |
        for runtime_path in "rust-runtime" "aws/rust-runtime"; do
          pushd "${runtime_path}" &>/dev/null
          cargo test --all-features
          cargo doc --no-deps --document-private-items --all-features
          # aws-smithy-http-server-python cannot be compiled on Windows since it uses the `signal-hook` crate
          # which is not really yet fully supported on the platform.
          cargo test --all-features --workspace --exclude aws-smithy-http-server-python
          cargo doc --no-deps --document-private-items --all-features --workspace --exclude aws-smithy-http-server-python
          popd &>/dev/null
        done

+2 −2
Original line number Diff line number Diff line
@@ -95,7 +95,7 @@ jobs:
        ./gradlew -Paws.services=+sts,+sso,+transcribestreaming,+dynamodb :aws:sdk:assemble

        # Copy the Server runtime crate(s) in
        cp -r rust-runtime/aws-smithy-http-server aws/sdk/build/aws-sdk/sdk
        cp -r rust-runtime/aws-smithy-http-server rust-runtime/aws-smithy-http-server-python aws/sdk/build/aws-sdk/sdk

        pushd aws/sdk/build/aws-sdk

@@ -103,7 +103,7 @@ jobs:
        sed -i '/examples/d' Cargo.toml

        # Add server runtime crates to the workspace
        sed -i 's/"sdk\/sts",/"sdk\/sts","sdk\/aws-smithy-http-server",/' Cargo.toml
        sed -i 's/"sdk\/sts",/"sdk\/sts","sdk\/aws-smithy-http-server","sdk\/aws-smithy-http-server-python",/' Cargo.toml

        cargo doc --no-deps --all-features
        popd
+4 −0
Original line number Diff line number Diff line
@@ -72,6 +72,10 @@ check-server-codegen-unit-tests-python:
check-server-e2e-test:
	$(CI_ACTION) $@ $(ARGS)

.PHONY: check-server-python-e2e-test
check-server-python-e2e-test:
	$(CI_ACTION) $@ $(ARGS)

.PHONY: check-style-and-lints
check-style-and-lints:
	$(CI_ACTION) $@ $(ARGS)

codegen-server-test/python/model

deleted120000 → 0
+0 −1
Original line number Diff line number Diff line
../model
 No newline at end of file
+131 −0
Original line number Diff line number Diff line
/// TODO(https://github.com/awslabs/smithy-rs/issues/1508)
/// $econcile this model with the main one living inside codegen-server-test/model/pokemon.smithy
/// once the Python implementation supports Streaming and Union shapes.
$version: "1.0"

namespace com.aws.example

use aws.protocols#restJson1

/// The Pokémon Service allows you to retrieve information about Pokémon species.
@title("Pokémon Service")
@restJson1
service PokemonService {
    version: "2021-12-01",
    resources: [PokemonSpecies],
    operations: [GetServerStatistics, EmptyOperation],
}

/// A Pokémon species forms the basis for at least one Pokémon.
@title("Pokémon Species")
resource PokemonSpecies {
    identifiers: {
        name: String
    },
    read: GetPokemonSpecies,
}

/// Retrieve information about a Pokémon species.
@readonly
@http(uri: "/pokemon-species/{name}", method: "GET")
operation GetPokemonSpecies {
    input: GetPokemonSpeciesInput,
    output: GetPokemonSpeciesOutput,
    errors: [ResourceNotFoundException],
}

@input
structure GetPokemonSpeciesInput {
    @required
    @httpLabel
    name: String
}

@output
structure GetPokemonSpeciesOutput {
    /// The name for this resource.
    @required
    name: String,

    /// A list of flavor text entries for this Pokémon species.
    @required
    flavorTextEntries: FlavorTextEntries
}

/// Retrieve HTTP server statistiscs, such as calls count.
@readonly
@http(uri: "/stats", method: "GET")
operation GetServerStatistics {
    input: GetServerStatisticsInput,
    output: GetServerStatisticsOutput,
}

@input
structure GetServerStatisticsInput { }

@output
structure GetServerStatisticsOutput {
    /// The number of calls executed by the server.
    @required
    calls_count: Long,
}

list FlavorTextEntries {
    member: FlavorText
}

structure FlavorText {
    /// The localized flavor text for an API resource in a specific language.
    @required
    flavorText: String,

    /// The language this name is in.
    @required
    language: Language,
}

/// Supported languages for FlavorText entries.
@enum([
    {
        name: "ENGLISH",
        value: "en",
        documentation: "American English.",
    },
    {
        name: "SPANISH",
        value: "es",
        documentation: "Español.",
    },
    {
        name: "ITALIAN",
        value: "it",
        documentation: "Italiano.",
    },
    {
        name: "JAPANESE",
        value: "jp",
        documentation: "日本語。",
    },
])
string Language

/// Empty operation, used to stress test the framework.
@readonly
@http(uri: "/empty-operation", method: "GET")
operation EmptyOperation {
    input: EmptyOperationInput,
    output: EmptyOperationOutput,
}

@input
structure EmptyOperationInput { }

@output
structure EmptyOperationOutput { }

@error("client")
@httpError(404)
structure ResourceNotFoundException {
    @required
    message: String,
}
Loading