Skip to content

Commit 7613677

Browse files
srinjoyraycopybara-github
authored andcommitted
Add pyproject.toml support to CRF
PiperOrigin-RevId: 807156043 Change-Id: I0fd2d42b0c56a2ea329666ddcda782d11b7ca7d0
1 parent 034e532 commit 7613677

File tree

21 files changed

+725
-73
lines changed

21 files changed

+725
-73
lines changed

builders/gcp/base/acceptance/python_fn_test.go

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,22 @@ func TestAcceptancePythonFn(t *testing.T) {
6969
MustUse: []string{pythonRuntime, pythonFF, pythonPIP},
7070
MustNotUse: []string{entrypoint},
7171
},
72+
{
73+
Name: "function_with_uv",
74+
App: "uv",
75+
Path: "/testFunction",
76+
Env: []string{"GOOGLE_FUNCTION_TARGET=testFunction", "GOOGLE_PYTHON_VERSION=3.13.0", "X_GOOGLE_RELEASE_TRACK=ALPHA"},
77+
MustUse: []string{pythonRuntime, pythonUV, pythonFF},
78+
MustNotUse: []string{entrypoint},
79+
},
80+
{
81+
Name: "function_with_poetry",
82+
App: "poetry",
83+
Path: "/testFunction",
84+
Env: []string{"GOOGLE_FUNCTION_TARGET=testFunction", "GOOGLE_PYTHON_VERSION=3.13.0", "X_GOOGLE_RELEASE_TRACK=ALPHA"},
85+
MustUse: []string{pythonRuntime, pythonPoetry, pythonFF},
86+
MustNotUse: []string{entrypoint},
87+
},
7288
}
7389
for _, tc := range testCases {
7490
tc := tc
@@ -97,6 +113,12 @@ func TestFailuresPythonFn(t *testing.T) {
97113
Env: []string{"GOOGLE_FUNCTION_TARGET=testFunction", "GOOGLE_PYTHON_VERSION=3.13.0"},
98114
MustMatch: "missing main.py and GOOGLE_FUNCTION_SOURCE not specified. Either create the function in main.py or specify GOOGLE_FUNCTION_SOURCE to point to the file that contains the function",
99115
},
116+
{
117+
Name: "missing_framework_pyproject",
118+
App: "fail_pyproject_without_framework",
119+
Env: []string{"GOOGLE_FUNCTION_TARGET=testFunction", "GOOGLE_PYTHON_VERSION=3.13.0", "X_GOOGLE_RELEASE_TRACK=ALPHA"},
120+
MustMatch: "This project is using pyproject.toml but you have not included the Functions Framework in your dependencies. Please add it by running: 'poetry add functions-framework' or 'uv add functions-framework'.",
121+
},
100122
}
101123

