Skip to content

Commit

Permalink
feat!: Python codegen (#503)
Browse files Browse the repository at this point in the history
  • Loading branch information
lucasmcdonald3 authored Aug 27, 2024
1 parent 1b395e0 commit 768014f
Show file tree
Hide file tree
Showing 650 changed files with 38,626 additions and 205 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#
# This local action sets up code dependencies
# to run Smithy-Dafny CI in GitHub Actions workflows.
#

name: "Install Smithy-Dafny codegen dependencies"
description: "Install Java package dependencies required to run Smithy-Dafny codegen"
runs:
using: "composite"
steps:
- name: Install smithy-dafny-codegen Rust dependencies locally
uses: gradle/gradle-build-action@v2
with:
arguments: :codegen-client:pTML :codegen-core:pTML :rust-runtime:pTML
build-root-directory: smithy-dafny-codegen-modules/smithy-rs

- name: Install smithy-dafny-codegen Python dependencies locally
uses: gradle/gradle-build-action@v2
with:
arguments: :smithy-python-codegen:pTML
build-root-directory: codegen/smithy-dafny-codegen-modules/smithy-python/codegen
4 changes: 4 additions & 0 deletions .github/workflows/manual.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,3 +28,7 @@ jobs:
uses: ./.github/workflows/test_models_rust_tests.yml
with:
dafny: ${{ inputs.dafny }}
manual-ci-python:
uses: ./.github/workflows/test_models_python_tests.yml
with:
dafny: ${{ inputs.dafny }}
5 changes: 5 additions & 0 deletions .github/workflows/nightly_dafny.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,11 @@ jobs:
uses: ./.github/workflows/test_models_rust_tests.yml
with:
dafny: "feat-rust"
dafny-nightly-python:
if: github.event_name != 'schedule' || github.repository_owner == 'smithy-lang'
uses: ./.github/workflows/test_models_python_tests.yml
with:
dafny: "nightly-latest"

cut-issue-on-failure:
runs-on: ubuntu-latest
Expand Down
13 changes: 13 additions & 0 deletions .github/workflows/pull.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,12 @@ jobs:
- name: Populate Dafny versions list
id: populate-dafny-versions-list
run: echo "dafny-versions-list=['4.2.0', '4.4.0']" >> $GITHUB_OUTPUT
- name: Populate Dafny versions list for "only new versions" languages (Python)
id: populate-only-new-dafny-versions-list
run: echo "only-new-dafny-versions-list=['4.7.0']" >> $GITHUB_OUTPUT
outputs:
dafny-version-list: ${{ steps.populate-dafny-versions-list.outputs.dafny-versions-list }}
only-new-dafny-version-list: ${{ steps.populate-only-new-dafny-versions-list.outputs.only-new-dafny-versions-list }}

pr-ci-verification:
needs: pr-populate-dafny-versions
Expand Down Expand Up @@ -53,3 +57,12 @@ jobs:
uses: ./.github/workflows/test_models_rust_tests.yml
with:
dafny: ${{ matrix.dafny-version }}
pr-ci-python:
needs: pr-populate-dafny-versions
strategy:
fail-fast: false
matrix:
dafny-version: ${{ fromJson(needs.pr-populate-dafny-versions.outputs.only-new-dafny-version-list) }}
uses: ./.github/workflows/test_models_python_tests.yml
with:
dafny: ${{ matrix.dafny-version }}
13 changes: 13 additions & 0 deletions .github/workflows/push.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,12 @@ jobs:
- name: Populate Dafny versions list
id: populate-dafny-versions-list
run: echo "dafny-versions-list=['4.2.0', '4.4.0']" >> $GITHUB_OUTPUT
- name: Populate Dafny versions list for "only new versions" languages (Python)
id: populate-only-new-dafny-versions-list
run: echo "only-new-dafny-versions-list=['4.7.0']" >> $GITHUB_OUTPUT
outputs:
dafny-version-list: ${{ steps.populate-dafny-versions-list.outputs.dafny-versions-list }}
only-new-dafny-version-list: ${{ steps.populate-only-new-dafny-versions-list.outputs.only-new-dafny-versions-list }}

push-ci-verification:
needs: pr-populate-dafny-versions
Expand Down Expand Up @@ -55,3 +59,12 @@ jobs:
uses: ./.github/workflows/test_models_rust_tests.yml
with:
dafny: ${{ matrix.dafny-version }}
push-ci-python:
needs: pr-populate-dafny-versions
strategy:
fail-fast: false
matrix:
dafny-version: ${{ fromJson(needs.pr-populate-dafny-versions.outputs.only-new-dafny-version-list) }}
uses: ./.github/workflows/test_models_python_tests.yml
with:
dafny: ${{ matrix.dafny-version }}
7 changes: 2 additions & 5 deletions .github/workflows/smithy-polymorph.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,8 @@ jobs:
# Matching the hard-coded version for the "2023" edition for now
dafny-version: 4.1.0

- name: Install smithy-dafny-codegen dependencies locally
uses: gradle/gradle-build-action@v2
with:
arguments: :codegen-client:pTML :codegen-core:pTML :rust-runtime:pTML
build-root-directory: smithy-dafny-codegen-modules/smithy-rs
- name: Install Smithy-Dafny codegen dependencies
uses: ./.github/actions/install_smithy_dafny_codegen_dependencies

- name: Execute smithy-dafny-codegen-cli tests
uses: gradle/gradle-build-action@v2
Expand Down
7 changes: 2 additions & 5 deletions .github/workflows/test_models_dafny_verification.yml
Original file line number Diff line number Diff line change
Expand Up @@ -58,11 +58,8 @@ jobs:
distribution: "corretto"
java-version: "17"

- name: Install smithy-dafny-codegen dependencies locally
uses: gradle/gradle-build-action@v2
with:
arguments: :codegen-client:pTML :codegen-core:pTML :rust-runtime:pTML
build-root-directory: smithy-dafny-codegen-modules/smithy-rs
- name: Install Smithy-Dafny codegen dependencies
uses: ./.github/actions/install_smithy_dafny_codegen_dependencies

- name: Install smithy-dafny-codegen locally
uses: gradle/gradle-build-action@v2
Expand Down
7 changes: 2 additions & 5 deletions .github/workflows/test_models_java_tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -68,11 +68,8 @@ jobs:
arguments: publishToMavenLocal
build-root-directory: smithy-dafny-conversion

- name: Install smithy-dafny-codegen dependencies locally
uses: gradle/gradle-build-action@v2
with:
arguments: :codegen-client:pTML :codegen-core:pTML :rust-runtime:pTML
build-root-directory: smithy-dafny-codegen-modules/smithy-rs
- name: Install Smithy-Dafny codegen dependencies
uses: ./.github/actions/install_smithy_dafny_codegen_dependencies

- name: Install smithy-dafny-codegen locally
uses: gradle/gradle-build-action@v2
Expand Down
7 changes: 2 additions & 5 deletions .github/workflows/test_models_net_tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -78,11 +78,8 @@ jobs:
distribution: "corretto"
java-version: "17"

- name: Install smithy-dafny-codegen dependencies locally
uses: gradle/gradle-build-action@v2
with:
arguments: :codegen-client:pTML :codegen-core:pTML :rust-runtime:pTML
build-root-directory: smithy-dafny-codegen-modules/smithy-rs
- name: Install Smithy-Dafny codegen dependencies
uses: ./.github/actions/install_smithy_dafny_codegen_dependencies

- name: Install smithy-dafny-codegen locally
uses: gradle/gradle-build-action@v2
Expand Down
98 changes: 98 additions & 0 deletions .github/workflows/test_models_python_tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
# This workflow performs tests in Python.
name: Library Python tests

on:
workflow_call:
inputs:
dafny:
description: "The Dafny version to run"
required: true
type: string
num_shards:
required: false
type: number
default: 5

jobs:
populate-matrix-dimensions:
runs-on: ubuntu-latest
steps:
- name: Populate shard list
id: populate-shard-list
run: echo "shard-list=[`seq -s , 1 ${{ inputs.num_shards }}`]" >> $GITHUB_OUTPUT
outputs:
shard-list: ${{ steps.populate-shard-list.outputs.shard-list }}

testPython:
needs: populate-matrix-dimensions
strategy:
fail-fast: false # at least for development; see all errors
matrix:
shard: ${{ fromJson(needs.populate-matrix-dimensions.outputs.shard-list) }}
runs-on: "ubuntu-latest"
permissions:
id-token: write
contents: read
env:
DOTNET_CLI_TELEMETRY_OPTOUT: 1
DOTNET_NOLOGO: 1
steps:
- name: Support longpaths on Git checkout
run: |
git config --global core.longpaths true
- name: Configure AWS Credentials
uses: aws-actions/configure-aws-credentials@v1
with:
aws-region: us-west-2
role-to-assume: arn:aws:iam::370957321024:role/GitHub-CI-PolymorphTestModels-Role-us-west-2
role-session-name: PythonTests

- uses: actions/checkout@v3
with:
submodules: recursive

- name: Setup Dafny
uses: dafny-lang/[email protected]
with:
dafny-version: ${{ inputs.dafny }}

- name: Setup Python for running tests
uses: actions/setup-python@v4
with:
python-version: 3.11
architecture: x64
- run: |
python -m pip install --upgrade pip
pip install --upgrade tox
pip install poetry
- name: Setup Java 17 for codegen
uses: actions/setup-java@v3
with:
distribution: "corretto"
java-version: 17

- name: Setup smithy-dafny-conversion
uses: gradle/gradle-build-action@v2
with:
arguments: publishToMavenLocal
build-root-directory: smithy-dafny-conversion

- name: Install Smithy-Dafny codegen dependencies
uses: ./.github/actions/install_smithy_dafny_codegen_dependencies

- name: Install smithy-dafny-codegen locally
uses: gradle/gradle-build-action@v2
with:
arguments: :smithy-dafny-codegen:pTML
build-root-directory: codegen

- name: Execute smithy-dafny-codegen-test tests
uses: gradle/gradle-build-action@v2
env:
JUNIT_SHARD: ${{ matrix.shard }}
JUNIT_SHARD_COUNT: ${{ inputs.num_shards }}
with:
arguments: :smithy-dafny-codegen-test:test --tests '*smithypython*' --info
build-root-directory: codegen
7 changes: 2 additions & 5 deletions .github/workflows/test_models_rust_tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -69,11 +69,8 @@ jobs:
distribution: "corretto"
java-version: "17"

- name: Install smithy-dafny-codegen dependencies locally
uses: gradle/gradle-build-action@v2
with:
arguments: :codegen-client:pTML :codegen-core:pTML :rust-runtime:pTML
build-root-directory: smithy-dafny-codegen-modules/smithy-rs
- name: Install Smithy-Dafny codegen dependencies
uses: ./.github/actions/install_smithy_dafny_codegen_dependencies

- name: Install smithy-dafny-codegen locally
uses: gradle/gradle-build-action@v2
Expand Down
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
/.idea
/.history
/.smithy.lsp.log
*.pyc

*/**/.idea
/codegen/smithy-dafny-codegen/bin
Expand All @@ -11,6 +12,7 @@
.project
.classpath
.settings
.class

# Added by formatting tooling
node_modules
2 changes: 2 additions & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
**/smithy-dafny-codegen-modules/**

# Codegen templates (often not parsable)
codegen/smithy-dafny-codegen/src/main/resources/templates/**/*.*

Expand Down
8 changes: 7 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,16 @@ format_java_misc-check: setup_prettier
setup_prettier:
npm i --no-save prettier@3 [email protected]

mvn_local_deploy_polymorph_dependencies:
mvn_local_deploy_polymorph_dependencies: mvn_local_deploy_polymorph_rust_dependencies mvn_local_deploy_polymorph_python_dependencies

mvn_local_deploy_polymorph_rust_dependencies:
cd smithy-dafny-codegen-modules/smithy-rs; \
./gradlew :codegen-client:pTML :codegen-core:pTML :rust-runtime:pTML

mvn_local_deploy_polymorph_python_dependencies:
cd codegen/smithy-dafny-codegen-modules/smithy-python/codegen; \
./gradlew :smithy-python-codegen:pTML

mvn_local_deploy_polymorph:
cd codegen; \
./gradlew :smithy-dafny-codegen:pTML
Loading

0 comments on commit 768014f

Please sign in to comment.