generated from TBD54566975/tbd-project-template
-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: wire up python schema extraction (#3369)
Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
- Loading branch information
1 parent
061ed8c
commit 17ead1f
Showing
19 changed files
with
245 additions
and
63 deletions.
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
Empty file.
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 |
---|---|---|
@@ -1,3 +1,3 @@ | ||
// Code generated by FTL. DO NOT EDIT. | ||
# Code generated by FTL. DO NOT EDIT. | ||
|
||
{{- $name := .Name -}} |
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,55 @@ | ||
package compile | ||
|
||
import ( | ||
"context" | ||
"os" | ||
"path/filepath" | ||
"testing" | ||
|
||
"github.com/TBD54566975/ftl/internal/exec" | ||
"github.com/TBD54566975/ftl/internal/log" | ||
"github.com/TBD54566975/ftl/internal/moduleconfig" | ||
"github.com/TBD54566975/ftl/internal/schema" | ||
"github.com/alecthomas/assert/v2" | ||
) | ||
|
||
func TestBuild(t *testing.T) { | ||
// set up | ||
moduleDir, err := filepath.Abs("testdata/echo") | ||
assert.NoError(t, err) | ||
ctx := log.ContextWithNewDefaultLogger(context.Background()) | ||
assert.NoError(t, os.RemoveAll(filepath.Join(moduleDir, ".venv"))) | ||
assert.NoError(t, exec.Command(ctx, log.Debug, moduleDir, "uv", "sync", "-n").Run()) | ||
|
||
t.Run("schema extraction", func(t *testing.T) { | ||
config := moduleconfig.AbsModuleConfig{ | ||
Dir: moduleDir, | ||
Module: "test", | ||
} | ||
actual, buildErrors, err := Build(ctx, "", "", config, &schema.Schema{}, nil, true) | ||
assert.NoError(t, err) | ||
assert.Equal(t, 0, len(buildErrors)) | ||
expected := &schema.Module{ | ||
Name: "echo", | ||
Decls: []schema.Decl{ | ||
&schema.Data{ | ||
Name: "EchoRequest", | ||
Fields: []*schema.Field{ | ||
{Name: "name", Type: &schema.String{}}, | ||
}, | ||
}, | ||
&schema.Data{ | ||
Name: "EchoResponse", | ||
Fields: []*schema.Field{ | ||
{Name: "message", Type: &schema.String{}}, | ||
}, | ||
}, | ||
&schema.Verb{Name: "echo", | ||
Request: &schema.Ref{Module: "echo", Name: "EchoRequest"}, | ||
Response: &schema.Ref{Module: "echo", Name: "EchoResponse"}, | ||
}, | ||
}, | ||
} | ||
assert.Equal(t, expected, actual, assert.Exclude[schema.Position]()) | ||
}) | ||
} |
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 @@ | ||
3.12 |
Empty file.
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,18 @@ | ||
from dataclasses import dataclass | ||
|
||
from ftl import verb | ||
|
||
|
||
@dataclass | ||
class EchoRequest: | ||
name: str | ||
|
||
|
||
@dataclass | ||
class EchoResponse: | ||
message: str | ||
|
||
|
||
@verb | ||
def echo(req: EchoRequest) -> EchoResponse: | ||
return EchoResponse(message=f"ayooo, {req.name}!") |
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,2 @@ | ||
module = "echo" | ||
language = "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,10 @@ | ||
[project] | ||
name = "echo" | ||
version = "0.1.0" | ||
description = "Add your description here" | ||
readme = "README.md" | ||
requires-python = ">=3.12" | ||
dependencies = ["ftl"] | ||
|
||
[tool.uv.sources] | ||
ftl = { path = "../../../../python-runtime/ftl" } |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
Oops, something went wrong.