File: clPythonLocator.cpp

package info (click to toggle)
codelite 14.0%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 112,816 kB
  • sloc: cpp: 483,662; ansic: 150,144; php: 9,569; lex: 4,186; python: 3,417; yacc: 2,820; sh: 1,147; makefile: 52; xml: 13
file content (70 lines) | stat: -rw-r--r-- 1,810 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
#include "clPythonLocator.hpp"
#include "file_logger.h"
#include "globals.h"
#include "wx/filename.h"
#ifdef __WXMSW__
#include "clRegistery.hpp"
#include "wx/msw/registry.h"
#endif

clPythonLocator::clPythonLocator() {}

clPythonLocator::~clPythonLocator() {}

bool clPythonLocator::Locate()
{
#ifdef __WXMSW__
    return MSWLocate();
#else
    wxFileName exepath;
    wxFileName pippath;
    // Search for python3 before we search for python2
    if(::clFindExecutable("python3", exepath)) {
        m_python = exepath.GetFullPath();
    } else {
        // couldn't find python3, try python without suffix
        if(::clFindExecutable("python", exepath)) {
            m_python = exepath.GetFullPath();
        } else {
            return false;
        }
    }
    if(::clFindExecutable("pip3", pippath)) {
        m_pip = pippath.GetFullPath();
    } else {
        // couldn't find pip3, try python without suffix
        if(::clFindExecutable("pip", exepath)) {
            m_pip = pippath.GetFullPath();
        } else {
            return false;
        }
    }
    return exepath.FileExists();
#endif
}

bool clPythonLocator::MSWLocate()
{
#ifdef __WXMSW__
    clRegistery reg("SOFTWARE\\Python\\PythonCore");
    wxString child = reg.GetFirstChild();
    if(child.IsEmpty()) { return false; }

    clRegistery regChild(child + "\\InstallPath");
    m_python = regChild.ReadValueString("ExecutablePath");
    if(!m_python.empty()) {
        clDEBUG() << "Python exe located at:" << m_python;

        wxFileName fnPip(m_python);
        fnPip.AppendDir("Scripts");
        fnPip.SetName("pip");
        m_pip = fnPip.GetFullPath();
        // Try to locate pip
        return true;
    } else {
        clDEBUG() << "No python installation found";
    }
    return false;
#endif
    return false;
}