MCPcopy Create free account
hub / github.com/NatronGitHub/Natron / setupPythonEnv

Function setupPythonEnv

Global/PythonUtils.cpp:69–237  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

67}
68
69void setupPythonEnv(const std::string& binPath)
70{
71 //Disable user sites as they could conflict with Natron bundled packages.
72 //If this is set, Python won’t add the user site-packages directory to sys.path.
73 //See https://www.python.org/dev/peps/pep-0370/
74 ProcInfo::putenv_wrapper("PYTHONNOUSERSITE", "1");
75 ++Py_NoUserSiteDirectory;
76
77 //
78 // set up paths, clear those that don't exist or are not valid
79 //
80#ifdef __NATRON_WIN32__
81 static std::string pythonHome = binPath + "\\.."; // must use static storage
82 static const std::wstring pythonHomeW = StrUtils::utf8_to_utf16(pythonHome);
83 std::string pyPathZip = pythonHome + "\\lib\\python" NATRON_PY_VERSION_STRING_NO_DOT ".zip";
84 std::string pyPath = pythonHome + "\\lib\\python" NATRON_PY_VERSION_STRING;
85 std::string pyPathDynLoad = pyPath + "\\lib-dynload";
86 std::string pyPathSitePackages = pyPath + "\\site-packages";
87 std::string pluginPath = binPath + "\\..\\Plugins";
88#else
89# if defined(__NATRON_LINUX__)
90 static std::string pythonHome = binPath + "/.."; // must use static storage
91# elif defined(__NATRON_OSX__)
92 static std::string pythonHome = binPath+ "/../Frameworks/Python.framework/Versions/" NATRON_PY_VERSION_STRING; // must use static storage
93# else
94# error "unsupported platform"
95# endif
96 static const std::wstring pythonHomeW = StrUtils::utf8_to_utf16(pythonHome);
97 std::string pyPathZip = pythonHome + "/lib/python" NATRON_PY_VERSION_STRING_NO_DOT ".zip";
98 std::string pyPath = pythonHome + "/lib/python" NATRON_PY_VERSION_STRING;
99 std::string pyPathDynLoad = pyPath + "/lib-dynload";
100 std::string pyPathSitePackages = pyPath + "/site-packages";
101 std::string pluginPath = binPath + "/../Plugins";
102#endif
103 if ( !fileExists( StrUtils::fromNativeSeparators(pyPathZip) ) ) {
104# if defined(NATRON_CONFIG_SNAPSHOT) || defined(DEBUG)
105 printf( "\"%s\" does not exist, not added to PYTHONPATH\n", pyPathZip.c_str() );
106# endif
107 pyPathZip.clear();
108 }
109 if ( !dirExists( StrUtils::fromNativeSeparators(pyPath) ) ) {
110# if defined(NATRON_CONFIG_SNAPSHOT) || defined(DEBUG)
111 printf( "\"%s\" does not exist, not added to PYTHONPATH\n", pyPath.c_str() );
112# endif
113 pyPath.clear();
114 }
115 if ( !dirExists( StrUtils::fromNativeSeparators(pyPathDynLoad) ) ) {
116# if defined(NATRON_CONFIG_SNAPSHOT) || defined(DEBUG)
117 printf( "\"%s\" does not exist, not added to PYTHONPATH\n", pyPathDynLoad.c_str() );
118# endif
119 pyPathDynLoad.clear();
120 }
121 if ( !dirExists( StrUtils::fromNativeSeparators(pyPathSitePackages) ) ) {
122# if defined(NATRON_CONFIG_SNAPSHOT) || defined(DEBUG)
123 printf( "\"%s\" does not exist, not added to PYTHONPATH\n", pyPathSitePackages.c_str() );
124# endif
125 pyPathSitePackages.clear();
126 }

Callers 2

initPythonMethod · 0.85
mainFunction · 0.85

Calls 8

fileExistsFunction · 0.85
fromNativeSeparatorsFunction · 0.85
dirExistsFunction · 0.85
joinFunction · 0.85
emptyMethod · 0.80
utf8_to_utf16Function · 0.70
clearMethod · 0.45
push_backMethod · 0.45

Tested by

no test coverage detected