@@ -1304,6 +1304,66 @@ def test_init_setpythonhome(self):
13041304 self .check_all_configs ("test_init_setpythonhome" , config ,
13051305 api = API_COMPAT , env = env )
13061306
1307+ def test_init_is_python_build_with_home (self ):
1308+ # Test _Py_path_config._is_python_build configuration (gh-91985)
1309+ config = self ._get_expected_config ()
1310+ paths = config ['config' ]['module_search_paths' ]
1311+ paths_str = os .path .pathsep .join (paths )
1312+
1313+ for path in paths :
1314+ if not os .path .isdir (path ):
1315+ continue
1316+ if os .path .exists (os .path .join (path , 'os.py' )):
1317+ home = os .path .dirname (path )
1318+ break
1319+ else :
1320+ self .fail (f"Unable to find home in { paths !r} " )
1321+
1322+ prefix = exec_prefix = home
1323+ if MS_WINDOWS :
1324+ stdlib = os .path .join (home , "Lib" )
1325+ # Because we are specifying 'home', module search paths
1326+ # are fairly static
1327+ expected_paths = [paths [0 ], stdlib , os .path .join (home , 'DLLs' )]
1328+ else :
1329+ version = f'{ sys .version_info .major } .{ sys .version_info .minor } '
1330+ stdlib = os .path .join (home , sys .platlibdir , f'python{ version } ' )
1331+ expected_paths = self .module_search_paths (prefix = home , exec_prefix = home )
1332+
1333+ config = {
1334+ 'home' : home ,
1335+ 'module_search_paths' : expected_paths ,
1336+ 'prefix' : prefix ,
1337+ 'base_prefix' : prefix ,
1338+ 'exec_prefix' : exec_prefix ,
1339+ 'base_exec_prefix' : exec_prefix ,
1340+ 'pythonpath_env' : paths_str ,
1341+ 'stdlib_dir' : stdlib ,
1342+ }
1343+ # The code above is taken from test_init_setpythonhome()
1344+ env = {'TESTHOME' : home , 'PYTHONPATH' : paths_str }
1345+
1346+ env ['NEGATIVE_ISPYTHONBUILD' ] = '1'
1347+ config ['_is_python_build' ] = 0
1348+ self .check_all_configs ("test_init_is_python_build" , config ,
1349+ api = API_COMPAT , env = env )
1350+
1351+ env ['NEGATIVE_ISPYTHONBUILD' ] = '0'
1352+ config ['_is_python_build' ] = 1
1353+ exedir = os .path .dirname (sys .executable )
1354+ with open (os .path .join (exedir , 'pybuilddir.txt' ), encoding = 'utf8' ) as f :
1355+ expected_paths [2 ] = os .path .normpath (
1356+ os .path .join (exedir , f'{ f .read ()} \n $' .splitlines ()[0 ]))
1357+ if not MS_WINDOWS :
1358+ # PREFIX (default) is set when running in build directory
1359+ prefix = exec_prefix = sys .prefix
1360+ # stdlib calculation (/Lib) is not yet supported
1361+ expected_paths [0 ] = self .module_search_paths (prefix = prefix )[0 ]
1362+ config .update (prefix = prefix , base_prefix = prefix ,
1363+ exec_prefix = exec_prefix , base_exec_prefix = exec_prefix )
1364+ self .check_all_configs ("test_init_is_python_build" , config ,
1365+ api = API_COMPAT , env = env )
1366+
13071367 def copy_paths_by_env (self , config ):
13081368 all_configs = self ._get_expected_config ()
13091369 paths = all_configs ['config' ]['module_search_paths' ]
0 commit comments