(ctx context.Context, pipConfig context.PythonConfig, libraries *[]string)
| 21 | var PythonTool *pythonTool |
| 22 | |
| 23 | func 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(" ") |
no test coverage detected