102124
for _, tc := range testCases {

builders/gcp/base/builder.toml

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -501,6 +501,43 @@ description = "Ubuntu 22.04 base image with buildpacks for .NET, Dart, Go, Java,
501501
id = "google.utils.label-image"
502502

503503
# Python functions.
504+
# Poetry order group.
505+
[[order]]
506+
[[order.group]]
507+
id = "google.python.runtime"
508+
509+
[[order.group]]
510+
id = "google.python.functions-framework"
511+
512+
[[order.group]]
513+
id = "google.python.poetry"
514+
515+
[[order.group]]
516+
id = "google.config.entrypoint"
517+
optional = true
518+
519+
[[order.group]]
520+
id = "google.utils.label-image"
521+
522+
# UV order group.
523+
[[order]]
524+
[[order.group]]
525+
id = "google.python.runtime"
526+
527+
[[order.group]]
528+
id = "google.python.functions-framework"
529+
530+
[[order.group]]
531+
id = "google.python.uv"
532+
533+
[[order.group]]
534+
id = "google.config.entrypoint"
535+
optional = true
536+
537+
[[order.group]]
538+
id = "google.utils.label-image"
539+
540+
# Pip order group.
504541
[[order]]
505542
[[order.group]]
506543
id = "google.python.runtime"

builders/gcp/base/google.22.builder.toml

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -501,6 +501,43 @@ description = "Ubuntu 22.04 base image with buildpacks for .NET, Dart, Go, Java,
501501
id = "google.utils.label-image"
502502

503503
# Python functions.
504+
# Poetry order group.
505+
[[order]]
506+
[[order.group]]
507+
id = "google.python.runtime"
508+
509+
[[order.group]]
510+
id = "google.python.functions-framework"
511+
512+
[[order.group]]
513+
id = "google.python.poetry"
514+
515+
[[order.group]]
516+
id = "google.config.entrypoint"
517+
optional = true
518+
519+
[[order.group]]
520+
id = "google.utils.label-image"
521+
522+
# UV order group.
523+
[[order]]
524+
[[order.group]]
525+
id = "google.python.runtime"
526+
527+
[[order.group]]
528+
id = "google.python.functions-framework"
529+
530+
[[order.group]]
531+
id = "google.python.uv"
532+
533+
[[order.group]]
534+
id = "google.config.entrypoint"
535+
optional = true
536+
537+
[[order.group]]
538+
id = "google.utils.label-image"
539+
540+
# Pip order group.
504541
[[order]]
505542
[[order.group]]
506543
id = "google.python.runtime"

builders/gcp/base/google.24.builder.runner.toml

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -501,6 +501,43 @@ description = "Ubuntu 24.04 base image with buildpacks for .NET, Dart, Go, Java,
501501
id = "google.utils.label-image"
502502

503503
# Python functions.
504+
# Poetry order group.
505+
[[order]]
506+
[[order.group]]
507+
id = "google.python.runtime"
508+
509+
[[order.group]]
510+
id = "google.python.functions-framework"
511+
512+
[[order.group]]
513+
id = "google.python.poetry"
514+
515+
[[order.group]]
516+
id = "google.config.entrypoint"
517+
optional = true
518+
519+
[[order.group]]
520+
id = "google.utils.label-image"
521+
522+
# UV order group.
523+
[[order]]
524+
[[order.group]]
525+
id = "google.python.runtime"
526+
527+
[[order.group]]
528+
id = "google.python.functions-framework"
529+
530+
[[order.group]]
531+
id = "google.python.uv"
532+
533+
[[order.group]]
534+
id = "google.config.entrypoint"
535+
optional = true
536+
537+
[[order.group]]
538+
id = "google.utils.label-image"
539+
540+
# Pip order group.
504541
[[order]]
505542
[[order.group]]
506543
id = "google.python.runtime"

builders/gcp/base/google.24.builder.toml

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -501,6 +501,43 @@ description = "Ubuntu 24.04 base image with buildpacks for .NET, Dart, Go, Java,
501501
id = "google.utils.label-image"
502502

503503
# Python functions.
504+
# Poetry order group.
505+
[[order]]
506+
[[order.group]]
507+
id = "google.python.runtime"
508+
509+
[[order.group]]
510+
id = "google.python.functions-framework"
511+
512+
[[order.group]]
513+
id = "google.python.poetry"
514+
515+
[[order.group]]
516+
id = "google.config.entrypoint"
517+
optional = true
518+
519+
[[order.group]]
520+
id = "google.utils.label-image"
521+
522+
# UV order group.
523+
[[order]]
524+
[[order.group]]
525+
id = "google.python.runtime"
526+
527+
[[order.group]]
528+
id = "google.python.functions-framework"
529+
530+
[[order.group]]
531+
id = "google.python.uv"
532+
533+
[[order.group]]
534+
id = "google.config.entrypoint"
535+
optional = true
536+
537+
[[order.group]]
538+
id = "google.utils.label-image"
539+
540+
# Pip order group.
504541
[[order]]
505542
[[order.group]]
506543
id = "google.python.runtime"

builders/python/acceptance/gcf_test.go

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,15 @@ import (
1919
"github.com/GoogleCloudPlatform/buildpacks/internal/acceptance"
2020
)
2121

22+
const (
23+
entrypoint = "google.config.entrypoint"
24+
pythonFF = "google.python.functions-framework"
25+
pythonPIP = "google.python.pip"
26+
pythonRuntime = "google.python.runtime"
27+
pythonPoetry = "google.python.poetry"
28+
pythonUV = "google.python.uv"
29+
)
30+
2231
func init() {
2332
acceptance.DefineFlags()
2433
}
@@ -84,6 +93,27 @@ func TestAcceptance(t *testing.T) {
8493
SkipStacks: []string{"google.min.22"},
8594
VersionInclusionConstraint: ">= 3.8.0",
8695
},
96+
{
97+
Name: "poetry",
98+
App: "poetry",
99+
Env: []string{"X_GOOGLE_RELEASE_TRACK=ALPHA"},
100+
VersionInclusionConstraint: ">=3.9.0",
101+
MustUse: []string{pythonRuntime, pythonPoetry, pythonFF},
102+
},
103+
{
104+
Name: "pyproject",
105+
App: "pyproject",
106+
Env: []string{"X_GOOGLE_RELEASE_TRACK=ALPHA"},
107+
VersionInclusionConstraint: ">=3.9.0",
108+
MustUse: []string{pythonRuntime, pythonUV, pythonFF},
109+
},
110+
{
111+
Name: "uv",
112+
App: "uv",
113+
Env: []string{"X_GOOGLE_RELEASE_TRACK=ALPHA"},
114+
VersionInclusionConstraint: ">=3.9.0",
115+
MustUse: []string{pythonRuntime, pythonUV, pythonFF},
116+
},
87117
}
88118
for _, tc := range acceptance.FilterTests(t, imageCtx, testCases) {
89119
tc := applyStaticTestOptions(tc)
@@ -135,6 +165,12 @@ func TestFailures(t *testing.T) {
135165
Env: []string{"GOOGLE_VENDOR_PIP_DEPENDENCIES=vendor"},
136166
MustMatch: "Vendored dependencies detected, please add functions-framework to requirements.txt and download it using pip",
137167
},
168+
{
169+
Name: "fail_pyproject_without_framework",
170+
App: "fail_pyproject_without_framework",
171+
Env: []string{"X_GOOGLE_RELEASE_TRACK=ALPHA"},
172+
MustMatch: "This project is using pyproject.toml but you have not included the Functions Framework in your dependencies. Please add it by running: 'poetry add functions-framework' or 'uv add functions-framework'.",
173+
},
138174
}
139175

