MCPcopy Create free account
hub / github.com/GoogleCloudPlatform/buildpacks / GetScriptCommand

Function GetScriptCommand

pkg/python/pyproject.go:487–531  ·  view source on GitHub ↗

GetScriptCommand returns the script command from pyproject.toml if it exists.

(ctx *gcp.Context)

Source from the content-addressed store, hash-verified

485 }
486
487 var parsedTOML struct {
488 Project struct {
489 Scripts map[string]string `toml:"scripts"`
490 } `toml:"project"`
491 Tool struct {
492 Poetry struct {
493 Scripts map[string]string `toml:"scripts"`
494 } `toml:"poetry"`
495 } `toml:"tool"`
496 }
497 if _, err := toml.Decode(string(pyprojectTomlContent), &parsedTOML); err != nil {
498 ctx.Warnf("Could not parse %s: %v", pyprojectToml, err)
499 return nil, nil
500 }
501
502 if len(parsedTOML.Tool.Poetry.Scripts) > 0 {
503 if len(parsedTOML.Tool.Poetry.Scripts) == 1 {
504 for scriptName := range parsedTOML.Tool.Poetry.Scripts {
505 return []string{scriptName}, nil
506 }
507 }
508 if parsedTOML.Tool.Poetry.Scripts["start"] != "" {
509 return []string{"start"}, nil
510 }
511 }
512
513 if len(parsedTOML.Project.Scripts) > 0 {
514 if len(parsedTOML.Project.Scripts) == 1 {
515 for scriptName := range parsedTOML.Project.Scripts {
516 return []string{scriptName}, nil
517 }
518 }
519 if parsedTOML.Project.Scripts["start"] != "" {
520 return []string{"start"}, nil
521 }
522 }
523
524 return nil, nil
525}
526
527// IsPyprojectEnabled checks if the pyproject feature is enabled.
528func IsPyprojectEnabled(ctx *gcp.Context) bool {
529 pyprojectTomlExists, _ := ctx.FileExists(pyprojectToml)
530 if !pyprojectTomlExists {
531 return false
532 }
533 if isBothPyprojectAndRequirementsPresent(ctx) {
534 return false // Prefer requirements.txt over pyproject.toml.

Callers 2

BuildFnFunction · 0.92
TestGetScriptCommandFunction · 0.85

Calls 2

ReadFileMethod · 0.80
WarnfMethod · 0.80

Tested by 1

TestGetScriptCommandFunction · 0.68