github.com/ddev/ddev@v1.23.2-0.20240519125000-d824ffe36ff3/pkg/ddevapp/python.go (about) 1 package ddevapp 2 3 import ( 4 "github.com/ddev/ddev/pkg/fileutil" 5 "github.com/ddev/ddev/pkg/nodeps" 6 "github.com/ddev/ddev/pkg/util" 7 "os" 8 "path/filepath" 9 ) 10 11 // isPythonApp returns true if the app is otherwise indeterminate Python 12 func isPythonApp(app *DdevApp) bool { 13 docroot := filepath.Join(app.AppRoot, app.Docroot) 14 // Don't trigger on django4 15 if fileutil.FileExists(filepath.Join(docroot, "manage.py")) { 16 return false 17 } 18 19 files, err := os.ReadDir(docroot) 20 if err != nil { 21 return false 22 } 23 24 // If there are .py files in the docroot, assume Python type 25 for _, file := range files { 26 if !file.IsDir() && filepath.Ext(file.Name()) == ".py" { 27 return true 28 } 29 } 30 return false 31 } 32 33 // pythonConfigOverrideAction sets up webserverType and anything else 34 // we might need for generic Python. 35 func pythonConfigOverrideAction(app *DdevApp) error { 36 if app.WebserverType == nodeps.WebserverDefault { 37 app.WebserverType = nodeps.WebserverNginxGunicorn 38 } 39 if app.Database == DatabaseDefault { 40 app.Database.Type = nodeps.Postgres 41 app.Database.Version = nodeps.Postgres14 42 } 43 return nil 44 } 45 46 // pythonPostConfigAction reminds people that they may need WSGI_APP env var 47 func pythonPostConfigAction(_ *DdevApp) error { 48 util.Warning("Your project may need a WSGI_APP environment variable to work correctly") 49 return nil 50 }