refactor(python): install python versions to runtimes/python

This commit is contained in:
Marc 2024-01-28 22:25:24 -05:00
parent d039bb5d4c
commit d9cb6a07ce
Signed by: marc
GPG key ID: 048E042F22B5DC79
6 changed files with 19 additions and 16 deletions

View file

@ -9,7 +9,7 @@ import (
)
func uninstallPython(args []string, flags cli.Flags, currentState state.State) error {
runtimePath := state.GetStatePath("runtimes", "py-"+args[1])
runtimePath := state.GetStatePath("runtimes", "python", args[1])
err := os.RemoveAll(runtimePath)
return err
}
@ -79,7 +79,7 @@ func which(args []string, flags cli.Flags, currentState state.State) error {
printedPath = sysPath + " (system)"
} else if isInstalled {
tag := VersionStringToStruct(selectedVersion.Version)
printedPath = state.GetStatePath("runtimes", "py-"+selectedVersion.Version, "bin", "python"+tag.MajorMinor())
printedPath = state.GetStatePath("runtimes", "python", selectedVersion.Version, "bin", "python"+tag.MajorMinor())
} else {
logger.InfoLogger.Printf("The desired version (%s) is not installed.\n", selectedVersion.Version)
return nil

View file

@ -14,7 +14,7 @@ import (
func TestListVersionOutputsNoticeIfNoVersionsInstalled(t *testing.T) {
defer testutils.SetupAndCleanupEnvironment(t)()
os.Mkdir(state.GetStatePath("runtimes"), 0750)
os.MkdirAll(state.GetStatePath("runtimes", "python"), 0750)
var out bytes.Buffer
logger.InfoLogger.SetOutput(&out)
@ -31,7 +31,7 @@ func TestListVersionOutputsNoticeIfNoVersionsInstalled(t *testing.T) {
func TestListVersionOutputsVersionsInstalled(t *testing.T) {
defer testutils.SetupAndCleanupEnvironment(t)()
os.MkdirAll(state.GetStatePath("runtimes", "py-1.2.3"), 0750)
os.MkdirAll(state.GetStatePath("runtimes", "python", "1.2.3"), 0750)
var out bytes.Buffer
logger.InfoLogger.SetOutput(&out)
@ -89,11 +89,11 @@ func TestWhichOutputsVersionSelectedIfInstalled(t *testing.T) {
logger.InfoLogger.SetOutput(&out)
defer logger.InfoLogger.SetOutput(os.Stdout)
os.MkdirAll(state.GetStatePath("runtimes", "py-1.2.3"), 0750)
os.MkdirAll(state.GetStatePath("runtimes", "python", "1.2.3"), 0750)
which([]string{}, cli.Flags{}, state.State{GlobalVersion: "1.2.3"})
captured := strings.TrimSpace(out.String())
expected := state.GetStatePath("runtimes", "py-1.2.3", "bin", "python1.2")
expected := state.GetStatePath("runtimes", "python", "1.2.3", "bin", "python1.2")
if !strings.Contains(captured, expected) {
t.Errorf("Unexpected message: %s, not %s", captured, expected)
}
@ -124,11 +124,11 @@ func TestWhichOutputsVersionWithoutPrefixesIfRawOutput(t *testing.T) {
logger.InfoLogger.SetOutput(&out)
defer logger.InfoLogger.SetOutput(os.Stdout)
os.MkdirAll(state.GetStatePath("runtimes", "py-1.2.3"), 0750)
os.MkdirAll(state.GetStatePath("runtimes", "python", "1.2.3"), 0750)
which([]string{}, cli.Flags{RawOutput: true}, state.State{GlobalVersion: "1.2.3"})
captured := strings.TrimSpace(out.String())
expected := state.GetStatePath("runtimes", "py-1.2.3", "bin", "python1.2")
expected := state.GetStatePath("runtimes", "python", "1.2.3", "bin", "python1.2")
if captured != expected {
t.Errorf("Unexpected message: %s, not %s", captured, expected)
}

View file

@ -107,7 +107,11 @@ func buildFromSource(pkgMeta PackageMetadata, verbose bool) (PackageMetadata, er
logger.InfoLogger.Println("Configuring installer")
targetDirectory := state.GetStatePath("runtimes", "py-"+pkgMeta.Version)
if _, err := os.Stat(state.GetStatePath("runtimes", "python")); os.IsNotExist(err) {
os.Mkdir(state.GetStatePath("runtimes", "python"), 0775)
}
targetDirectory := state.GetStatePath("runtimes", "python", pkgMeta.Version)
_, configureErr := exec.RunCommand([]string{"./configure", "--prefix=" + targetDirectory, "--enable-optimizations"}, unzippedRoot, !verbose)

View file

@ -30,7 +30,7 @@ type SelectedVersion struct {
}
func ListInstalledVersions() ([]string, error) {
runtimesDir := state.GetStatePath("runtimes")
runtimesDir := state.GetStatePath("runtimes", "python")
entries, err := os.ReadDir(runtimesDir)
if err != nil {
@ -40,7 +40,7 @@ func ListInstalledVersions() ([]string, error) {
installedVersions := []string{}
for _, d := range entries {
installedVersions = append(installedVersions, strings.TrimPrefix(d.Name(), "py-"))
installedVersions = append(installedVersions, d.Name())
}
return installedVersions, nil

View file

@ -127,7 +127,7 @@ func TestListInstalledVersion(t *testing.T) {
os.Mkdir(state.GetStatePath("runtimes"), 0750)
for _, version := range versions {
os.Mkdir(state.GetStatePath("runtimes", "py-"+version), 0750)
os.MkdirAll(state.GetStatePath("runtimes", "python", version), 0750)
}
installedVersions, _ := ListInstalledVersions()
@ -140,7 +140,7 @@ func TestListInstalledVersion(t *testing.T) {
func TestListInstalledVersionNoVersionsInstalled(t *testing.T) {
defer testutils.SetupAndCleanupEnvironment(t)()
os.Mkdir(state.GetStatePath("runtimes"), 0750)
os.MkdirAll(state.GetStatePath("runtimes", "python"), 0750)
installedVersions, _ := ListInstalledVersions()

View file

@ -5,7 +5,6 @@ import (
"io/ioutil"
"os"
"path"
"strings"
)
// Persistent state used by the CLI to track runtime information
@ -46,12 +45,12 @@ func WriteState(version string) {
}
func GetAvailableVersions() []string {
entries, _ := os.ReadDir(GetStatePath("runtimes"))
entries, _ := os.ReadDir(GetStatePath("runtimes", "python"))
versions := []string{}
for _, d := range entries {
versions = append(versions, strings.TrimPrefix(d.Name(), "py-"))
versions = append(versions, d.Name())
}
return versions