Skip to content

Commit

Permalink
[bug] If packageDir does not exist, run Install (#235)
Browse files Browse the repository at this point in the history
* If packageDir does not exist, run Install

* Also consider PYTHONUSERBASE in GetPackageDir

* upm show-package-dir should show the root, not site-packages
  • Loading branch information
blast-hardcheese authored Feb 15, 2024
1 parent f33424b commit a040336
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
12 changes: 11 additions & 1 deletion internal/backends/python/python.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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)
}
Expand Down
6 changes: 5 additions & 1 deletion internal/cli/cmds.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}
Expand Down

0 comments on commit a040336

Please sign in to comment.