Skip to content

Commit

Permalink
feat: handle library only pip packages
Browse files Browse the repository at this point in the history
  • Loading branch information
femnad committed May 15, 2024
1 parent bc2ecaf commit 19fe654
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 8 deletions.
3 changes: 2 additions & 1 deletion entity/python.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,10 @@ import (

type PythonPkg struct {
unless.BasicUnlessable
BinLinks []string `yaml:"link"`
Library bool `yaml:"library"`
Pkg string `yaml:"name"`
Reqs []string `yaml:"reqs"`
BinLinks []string `yaml:"link"`
Unless unless.Unless `yaml:"unless"`
Version string `yaml:"version"`
VersionLookup VersionLookupSpec `yaml:"version_lookup"`
Expand Down
22 changes: 15 additions & 7 deletions provision/python.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,26 +29,34 @@ func pipInstall(pipBin, pkg, version string) error {
}

func pythonInstall(pkg entity.PythonPkg, cfg entity.Config) error {
name := pkg.Name()
baseDir := internal.ExpandUser(cfg.Settings.VirtualEnvDir)
venvDir := path.Join(baseDir, name)
venvPip := path.Join(venvDir, "bin", "pip")

if pkg.Library {
pkg.Unless = unless.Unless{
Cmd: fmt.Sprintf("%s show %s", venvPip, name),
}
if pkg.GetVersion() != "" {
pkg.Unless.Post = `head 1 | splitBy ": " -1`
}
}

if unless.ShouldSkip(pkg, cfg.Settings) {
internal.Log.Debugf("skipping pip install for %s", pkg.Name())
return nil
}

internal.Log.Infof("Installing Python package %s", pkg.Name())

name := pkg.Name()
baseDir := internal.ExpandUser(cfg.Settings.VirtualEnvDir)
venvDir := path.Join(baseDir, name)

cmd := fmt.Sprintf("virtualenv %s", venvDir)
err := marecmd.RunErrOnly(marecmd.Input{Command: cmd})
if err != nil {
internal.Log.Errorf("error creating virtualenv for package %s: %v", name, err)
return err
}

venvPip := path.Join(venvDir, "bin", "pip")

version, err := pkg.LookupVersion(cfg.Settings)
if err != nil {
return err
Expand All @@ -71,7 +79,7 @@ func pythonInstall(pkg entity.PythonPkg, cfg entity.Config) error {
home := os.Getenv("HOME")
homeBin := path.Join(home, "bin")

if len(pkg.BinLinks) == 0 {
if len(pkg.BinLinks) == 0 && !pkg.Library {
pkg.BinLinks = []string{pkg.Name()}
}
for _, link := range pkg.BinLinks {
Expand Down

0 comments on commit 19fe654

Please sign in to comment.