140176
for _, tc := range acceptance.FilterFailureTests(t, testCases) {

builders/python/builder.toml.template

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,55 @@ description = "Unified builder all Python runtimes"
8080
id = "google.utils.label-image"
8181

8282
# Python functions (gcf and gcp).
83+
# Poetry order group.
84+
[[order]]
85+
86+
# gcf only
87+
[[order.group]]
88+
id = "google.utils.archive-source"
89+
optional = true
90+
91+
[[order.group]]
92+
id = "google.python.runtime"
93+
94+
[[order.group]]
95+
id = "google.python.functions-framework"
96+
97+
[[order.group]]
98+
id = "google.python.poetry"
99+
100+
[[order.group]]
101+
id = "google.utils.label-image"
102+
103+
[[order.group]]
104+
id = "google.python.link-runtime"
105+
optional = true
106+
107+
# UV order group.
108+
[[order]]
109+
110+
# gcf only
111+
[[order.group]]
112+
id = "google.utils.archive-source"
113+
optional = true
114+
115+
[[order.group]]
116+
id = "google.python.runtime"
117+
118+
[[order.group]]
119+
id = "google.python.functions-framework"
120+
121+
[[order.group]]
122+
id = "google.python.uv"
123+
124+
[[order.group]]
125+
id = "google.utils.label-image"
126+
127+
[[order.group]]
128+
id = "google.python.link-runtime"
129+
optional = true
130+
131+
# Pip order group.
83132
[[order]]
84133

85134
# gcf only

builders/python/builder_using_runner.toml.template

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,56 @@ description = "Unified builder all Python runtimes"
8080
id = "google.utils.label-image"
8181

8282
# Python functions (gcf and gcp).
83+
84+
# Poetry order group.
85+
[[order]]
86+
87+
# gcf only
88+
[[order.group]]
89+
id = "google.utils.archive-source"
90+
optional = true
91+
92+
[[order.group]]
93+
id = "google.python.runtime"
94+
95+
[[order.group]]
96+
id = "google.python.functions-framework"
97+
98+
[[order.group]]
99+
id = "google.python.poetry"
100+
101+
[[order.group]]
102+
id = "google.utils.label-image"
103+
104+
[[order.group]]
105+
id = "google.python.link-runtime"
106+
optional = true
107+
108+
# UV order group.
109+
[[order]]
110+
111+
# gcf only
112+
[[order.group]]
113+
id = "google.utils.archive-source"
114+
optional = true
115+
116+
[[order.group]]
117+
id = "google.python.runtime"
118+
119+
[[order.group]]
120+
id = "google.python.functions-framework"
121+
122+
[[order.group]]
123+
id = "google.python.uv"
124+
125+
[[order.group]]
126+
id = "google.utils.label-image"
127+
128+
[[order.group]]
129+
id = "google.python.link-runtime"
130+
optional = true
131+
132+
# Pip order group.
83133
[[order]]
84134

85135
# gcf only

0 commit comments

Comments
 (0)