MCPcopy Index your code
hub / github.com/celer-pkg/celer / pip3Install

Function pip3Install

buildtools/setup_python.go:23–101  ·  view source on GitHub ↗
(ctx context.Context, pipConfig context.PythonConfig, libraries *[]string)

Source from the content-addressed store, hash-verified

21var PythonTool *pythonTool
22
23func pip3Install(ctx context.Context, pipConfig context.PythonConfig, libraries *[]string) error {
24 // Get python version from project config if available, otherwise use default version.
25 pythonVersion := GetDefaultPythonVersion()
26 pythonConfig := ctx.PythonConfig()
27 if pythonConfig != nil && pythonConfig.GetVersion() != "" {
28 pythonVersion = pythonConfig.GetVersion()
29 }
30 venvDir := getPythonVenvPath(pythonVersion, ctx.Project().GetName())
31
32 // Setup python3 using conda.
33 if err := setupPython(ctx, pythonVersion); err != nil {
34 return fmt.Errorf("failed to setup python3 -> %w", err)
35 }
36
37 // Install extra tools. Check if package is already installed in PYTHONUSERBASE to avoid frequent PyPI requests.
38 // PYTHONUSERBASE is already set globally, so pip will install to workspace directory.
39 for _, library := range *libraries {
40 if !strings.HasPrefix(library, "python3:") {
41 continue
42 }
43
44 // Format python3 library name version.
45 nameVersion := strings.TrimPrefix(library, "python3:")
46 nameVersion = strings.ReplaceAll(nameVersion, "@", "==")
47
48 // Check if package is already installed in PYTHONUSERBASE to avoid frequent PyPI requests.
49 if isPackageInstalled(nameVersion, venvDir) {
50 continue
51 }
52
53 // Build pip install command with PyPI source configuration.
54 var builder strings.Builder
55
56 // If Python needs LD_LIBRARY_PATH, prepend it to the command.
57 if PythonTool.ldLibraryPath != "" {
58 fmt.Fprintf(&builder, "LD_LIBRARY_PATH=%s ", PythonTool.ldLibraryPath)
59 }
60
61 builder.WriteString(PythonTool.Path)
62 builder.WriteString(" -m pip install")
63
64 // Add PyPI source configuration if available.
65 if pipConfig != nil {
66 if indexUrl := pipConfig.GetIndexUrl(); indexUrl != "" {
67 builder.WriteString(" -i ")
68 builder.WriteString(indexUrl)
69 }
70 for _, extraUrl := range pipConfig.GetExtraIndexUrls() {
71 builder.WriteString(" --extra-index-url ")
72 builder.WriteString(extraUrl)
73 }
74 for _, host := range pipConfig.GetTrustedHosts() {
75 builder.WriteString(" --trusted-host ")
76 builder.WriteString(host)
77 }
78 }
79
80 builder.WriteString(" ")

Callers 1

CheckToolsFunction · 0.85

Calls 15

NewExecutorFunction · 0.92
AppendPythonBinDirFunction · 0.92
GetDefaultPythonVersionFunction · 0.85
getPythonVenvPathFunction · 0.85
setupPythonFunction · 0.85
isPackageInstalledFunction · 0.85
SprintfMethod · 0.80
ExecuteMethod · 0.80
PythonConfigMethod · 0.65
GetVersionMethod · 0.65
GetNameMethod · 0.65
ProjectMethod · 0.65

Tested by

no test coverage detected