From a040336c5e3c4430380aa0b758e527015604a117 Mon Sep 17 00:00:00 2001 From: Devon Stewart Date: Thu, 15 Feb 2024 13:47:59 -0800 Subject: [PATCH] [bug] If packageDir does not exist, run Install (#235) * If packageDir does not exist, run Install * Also consider PYTHONUSERBASE in GetPackageDir * upm show-package-dir should show the root, not site-packages --- internal/backends/python/python.go | 12 +++++++++++- internal/cli/cmds.go | 6 +++++- 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/internal/backends/python/python.go b/internal/backends/python/python.go index 7df1f080..bd089a4a 100644 --- a/internal/backends/python/python.go +++ b/internal/backends/python/python.go @@ -284,6 +284,11 @@ func makePythonPoetryBackend(python string) api.LanguageBackend { return venv } + // Take PYTHONUSERBASE into consideration, if set + if userbase := os.Getenv("PYTHONUSERBASE"); userbase != "" { + return userbase + } + // Terminate early if we're running inside a repl. // This will suppress the following poetry commands // from showing up in the Packager pane. @@ -417,9 +422,14 @@ func makePythonPipBackend(python string) api.LanguageBackend { return venv } + // Take PYTHONUSERBASE into consideration, if set + if userbase := os.Getenv("PYTHONUSERBASE"); userbase != "" { + return userbase + } + if outputB, err := util.GetCmdOutputFallible([]string{ "python", - "-c", "import site; print(site.USER_SITE)", + "-c", "import site; print(site.USER_BASE)", }); err == nil { return string(outputB) } diff --git a/internal/cli/cmds.go b/internal/cli/cmds.go index de10c8bf..338333dd 100644 --- a/internal/cli/cmds.go +++ b/internal/cli/cmds.go @@ -247,7 +247,11 @@ func maybeInstall(ctx context.Context, b api.LanguageBackend, forceInstall bool) if !util.Exists(b.Specfile) { return } - if forceInstall || store.HasSpecfileChanged(b) { + var needsPackageDir bool + if packageDir := b.GetPackageDir(); packageDir != "" { + needsPackageDir = !util.Exists(packageDir) + } + if forceInstall || store.HasSpecfileChanged(b) || needsPackageDir { b.Install(ctx) } }