MCPcopy Create free account
hub / github.com/TykTechnologies/tyk / FindPythonConfig

Function FindPythonConfig

dlpython/main.go:43–125  ·  view source on GitHub ↗

FindPythonConfig scans PATH for common python-config locations.

(customVersion string)

Source from the content-addressed store, hash-verified

41
42// FindPythonConfig scans PATH for common python-config locations.
43func FindPythonConfig(customVersion string) (selectedVersion string, err error) {
44 logger.Debugf("Requested python version: %q", customVersion)
45
46 // Not sure if this can be replaced with os.LookPath:
47 if paths == "" {
48 return selectedVersion, errEmptyPath
49 }
50
51 // Scan python-config binaries:
52 pythonConfigBinaries := map[string]string{}
53
54 for _, p := range strings.Split(paths, ":") {
55 if !strings.HasSuffix(p, "/bin") {
56 continue
57 }
58 files, err := ioutil.ReadDir(p)
59 if err != nil {
60 continue
61 }
62 for _, f := range files {
63 name := f.Name()
64 fullPath := filepath.Join(p, name)
65 matches := pythonExpr.FindAllStringSubmatch(name, -1)
66 if len(matches) == 0 {
67 continue
68 }
69
70 minorVersion := matches[0][3]
71 pyMallocBuild := matches[0][4]
72 isConfig := matches[0][5]
73 version := "3"
74 if minorVersion != "" {
75 version += "." + minorVersion
76 }
77 if pyMallocBuild != "" {
78 version += pyMallocBuild
79 }
80
81 if isConfig == "" {
82 continue
83 }
84
85 if _, exists := pythonConfigBinaries[version]; !exists {
86 pythonConfigBinaries[version] = fullPath
87 }
88 }
89 }
90
91 if len(pythonConfigBinaries) == 0 {
92 return selectedVersion, errors.New("No Python installations found")
93 }
94
95 for ver, binPath := range pythonConfigBinaries {
96 logger.Debugf("Found python-config binary: %s (%s)", ver, binPath)
97 }
98
99 if customVersion == "" {
100 var availableVersions []string

Callers 2

TestFindPythonConfigFunction · 0.85
TestInitFunction · 0.85

Calls 6

selectLatestVersionFunction · 0.85
getLibraryPathFromCfgFunction · 0.85
SplitMethod · 0.80
NameMethod · 0.65
DebugMethod · 0.65
FindAllStringSubmatchMethod · 0.45

Tested by 2

TestFindPythonConfigFunction · 0.68
TestInitFunction · 0.68