Skip to content

Commit

Permalink
fix version issue python
Browse files Browse the repository at this point in the history
  • Loading branch information
vineelsai26 committed Apr 27, 2024
1 parent a490a9c commit 2628eab
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 7 deletions.
11 changes: 6 additions & 5 deletions src/python/install.go
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,8 @@ func installPythonFromSource(version string, compile_flags_override string) (str
}

func installPython(version string) (string, error) {
fullURLFile := "https://repo.vineelsai.com/" + runtime.GOOS + "/generic/" + runtime.GOARCH + "/python-" + strings.TrimPrefix(version, "v") + ".tar.gz"
version = strings.TrimPrefix(version, "v")
fullURLFile := "https://repo.vineelsai.com/" + runtime.GOOS + "/generic/" + runtime.GOARCH + "/python-" + version + ".tar.gz"
downloadDir := filepath.Join(utils.GetHome(), ".cache", "vmn")
downloadedFilePath := filepath.Join(downloadDir, strings.Split(fullURLFile, "/")[len(strings.Split(fullURLFile, "/"))-1])

Expand All @@ -135,11 +136,11 @@ func installPython(version string) (string, error) {
// Unzip file
fmt.Println("Installing Python version " + version + "...")
if strings.HasSuffix(fileName, ".zip") {
if err := utils.Unzip(downloadedFilePath, utils.GetDestination(version, "python")); err != nil {
if err := utils.Unzip(downloadedFilePath, utils.GetDestination("v"+version, "python")); err != nil {
return "", err
}
} else if strings.HasSuffix(fileName, ".tar.gz") {
if err := utils.UnGzip(downloadedFilePath, utils.GetDestination(version, "python"), true); err != nil {
if err := utils.UnGzip(downloadedFilePath, utils.GetDestination("v"+version, "python"), true); err != nil {
return "", err
}
}
Expand Down Expand Up @@ -168,9 +169,9 @@ func Install(version string, compile bool, compile_flags_override string) (strin
} else if len(strings.Split(version, ".")) == 3 {
version = "v" + version
} else if len(strings.Split(version, ".")) == 2 {
version = GetLatestVersionOfVersion(strings.Split(version, ".")[0], strings.Split(version, ".")[1])
version = "v" + GetLatestVersionOfVersion(strings.Split(version, ".")[0], strings.Split(version, ".")[1])
} else if len(strings.Split(version, ".")) == 1 {
version = GetLatestVersionOfVersion(version, "")
version = "v" + GetLatestVersionOfVersion(version, "")
} else {
return "", fmt.Errorf("invalid version")
}
Expand Down
3 changes: 2 additions & 1 deletion src/python/uninstall.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,12 @@ import (
)

func uninstallVersion(version string) (string, error) {
version = strings.TrimPrefix(version, "v")
if !utils.IsInstalled(version, "python") {
return "", fmt.Errorf("Python version " + version + " is not installed")
}
fmt.Printf("Uninstalling Python %s\n", version)
path := utils.GetDestination(version, "python")
path := utils.GetDestination("v"+version, "python")
if err := os.RemoveAll(strings.TrimSpace(path)); err != nil {
exec.Command("bash", "-c", "rm -rf "+path).Run()
}
Expand Down
3 changes: 2 additions & 1 deletion src/utils/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ func GetCPUCount() int {
}

func GetDestination(version string, pl string) string {
return filepath.Join(GetHome(), ".vmn", pl, version)
version = strings.TrimPrefix(version, "v")
return filepath.Join(GetHome(), ".vmn", pl, "v"+version)
}

func GetVersionPath(version string, pl string) (string, error) {
Expand Down

0 comments on commit 2628eab

Please sign in to comment.