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

Function installRequirementsToTarget

pkg/python/python.go:759–789  ·  view source on GitHub ↗
(ctx *gcp.Context, targetPath string, reqs []string, cmdBuilder func(string) []string)

Source from the content-addressed store, hash-verified

757 content, err := os.ReadFile(req)
758 if err != nil {
759 return fmt.Errorf("failed to read requirements file %q: %w", req, err)
760 }
761 if _, err := destFile.Write(content); err != nil {
762 return fmt.Errorf("failed to write to destination file: %w", err)
763 }
764 // Add a newline to ensure files are separated correctly
765 if _, err := destFile.Write([]byte("\n")); err != nil {
766 return err
767 }
768 }
769 return nil
770}
771
772func installRequirementsToTarget(ctx *gcp.Context, targetPath string, reqs []string, cmdBuilder func(string) []string) error {
773 if len(reqs) == 0 {
774 return nil
775 }
776
777 reqFile := reqs[0]
778
779 if len(reqs) > 1 {
780 // Create a temporary file to merge all requirements
781 tmpFile, err := os.CreateTemp("", "merged_requirements_*.txt")
782 if err != nil {
783 return fmt.Errorf("failed to create temp file for requirements: %w", err)
784 }
785 tmpFile.Close()
786 defer os.Remove(tmpFile.Name())
787
788 if err := mergeRequirementsFiles(reqs, tmpFile.Name()); err != nil {
789 return err
790 }
791 reqFile = tmpFile.Name()
792 }

Callers 1

Calls 3

mergeRequirementsFilesFunction · 0.85
NameMethod · 0.80
ExecMethod · 0.80

Tested by

no test coverage detected