@@ -185,12 +185,17 @@ public void postInitialize(PythonCore core) {
185185 sys .setAttribute (name , base_prefix );
186186 }
187187
188+ String coreHome = context .getCoreHome ();
189+ String stdlibHome = context .getStdlibHome ();
190+ String capiHome = context .getCAPIHome ();
191+
188192 sys .setAttribute ("executable" , PythonOptions .getOption (context , PythonOptions .Executable ));
189193 sys .setAttribute ("graal_python_jython_emulation_enabled" , PythonOptions .getOption (context , PythonOptions .EmulateJython ));
190194 sys .setAttribute ("graal_python_host_import_enabled" , context .getEnv ().isHostLookupAllowed ());
191195 sys .setAttribute ("graal_python_home" , context .getLanguage ().getHome ());
192- sys .setAttribute ("graal_python_core_home" , context .getCoreHome ());
193- sys .setAttribute ("graal_python_stdlib_home" , context .getStdlibHome ());
196+ sys .setAttribute ("graal_python_core_home" , coreHome );
197+ sys .setAttribute ("graal_python_stdlib_home" , stdlibHome );
198+ sys .setAttribute ("graal_python_capi_home" , capiHome );
194199 sys .setAttribute ("__flags__" , core .factory ().createTuple (new Object []{
195200 false , // bytes_warning
196201 !PythonOptions .getFlag (context , PythonOptions .PythonOptimizeFlag ), // debug
@@ -214,33 +219,39 @@ public void postInitialize(PythonCore core) {
214219
215220 LanguageInfo llvmInfo = env .getInternalLanguages ().get (LLVM_LANGUAGE );
216221 Toolchain toolchain = env .lookup (llvmInfo , Toolchain .class );
217- String capiSrc = context .getCAPIHome ();
218- String capiHome = getCapiHome (env , sys );
222+
223+ boolean isIsolated = PythonOptions .getOption (context , PythonOptions .IsolateFlag );
224+ boolean capiSeparate = !capiHome .equals (coreHome );
219225
220226 Object [] path ;
221227 int pathIdx = 0 ;
222- boolean doIsolate = PythonOptions .getOption (context , PythonOptions .IsolateFlag );
223- int defaultPaths = doIsolate ? 3 : 4 ;
228+ int defaultPathsLen = 2 ;
229+ if (!isIsolated ) {
230+ defaultPathsLen ++;
231+ }
232+ if (capiSeparate ) {
233+ defaultPathsLen ++;
234+ }
224235 if (option .length () > 0 ) {
225236 String [] split = option .split (context .getEnv ().getPathSeparator ());
226- path = new Object [split .length + defaultPaths ];
237+ path = new Object [split .length + defaultPathsLen ];
227238 System .arraycopy (split , 0 , path , 0 , split .length );
228239 pathIdx = split .length ;
229240 } else {
230- path = new Object [defaultPaths ];
241+ path = new Object [defaultPathsLen ];
231242 }
232- if (!doIsolate ) {
243+ if (!isIsolated ) {
233244 path [pathIdx ++] = getScriptPath (env , args );
234245 }
235- path [pathIdx ++] = context .getStdlibHome ();
236- path [pathIdx ++] = context .getCoreHome () + env .getFileNameSeparator () + "modules" ;
237- path [pathIdx ++] = capiHome ;
246+ path [pathIdx ++] = stdlibHome ;
247+ path [pathIdx ++] = coreHome + env .getFileNameSeparator () + "modules" ;
248+ if (capiSeparate ) {
249+ // include our native modules on the path
250+ path [pathIdx ++] = capiHome + env .getFileNameSeparator () + "modules" ;
251+ }
238252 PList sysPaths = core .factory ().createList (path );
239253 sys .setAttribute ("path" , sysPaths );
240- sys .setAttribute ("graal_python_cext_src" , capiSrc );
241254 sys .setAttribute ("graal_python_platform_id" , toolchain .getIdentifier ());
242- sys .setAttribute ("graal_python_capi_home" , capiHome );
243- sys .setAttribute ("graal_python_capi_module_home" , capiHome );
244255 }
245256
246257 private static String getScriptPath (Env env , String [] args ) {
@@ -266,33 +277,6 @@ private static String getScriptPath(Env env, String[] args) {
266277 return scriptPath ;
267278 }
268279
269- private static String getCapiHome (Env env , PythonModule sys ) {
270- String pythonSubdir = "python" + PythonLanguage .MAJOR + "." + PythonLanguage .MINOR ;
271- return String .join (env .getFileNameSeparator (), getCapiUserBase (env , sys ), "lib" , pythonSubdir , "capi" );
272- }
273-
274- // similar to 'sysconfig._getuserbase()'
275- private static String getCapiUserBase (Env env , PythonModule sys ) {
276- String customUserBase = env .getEnvironment ().get ("PYTHONUSERBASE" );
277- if (customUserBase != null ) {
278- return customUserBase ;
279- }
280-
281- Object osName = sys .getAttribute ("platform" );
282- if (FRAMEWORK != PNone .NONE && PLATFORM_DARWIN .equals (osName )) {
283- String _framework = FRAMEWORK .toString ();
284- return String .join (env .getFileNameSeparator (), System .getProperty ("user.home" ), "Library" , _framework , PythonLanguage .MAJOR + "." + PythonLanguage .MINOR );
285- } else if (PLATFORM_WIN32 .equals (osName )) {
286- // first try to get 'APPDATA'
287- String appdata = System .getenv ("APPDATA" );
288- if (appdata != null ) {
289- return appdata + env .getFileNameSeparator () + "Python" ;
290- }
291- return System .getProperty ("user.home" ) + env .getFileNameSeparator () + "Python" ;
292- }
293- return System .getProperty ("user.home" ) + env .getFileNameSeparator () + ".local" ;
294- }
295-
296280 static String getPythonArch () {
297281 String arch = System .getProperty ("os.arch" , "" );
298282 if (arch .equals ("amd64" )) {
0 commit comments