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

Unified Diff: vpython/python/interpreter.go

Issue 2925723004: [vpython] Implement smart probing. (Closed)
Patch Set: sentinel text Created 3 years, 6 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/python/find.go ('k') | vpython/venv/config.go » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: vpython/python/interpreter.go
diff --git a/vpython/python/interpreter.go b/vpython/python/interpreter.go
index f3326cf36c4a33d0fac7046f4396b995999712f9..bc8e5f7048d56d4968b9d325d959a72ca3f155a4 100644
--- a/vpython/python/interpreter.go
+++ b/vpython/python/interpreter.go
@@ -20,8 +20,6 @@ import (
"golang.org/x/net/context"
)
-type runnerFunc func(cmd *exec.Cmd, capture bool) (string, error)
-
// Interpreter represents a system Python interpreter. It exposes the ability
// to use common functionality of that interpreter.
type Interpreter struct {
@@ -104,8 +102,7 @@ func (i *Interpreter) GetVersion(c context.Context) (v Version, err error) {
return
}
- if v, err = parseVersionOutput(strings.TrimSpace(string(out))); err != nil {
- err = errors.Annotate(err).Err()
+ if v, err = ParseVersionOutput(string(out)); err != nil {
return
}
@@ -141,13 +138,17 @@ func (i *Interpreter) Hash() (string, error) {
return i.cachedHash, i.cachedHashErr
}
-func parseVersionOutput(output string) (Version, error) {
+// ParseVersionOutput parses a Version out of the output of a "--version" Python
+// invocation.
+func ParseVersionOutput(output string) (Version, error) {
+ s := strings.TrimSpace(string(output))
+
// Expected output:
// Python X.Y.Z
- parts := strings.SplitN(output, " ", 2)
+ parts := strings.SplitN(s, " ", 2)
if len(parts) != 2 || parts[0] != "Python" {
return Version{}, errors.Reason("unknown version output").
- D("output", output).
+ D("output", s).
Err()
}
« no previous file with comments | « vpython/python/find.go ('k') | vpython/venv/config.go » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698