Skip to content

Commit 6880fc7

Browse files
HarshaliRakacopybara-github
authored andcommitted
Check for main.py and app.py in Root Directory only
PiperOrigin-RevId: 803099414 Change-Id: If56326f96f5b48352463080eb6eac10560f691cf
1 parent 3237b4b commit 6880fc7

File tree

2 files changed

+22
-7
lines changed

2 files changed

+22
-7
lines changed

cmd/python/missing_entrypoint/main.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -60,13 +60,13 @@ func DetectFn(ctx *gcp.Context) (gcp.DetectResult, error) {
6060

6161
// BuildFn is the exported build function.
6262
func BuildFn(ctx *gcp.Context) error {
63-
hasMain, err := ctx.HasAtLeastOne("main.py")
63+
hasMain, err := ctx.FileExists("main.py")
6464
if err != nil {
65-
return fmt.Errorf("finding main.py files: %w", err)
65+
return fmt.Errorf("finding main.py file: %w", err)
6666
}
67-
hasApp, err := ctx.HasAtLeastOne("app.py")
67+
hasApp, err := ctx.FileExists("app.py")
6868
if err != nil {
69-
return fmt.Errorf("finding app.py files: %w", err)
69+
return fmt.Errorf("finding app.py file: %w", err)
7070
}
7171
if !hasMain && !hasApp {
7272
return fmt.Errorf("for Python, provide a main.py or app.py file or set an entrypoint with %q env var or by creating a %q file", env.Entrypoint, "Procfile")

cmd/python/missing_entrypoint/main_test.go

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,28 +32,36 @@ func TestDetect(t *testing.T) {
3232
want int
3333
}{
3434
{
35-
name: "no py files",
35+
name: "no_py_files",
3636
files: map[string]string{
3737
"index.js": "",
3838
},
3939
want: 100,
4040
},
4141
{
42-
name: "has py file",
42+
name: "has_main_py_file",
4343
files: map[string]string{
4444
"main.py": "",
4545
},
4646
want: 0,
4747
},
4848
{
49-
name: "has multiple py files",
49+
name: "has_multiple_py_files",
5050
files: map[string]string{
5151
"main.py": "",
5252
"app.py": "",
5353
"utils.py": "",
5454
},
5555
want: 0,
5656
},
57+
{
58+
name: "has_multiple_py_files_with_nested_directory",
59+
files: map[string]string{
60+
"folder/main.py": "",
61+
"folder/__init__.py": "",
62+
},
63+
want: 0,
64+
},
5765
}
5866
for _, tc := range testCases {
5967
t.Run(tc.name, func(t *testing.T) {
@@ -369,6 +377,13 @@ func TestBuild(t *testing.T) {
369377
},
370378
wantExitCode: 1,
371379
},
380+
{
381+
name: "main_in_nested_directory",
382+
files: map[string]string{
383+
"folder/main.py": "",
384+
},
385+
wantExitCode: 1,
386+
},
372387
}
373388
for _, tc := range testCases {
374389
t.Run(tc.name, func(t *testing.T) {

0 commit comments

Comments
 (0)