From 7589385e18c590565ed53059821c7b75dbc45bd9 Mon Sep 17 00:00:00 2001 From: neonene <53406459+neonene@users.noreply.github.com> Date: Wed, 4 May 2022 10:07:53 +0900 Subject: [PATCH 1/8] insert pyd build directory --- Modules/getpath.py | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/Modules/getpath.py b/Modules/getpath.py index 26465c88aaea5c..daa2c459894fa4 100644 --- a/Modules/getpath.py +++ b/Modules/getpath.py @@ -692,6 +692,18 @@ def search_up(prefix, *landmarks, test=isfile): if stdlib_dir: pythonpath.append(stdlib_dir) if platstdlib_dir: + if os_name == 'nt' and real_executable_dir and \ + isfile(joinpath(real_executable_dir, BUILDDIR_TXT)): + p = platstdlib_dir + try: + p = joinpath( + real_executable_dir, + readlines(joinpath(real_executable_dir, BUILDDIR_TXT))[0], + ) + except IndexError: + p = real_executable_dir + if p != platstdlib_dir: + pythonpath.append(p) # prior to platstdlib_dir pythonpath.append(platstdlib_dir) config['module_search_paths'] = pythonpath From 5ed2daaeddfffff4c4aa2273e8b4c1194cd78c52 Mon Sep 17 00:00:00 2001 From: neonene <53406459+neonene@users.noreply.github.com> Date: Wed, 4 May 2022 10:21:27 +0900 Subject: [PATCH 2/8] Update test_embed.test_init_setpythonhome --- Lib/test/test_embed.py | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/Lib/test/test_embed.py b/Lib/test/test_embed.py index e25541820748bf..fa3a0bdc381ed8 100644 --- a/Lib/test/test_embed.py +++ b/Lib/test/test_embed.py @@ -1255,6 +1255,20 @@ def test_init_setpythonhome(self): # Because we are specifying 'home', module search paths # are fairly static expected_paths = [paths[0], stdlib, os.path.join(home, 'DLLs')] + # gh-91985 + exedir = os.path.dirname(self.test_exe) + _dlldir = None + try: + with open(os.path.join(exedir, 'pybuilddir.txt'), encoding="utf8") as fp: + _dlldir = os.path.normpath( + os.path.join(exedir, fp.read().splitlines()[0]) + ) + except IndexError: + _dlldir = exedir + except FileNotFoundError: + pass + if _dlldir and _dlldir != expected_paths[-1]: + expected_paths.insert(-1, _dlldir) else: version = f'{sys.version_info.major}.{sys.version_info.minor}' stdlib = os.path.join(home, sys.platlibdir, f'python{version}') From b450a26d8ad62c383e2a7a19ab0c944caa6d02b9 Mon Sep 17 00:00:00 2001 From: neonene <53406459+neonene@users.noreply.github.com> Date: Wed, 4 May 2022 21:49:58 +0900 Subject: [PATCH 3/8] update test_init_setpythonhome --- Lib/test/test_embed.py | 17 +++++++---------- 1 file changed, 7 insertions(+), 10 deletions(-) diff --git a/Lib/test/test_embed.py b/Lib/test/test_embed.py index fa3a0bdc381ed8..edc13c1cf49c4b 100644 --- a/Lib/test/test_embed.py +++ b/Lib/test/test_embed.py @@ -1255,20 +1255,17 @@ def test_init_setpythonhome(self): # Because we are specifying 'home', module search paths # are fairly static expected_paths = [paths[0], stdlib, os.path.join(home, 'DLLs')] - # gh-91985 - exedir = os.path.dirname(self.test_exe) - _dlldir = None + # gh-91985 insert a dll build path + p = os.path.dirname(self.test_exe) try: - with open(os.path.join(exedir, 'pybuilddir.txt'), encoding="utf8") as fp: - _dlldir = os.path.normpath( - os.path.join(exedir, fp.read().splitlines()[0]) + with open(os.path.join(p, 'pybuilddir.txt'), encoding="utf8") as f: + p = os.path.normpath( + os.path.join(p, f'{f.read()}\n'.split('\n')[0]) ) - except IndexError: - _dlldir = exedir + if p != expected_paths[-1]: + expected_paths.insert(-1, p) except FileNotFoundError: pass - if _dlldir and _dlldir != expected_paths[-1]: - expected_paths.insert(-1, _dlldir) else: version = f'{sys.version_info.major}.{sys.version_info.minor}' stdlib = os.path.join(home, sys.platlibdir, f'python{version}') From e4f681393270fb86ba5043674906b23662cb9150 Mon Sep 17 00:00:00 2001 From: neonene <53406459+neonene@users.noreply.github.com> Date: Wed, 4 May 2022 22:15:33 +0900 Subject: [PATCH 4/8] update test_init_setpythonhome --- Lib/test/test_embed.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Lib/test/test_embed.py b/Lib/test/test_embed.py index edc13c1cf49c4b..11868d0d531f6e 100644 --- a/Lib/test/test_embed.py +++ b/Lib/test/test_embed.py @@ -1260,7 +1260,7 @@ def test_init_setpythonhome(self): try: with open(os.path.join(p, 'pybuilddir.txt'), encoding="utf8") as f: p = os.path.normpath( - os.path.join(p, f'{f.read()}\n'.split('\n')[0]) + os.path.join(p, f'{f.read()}\n$'.splitlines()[0]) ) if p != expected_paths[-1]: expected_paths.insert(-1, p) From e88be42f0a9065bfdd780b011d2d21a2cab317b1 Mon Sep 17 00:00:00 2001 From: neonene <53406459+neonene@users.noreply.github.com> Date: Thu, 5 May 2022 20:04:45 +0900 Subject: [PATCH 5/8] remove a meaningless line --- Modules/getpath.py | 1 - 1 file changed, 1 deletion(-) diff --git a/Modules/getpath.py b/Modules/getpath.py index daa2c459894fa4..0bc0b3350d9319 100644 --- a/Modules/getpath.py +++ b/Modules/getpath.py @@ -694,7 +694,6 @@ def search_up(prefix, *landmarks, test=isfile): if platstdlib_dir: if os_name == 'nt' and real_executable_dir and \ isfile(joinpath(real_executable_dir, BUILDDIR_TXT)): - p = platstdlib_dir try: p = joinpath( real_executable_dir, From a49949501b480d79baae9db133f4095df19ce84c Mon Sep 17 00:00:00 2001 From: neonene <53406459+neonene@users.noreply.github.com> Date: Fri, 6 May 2022 00:24:39 +0900 Subject: [PATCH 6/8] formatting --- Lib/test/test_embed.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/Lib/test/test_embed.py b/Lib/test/test_embed.py index 11868d0d531f6e..174d24be75d003 100644 --- a/Lib/test/test_embed.py +++ b/Lib/test/test_embed.py @@ -1255,15 +1255,16 @@ def test_init_setpythonhome(self): # Because we are specifying 'home', module search paths # are fairly static expected_paths = [paths[0], stdlib, os.path.join(home, 'DLLs')] - # gh-91985 insert a dll build path - p = os.path.dirname(self.test_exe) try: - with open(os.path.join(p, 'pybuilddir.txt'), encoding="utf8") as f: + # gh-91985 insert a dll build path + p = os.path.dirname(self.test_exe) + with open(os.path.join(p, 'pybuilddir.txt'), encoding='utf8') as f: p = os.path.normpath( os.path.join(p, f'{f.read()}\n$'.splitlines()[0]) ) if p != expected_paths[-1]: expected_paths.insert(-1, p) + del p except FileNotFoundError: pass else: From 50a20543262dffc5d66766661be9e2fc359f66c9 Mon Sep 17 00:00:00 2001 From: neonene <53406459+neonene@users.noreply.github.com> Date: Fri, 6 May 2022 13:33:36 +0900 Subject: [PATCH 7/8] del p --- Lib/test/test_embed.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Lib/test/test_embed.py b/Lib/test/test_embed.py index 174d24be75d003..4c2f00a9227c90 100644 --- a/Lib/test/test_embed.py +++ b/Lib/test/test_embed.py @@ -1266,7 +1266,7 @@ def test_init_setpythonhome(self): expected_paths.insert(-1, p) del p except FileNotFoundError: - pass + del p else: version = f'{sys.version_info.major}.{sys.version_info.minor}' stdlib = os.path.join(home, sys.platlibdir, f'python{version}') From 239d2f8d5290e031e8f8412f301b633f3ebaf99e Mon Sep 17 00:00:00 2001 From: neonene <53406459+neonene@users.noreply.github.com> Date: Fri, 6 May 2022 20:06:44 +0900 Subject: [PATCH 8/8] move a bracket --- Lib/test/test_embed.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/Lib/test/test_embed.py b/Lib/test/test_embed.py index d2899cbd5717a4..f93301da88863c 100644 --- a/Lib/test/test_embed.py +++ b/Lib/test/test_embed.py @@ -1269,8 +1269,7 @@ def test_init_setpythonhome(self): p = os.path.dirname(self.test_exe) with open(os.path.join(p, 'pybuilddir.txt'), encoding='utf8') as f: p = os.path.normpath( - os.path.join(p, f'{f.read()}\n$'.splitlines()[0]) - ) + os.path.join(p, f'{f.read()}\n$'.splitlines()[0])) if p != expected_paths[-1]: expected_paths.insert(-1, p) del p