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

Side by Side Diff: vpython/python/find.go

Issue 2701073002: vpython: Add Python interpreter handling package. (Closed)
Patch Set: Created 3 years, 10 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 unified diff | Download patch
« no previous file with comments | « no previous file | vpython/python/interpreter.go » ('j') | vpython/python/interpreter.go » ('J')
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright 2017 The LUCI Authors. All rights reserved.
2 // Use of this source code is governed under the Apache License, Version 2.0
3 // that can be found in the LICENSE file.
4
5 package python
6
7 import (
8 "os/exec"
9
10 "github.com/luci/luci-go/common/errors"
11
12 "golang.org/x/net/context"
13 )
14
15 // Find attempts to find a Python interpreter matching the supplied version
16 // using PATH.
17 //
18 // In order to accommodate multiple configurations on operating systems, Find
19 // will attempt to identify versions that appear on the path
20 func Find(c context.Context, vers Version) (*Interpreter, error) {
21 // pythonM.m, pythonM, python
22 searches := make([]string, 0, 3)
23 pv := vers
24 pv.Patch = 0
25 if pv.Minor > 0 {
26 searches = append(searches, pv.PythonBase())
27 pv.Minor = 0
28 }
29 if pv.Major > 0 {
30 searches = append(searches, pv.PythonBase())
31 pv.Major = 0
32 }
33 searches = append(searches, pv.PythonBase())
34
35 for _, s := range searches {
36 p, err := exec.LookPath(s)
37 if err != nil {
38 if e, ok := err.(*exec.Error); ok && e.Err == exec.ErrNo tFound {
39 // Not found is okay.
40 continue
41 }
42 return nil, errors.Annotate(err).Reason("failed to searc h PATH for: %(interp)q").
43 D("interp", s).
44 Err()
45 }
46
47 i := Interpreter{
48 Python: p,
49 Isolated: true,
50 }
51 iv, err := i.GetVersion(c)
52 if err != nil {
53 return nil, errors.Annotate(err).Reason("failed to get v eriso for: %(interp)q").
iannucci 2017/02/21 10:08:16 versio
dnj 2017/02/21 23:21:35 Vers I/O
54 D("interp", p).
55 Err()
56 }
57 if vers.IsSatisfiedBy(iv) {
58 return &i, nil
59 }
60 }
61
62 return nil, errors.New("no Python found")
63 }
OLDNEW
« no previous file with comments | « no previous file | vpython/python/interpreter.go » ('j') | vpython/python/interpreter.go » ('J')

Powered by Google App Engine
This is Rietveld 408576698