From d579fa0564686036d628dd602d2ed6e5ff3db6ef Mon Sep 17 00:00:00 2001 From: Steve Dower Date: Wed, 13 Dec 2023 17:48:42 +0000 Subject: [PATCH] Add missed realpath and simplify sysconfig --- Lib/sysconfig/__init__.py | 11 +---------- Modules/getpath.py | 8 +++++++- 2 files changed, 8 insertions(+), 11 deletions(-) diff --git a/Lib/sysconfig/__init__.py b/Lib/sysconfig/__init__.py index c60c9f3440615b..deb438c705f3a0 100644 --- a/Lib/sysconfig/__init__.py +++ b/Lib/sysconfig/__init__.py @@ -404,16 +404,7 @@ def get_config_h_filename(): """Return the path of pyconfig.h.""" if _PYTHON_BUILD: if os.name == "nt": - # This ought to be as simple as dirname(sys._base_executable), but - # if a venv uses symlinks to a build in the source tree, then this - # fails. So instead we guess the subdirectory name from sys.winver - if sys.winver.endswith('-32'): - arch = 'win32' - elif sys.winver.endswith('-arm64'): - arch = 'arm64' - else: - arch = 'amd64' - inc_dir = os.path.join(_PROJECT_BASE, 'PCbuild', arch) + inc_dir = os.path.dirname(sys._base_executable) else: inc_dir = _PROJECT_BASE else: diff --git a/Modules/getpath.py b/Modules/getpath.py index 1410ffdbed8c70..59a98deb377b7b 100644 --- a/Modules/getpath.py +++ b/Modules/getpath.py @@ -403,7 +403,13 @@ def search_up(prefix, *landmarks, test=isfile): # ****************************************************************************** if not base_executable: - base_executable = executable or real_executable or '' + if executable: + try: + base_executable = realpath(executable) + except OSError: + base_executable = executable + else: + base_executable = real_executable or '' if not real_executable: real_executable = base_executable