Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(30)

Unified Diff: vpython/spec/spec.go

Issue 2918623003: [vpython] Verify environment, named installs. (Closed)
Patch Set: Created 3 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « vpython/application/subcommand_verify.go ('k') | vpython/spec/spec_test.go » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: vpython/spec/spec.go
diff --git a/vpython/spec/spec.go b/vpython/spec/spec.go
index 6a52115145436d37fc06d14bb82ad53f5c3767cc..97abe5a416423c0c3168657c87a6ee5f3bb28524 100644
--- a/vpython/spec/spec.go
+++ b/vpython/spec/spec.go
@@ -21,13 +21,27 @@ import (
// Render creates a human-readable string from spec.
func Render(spec *vpython.Spec) string { return proto.MarshalTextString(spec) }
-// Normalize normalizes the specification Message such that two messages
-// with identical meaning will have identical representation.
-func Normalize(spec *vpython.Spec, defaultVENVPackage *vpython.Spec_Package) error {
- if spec.Virtualenv == nil {
- spec.Virtualenv = defaultVENVPackage
+// NormalizeEnvironment normalizes the supplied Environment such that two
+// messages with identical meaning will have identical representation.
+func NormalizeEnvironment(env *vpython.Environment) error {
+ if env.Spec == nil {
+ env.Spec = &vpython.Spec{}
+ }
+ if err := NormalizeSpec(env.Spec); err != nil {
+ return err
+ }
+
+ if env.Runtime == nil {
+ env.Runtime = &vpython.Runtime{}
}
+ sort.Sort(pep425TagSlice(env.Pep425Tag))
+ return nil
+}
+
+// NormalizeSpec normalizes the specification Message such that two messages
+// with identical meaning will have identical representation.
+func NormalizeSpec(spec *vpython.Spec) error {
sort.Sort(specPackageSlice(spec.Wheel))
// No duplicate packages. Since we're sorted, we can just check for no
@@ -87,3 +101,16 @@ func (s specPackageSlice) Less(i, j int) bool {
func(i, j int) bool { return s[i].Version < s[j].Version },
}.Use(i, j)
}
+
+type pep425TagSlice []*vpython.Pep425Tag
+
+func (s pep425TagSlice) Len() int { return len(s) }
+func (s pep425TagSlice) Swap(i, j int) { s[i], s[j] = s[j], s[i] }
+
+func (s pep425TagSlice) Less(i, j int) bool {
+ return sortby.Chain{
+ func(i, j int) bool { return s[i].Version < s[j].Version },
+ func(i, j int) bool { return s[i].Abi < s[j].Abi },
+ func(i, j int) bool { return s[i].Arch < s[j].Arch },
+ }.Use(i, j)
+}
« no previous file with comments | « vpython/application/subcommand_verify.go ('k') | vpython/spec/spec_test.go » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698