@@ -15,7 +15,11 @@ import (
15
15
)
16
16
17
17
type environment struct {
18
- Dependencies []Dependency `yaml:"dependencies"`
18
+ Entries []Entry `yaml:"dependencies"`
19
+ }
20
+
21
+ type Entry struct {
22
+ Dependencies []Dependency
19
23
}
20
24
21
25
type Dependency struct {
@@ -42,13 +46,15 @@ func (p *Parser) Parse(r xio.ReadSeekerAt) ([]ftypes.Package, []ftypes.Dependenc
42
46
}
43
47
44
48
var pkgs ftypes.Packages
45
- for _ , dep := range env .Dependencies {
46
- pkg := p .toPackage (dep )
47
- // Skip empty pkgs
48
- if pkg .Name == "" {
49
- continue
49
+ for _ , entry := range env .Entries {
50
+ for _ , dep := range entry .Dependencies {
51
+ pkg := p .toPackage (dep )
52
+ // Skip empty pkgs
53
+ if pkg .Name == "" {
54
+ continue
55
+ }
56
+ pkgs = append (pkgs , pkg )
50
57
}
51
- pkgs = append (pkgs , pkg )
52
58
}
53
59
54
60
sort .Sort (pkgs )
@@ -96,8 +102,40 @@ func (*Parser) parseDependency(line string) (string, string) {
96
102
return name , parts [1 ]
97
103
}
98
104
99
- func (d * Dependency ) UnmarshalYAML (node * yaml.Node ) error {
100
- d .Value = node .Value
101
- d .Line = node .Line
105
+ func (e * Entry ) UnmarshalYAML (node * yaml.Node ) error {
106
+ var dependencies []Dependency
107
+ // cf. https://github.com/go-yaml/yaml/blob/f6f7691b1fdeb513f56608cd2c32c51f8194bf51/resolve.go#L70-L81
108
+ switch node .Tag {
109
+ case "!!str" :
110
+ dependencies = append (dependencies , Dependency {
111
+ Value : node .Value ,
112
+ Line : node .Line ,
113
+ })
114
+ case "!!map" :
115
+ if node .Content != nil {
116
+ // Map key is package manager (e.g. pip). So we need to store only map values (dependencies).
117
+ // e.g. dependencies:
118
+ // - pip:
119
+ // - pandas==2.1.4
120
+ if node .Content [1 ].Tag != "!!seq" { // Conda supports only map[string][]string format.
121
+ return xerrors .Errorf ("unsupported dependency type %q on line %d" , node .Content [1 ].Tag , node .Content [1 ].Line )
122
+ }
123
+
124
+ for _ , depContent := range node .Content [1 ].Content {
125
+ if depContent .Tag != "!!str" {
126
+ return xerrors .Errorf ("unsupported dependency type %q on line %d" , depContent .Tag , depContent .Line )
127
+ }
128
+
129
+ dependencies = append (dependencies , Dependency {
130
+ Value : depContent .Value ,
131
+ Line : depContent .Line ,
132
+ })
133
+ }
134
+ }
135
+ default :
136
+ return xerrors .Errorf ("unsupported dependency type %q on line %d" , node .Tag , node .Line )
137
+ }
138
+
139
+ e .Dependencies = dependencies
102
140
return nil
103
141
}
0 commit comments