File tree Expand file tree Collapse file tree 3 files changed +28
-4
lines changed Expand file tree Collapse file tree 3 files changed +28
-4
lines changed Original file line number Diff line number Diff line change @@ -5,7 +5,10 @@ go_library(
5
5
srcs = ["manifest.go" ],
6
6
importpath = "github.com/bazelbuild/rules_python/gazelle/manifest" ,
7
7
visibility = ["//visibility:public" ],
8
- deps = ["@in_gopkg_yaml_v2//:yaml_v2" ],
8
+ deps = [
9
+ "@com_github_emirpasic_gods//sets/treeset" ,
10
+ "@in_gopkg_yaml_v2//:yaml_v2" ,
11
+ ],
9
12
)
10
13
11
14
go_test (
Original file line number Diff line number Diff line change 6
6
"io"
7
7
"os"
8
8
9
+ "github.com/emirpasic/gods/sets/treeset"
10
+
9
11
yaml "gopkg.in/yaml.v2"
10
12
)
11
13
@@ -94,11 +96,30 @@ func (f *File) Decode(manifestPath string) error {
94
96
return nil
95
97
}
96
98
99
+ // ModulesMapping is the type used to map from importable Python modules to
100
+ // the wheel names that provide these modules.
101
+ type ModulesMapping map [string ]string
102
+
103
+ // MarshalYAML makes sure that we sort the module names before marshaling
104
+ // the contents of `ModulesMapping` to a YAML file. This ensures that the
105
+ // file is deterministically generated from the map.
106
+ func (m ModulesMapping ) MarshalYAML () (interface {}, error ) {
107
+ var mapslice yaml.MapSlice
108
+ keySet := treeset .NewWithStringComparator ()
109
+ for key := range m {
110
+ keySet .Add (key )
111
+ }
112
+ for _ , key := range keySet .Values () {
113
+ mapslice = append (mapslice , yaml.MapItem {Key : key , Value : m [key .(string )]})
114
+ }
115
+ return mapslice , nil
116
+ }
117
+
97
118
// Manifest represents the structure of the Gazelle manifest file.
98
119
type Manifest struct {
99
120
// ModulesMapping is the mapping from importable modules to which Python
100
121
// wheel name provides these modules.
101
- ModulesMapping map [ string ] string `yaml:"modules_mapping"`
122
+ ModulesMapping ModulesMapping `yaml:"modules_mapping"`
102
123
// PipDepsRepositoryName is the name of the pip_install repository target.
103
124
// DEPRECATED
104
125
PipDepsRepositoryName string `yaml:"pip_deps_repository_name,omitempty"`
Original file line number Diff line number Diff line change @@ -10,7 +10,7 @@ import (
10
10
"github.com/bazelbuild/rules_python/gazelle/manifest"
11
11
)
12
12
13
- var modulesMapping = map [ string ] string {
13
+ var modulesMapping = manifest. ModulesMapping {
14
14
"arrow" : "arrow" ,
15
15
"arrow.__init__" : "arrow" ,
16
16
"arrow.api" : "arrow" ,
@@ -76,4 +76,4 @@ func TestFile(t *testing.T) {
76
76
t .FailNow ()
77
77
}
78
78
})
79
- }
79
+ }
You can’t perform that action at this time.
0 commit comments