Skip to content

Commit

Permalink
fix: flatten pypi packages in the label (#1302)
Browse files Browse the repository at this point in the history
* fix: flatten pypi packages in the label

Signed-off-by: Keming <kemingyang@tensorchord.ai>

* delete the fitler for pypi commands

Signed-off-by: Keming <kemingyang@tensorchord.ai>

Signed-off-by: Keming <kemingyang@tensorchord.ai>
  • Loading branch information
kemingy committed Dec 14, 2022
1 parent 0a416d1 commit 1cc8c48
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 51 deletions.
6 changes: 5 additions & 1 deletion pkg/lang/ir/v0/compile.go
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,11 @@ func (g generalGraph) Labels() (map[string]string, error) {
return nil, err
}
labels[types.ImageLabelAPT] = string(str)
str, err = json.Marshal(g.PyPIPackages)
pyPackages := []string{}
for _, pkg := range g.PyPIPackages {
pyPackages = append(pyPackages, pkg...)
}
str, err = json.Marshal(pyPackages)
if err != nil {
return nil, err
}
Expand Down
6 changes: 5 additions & 1 deletion pkg/lang/ir/v1/compile.go
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,11 @@ func (g generalGraph) Labels() (map[string]string, error) {
return nil, err
}
labels[types.ImageLabelAPT] = string(str)
str, err = json.Marshal(g.PyPIPackages)
pyPackages := []string{}
for _, pkg := range g.PyPIPackages {
pyPackages = append(pyPackages, pkg...)
}
str, err = json.Marshal(pyPackages)
if err != nil {
return nil, err
}
Expand Down
18 changes: 4 additions & 14 deletions pkg/types/envd.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ package types
import (
"encoding/json"
"fmt"
"strings"

"github.com/docker/docker/api/types"
"github.com/moby/buildkit/util/system"
Expand Down Expand Up @@ -315,20 +314,11 @@ func NewDependencyFromLabels(label map[string]string) (*Dependency, error) {
dep.APTPackages = lst
}
if pypiCommands, ok := label[ImageLabelPyPI]; ok {
lst, err := parsePyPICommands(pypiCommands)
pkgs, err := parsePyPICommands(pypiCommands)
if err != nil {
return nil, err
}
packages := []string{}

for _, pkgs := range lst {
for i, pkg := range pkgs {
if !strings.HasPrefix(pkg, "-") && (i == 0 || !strings.HasPrefix(pkgs[i-1], "-")) {
packages = append(packages, pkg)
}
}
}
dep.PyPIPackages = packages
dep.PyPIPackages = pkgs
}
return &dep, nil
}
Expand All @@ -339,8 +329,8 @@ func parseAPTPackages(lst string) ([]string, error) {
return pkgs, err
}

func parsePyPICommands(lst string) ([][]string, error) {
var pkgs [][]string
func parsePyPICommands(lst string) ([]string, error) {
var pkgs []string
err := json.Unmarshal([]byte(lst), &pkgs)
return pkgs, err
}
Expand Down
35 changes: 0 additions & 35 deletions pkg/types/envd_test.go

This file was deleted.

0 comments on commit 1cc8c48

Please sign in to comment.