| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -74,6 +74,27 @@ def debug_build(program): | |||
| 74 | 74 | return name.casefold().endswith("_d".casefold()) | |
| 75 | 75 | ||
| 76 | 76 | ||
| 77 | + def getpath_which(program_name): | ||
| 78 | + if sys.platform != 'cygwin': | ||
| 79 | + return shutil.which(program_name) | ||
| 80 | + | ||
| 81 | + # shutil.which() checks for os.access(fn, os.F_OK | os.X_OK), whereas | ||
| 82 | + # getpath.isxfile() doesn't. The difference matters on Cygwin. | ||
| 83 | + import stat | ||
| 84 | + def isxfile(fn): | ||
| 85 | + try: | ||
| 86 | + st = os.stat(fn) | ||
| 87 | + except OSError: | ||
| 88 | + return False | ||
| 89 | + return stat.S_ISREG(st.st_mode) | ||
| 90 | + | ||
| 91 | + for p in os.environ['PATH'].split(':'): | ||
| 92 | + p = os.path.join(p, program_name) | ||
| 93 | + if isxfile(p): | ||
| 94 | + return p | ||
| 95 | + return None | ||
| 96 | + | ||
| 97 | + | ||
| 77 | 98 | def remove_python_envvars(): | |
| 78 | 99 | env = dict(os.environ) | |
| 79 | 100 | # Remove PYTHON* environment variables to get deterministic environment | |
@@ -92,6 +113,8 @@ def setUp(self): | |||
| 92 | 113 | exename += ext | |
| 93 | 114 | exepath = builddir | |
| 94 | 115 | else: | |
| 116 | + if sys.platform == 'cygwin': | ||
| 117 | + exename += '.exe' | ||
| 95 | 118 | exepath = os.path.join(builddir, 'Programs') | |
| 96 | 119 | self.test_exe = exe = os.path.join(exepath, exename) | |
| 97 | 120 | if not os.path.exists(exe): | |
@@ -328,6 +351,8 @@ def test_pre_initialization_api(self): | |||
| 328 | 351 | expected_path = self.test_exe | |
| 329 | 352 | else: | |
| 330 | 353 | expected_path = os.path.join(os.getcwd(), "_testembed") | |
| 354 | + if sys.platform == 'cygwin': | ||
| 355 | + expected_path += '.exe' | ||
| 331 | 356 | expected_output = f"sys.executable: {expected_path}\n" | |
| 332 | 357 | self.assertIn(expected_output, out) | |
| 333 | 358 | self.assertEqual(err, '') | |
@@ -872,12 +897,16 @@ def get_expected_config(self, expected_preconfig, expected, | |||
| 872 | 897 | default_executable = os.path.abspath(expected['program_name']) | |
| 873 | 898 | else: | |
| 874 | 899 | default_executable = os.path.join(os.getcwd(), '_testembed') | |
| 900 | + if sys.platform == 'cygwin': | ||
| 901 | + default_executable += '.exe' | ||
| 875 | 902 | if expected['executable'] is self.GET_DEFAULT_CONFIG: | |
| 876 | 903 | expected['executable'] = default_executable | |
| 877 | 904 | if expected['base_executable'] is self.GET_DEFAULT_CONFIG: | |
| 878 | 905 | expected['base_executable'] = default_executable | |
| 879 | 906 | if expected['program_name'] is self.GET_DEFAULT_CONFIG: | |
| 880 | 907 | expected['program_name'] = './_testembed' | |
| 908 | + if sys.platform == 'cygwin': | ||
| 909 | + expected['program_name'] += '.exe' | ||
| 881 | 910 | ||
| 882 | 911 | config = configs['config'] | |
| 883 | 912 | for key, value in expected.items(): | |
@@ -1370,7 +1399,7 @@ def default_program_name(self, config): | |||
| 1370 | 1399 | if MACOS: | |
| 1371 | 1400 | executable = self.test_exe | |
| 1372 | 1401 | else: | |
| 1373 | - executable = shutil.which(program_name) or '' | ||
| 1402 | + executable = getpath_which(program_name) or '' | ||
| 1374 | 1403 | config.update({ | |
| 1375 | 1404 | 'program_name': program_name, | |
| 1376 | 1405 | 'base_executable': executable, | |
@@ -1469,6 +1498,13 @@ def tmpdir_with_python(self, subdir=None): | |||
| 1469 | 1498 | shutil.copystat(self.test_exe, exec_copy) | |
| 1470 | 1499 | self.test_exe = exec_copy | |
| 1471 | 1500 | ||
| 1501 | + if sys.platform == "cygwin": | ||
| 1502 | + # Copy libpython DLL | ||
| 1503 | + exe_path = os.path.dirname(sys.executable) | ||
| 1504 | + libpython_dll = sysconfig.get_config_var('DLLLIBRARY') | ||
| 1505 | + shutil.copy2(os.path.join(exe_path, libpython_dll), | ||
| 1506 | + os.path.join(tmpdir, libpython_dll)) | ||
| 1507 | + | ||
| 1472 | 1508 | yield tmpdir | |
| 1473 | 1509 | ||
| 1474 | 1510 | def test_init_setpythonhome(self): | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -41,8 +41,13 @@ char **main_argv; | |||
| 41 | 41 | #define PROGRAM "test_embed" | |
| 42 | 42 | ||
| 43 | 43 | /* Use path starting with "./" avoids a search along the PATH */ | |
| 44 | - #define PROGRAM_NAME L"./_testembed" | ||
| 45 | - #define PROGRAM_NAME_UTF8 "./_testembed" | ||
| 44 | + #ifdef __CYGWIN__ | ||
| 45 | + # define PROGRAM_NAME L"./_testembed.exe" | ||
| 46 | + # define PROGRAM_NAME_UTF8 "./_testembed.exe" | ||
| 47 | + #else | ||
| 48 | + # define PROGRAM_NAME L"./_testembed" | ||
| 49 | + # define PROGRAM_NAME_UTF8 "./_testembed" | ||
| 50 | + #endif | ||
| 46 | 51 | ||
| 47 | 52 | #define INIT_LOOPS 4 | |
| 48 | 53 | ||
| Back | FazBrowse Home | New Git URL |
0 commit comments