Skip to content

Commit

Permalink
feat(Python)!: Python codegen raises error if formatters aren't insta…
Browse files Browse the repository at this point in the history
…lled (#709)

**BREAKING CHANGE:** You must install `docformatter` and `black` to run Python codegen. Smithy-Dafny Python codegen will now raise an error when these formatters are not found. This was previously treated as a warning. This change may disrupt existing workflows that generated Python code without these formatters installed.
  • Loading branch information
lucasmcdonald3 authored Nov 21, 2024
1 parent 180ad67 commit 94c3aa1
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 4 deletions.
3 changes: 3 additions & 0 deletions .github/workflows/test_models_python_tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,9 @@ jobs:
arguments: :smithy-dafny-codegen:pTML
build-root-directory: codegen

- name: Install formatters
run: make setup_smithy_dafny_python

- name: Execute smithy-dafny-codegen-test tests
uses: gradle/gradle-build-action@v2
env:
Expand Down
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,14 @@ See the [`codegen/smithy-dafny-codegen-cli`](codegen/smithy-dafny-codegen-cli) d
make mvn_local_deploy_polymorph
```

### Python

1. To generate Python code with Smithy-Dafny, you must install Python libraries that format the code. Run:
```
make setup_smithy_dafny_python
```
The packages installed by this step must be accessible via a `bash` invocation of `python3`.

## Limitations

### Completeness
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -346,8 +346,7 @@ private void formatCode(FileManifest fileManifest) {
try {
CodegenUtils.runCommand("python3 -m black -h", fileManifest.getBaseDir());
} catch (CodegenException e) {
LOGGER.warning("Unable to find the python package black. Skipping formatting.");
return;
throw new CodegenException("Unable to find the python package black. Run `make setup_smithy_dafny_python` and ensure `python3 -m black` indicates the package is installed.", e);
}
LOGGER.info("Running code formatter on generated code");
CodegenUtils.runCommand("python3 -m black . --exclude \"\"", fileManifest.getBaseDir());
Expand All @@ -357,8 +356,7 @@ private void formatDocstrings(FileManifest fileManifest) {
try {
CodegenUtils.runCommand("python3 -m docformatter -h", fileManifest.getBaseDir());
} catch (CodegenException e) {
LOGGER.warning("Unable to find the python package docformatter. Skipping formatting.");
return;
throw new CodegenException("Unable to find the python package docformatter. Run `make setup_smithy_dafny_python` and ensure `python3 -m docformatter` indicates the package is installed.", e);
}
LOGGER.info("Running docformatter on generated code");
// docformatter exit codes:
Expand Down

0 comments on commit 94c3aa1

Please sign in to comment.