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