From 889d729422ec0bd4e1dd8a5016033410c2d26a5e Mon Sep 17 00:00:00 2001 From: Steve Dower Date: Fri, 4 Sep 2020 21:36:13 +0100 Subject: [PATCH 1/3] bpo-41627: Distinguish 32 and 64-bit user site packages on Windows --- Lib/site.py | 3 ++- Lib/sysconfig.py | 15 ++++++++------- .../2020-09-04-21-35-28.bpo-41627.sx2KN1.rst | 2 ++ 3 files changed, 12 insertions(+), 8 deletions(-) create mode 100644 Misc/NEWS.d/next/Windows/2020-09-04-21-35-28.bpo-41627.sx2KN1.rst diff --git a/Lib/site.py b/Lib/site.py index 8979365cafc37e..4c095774729c5e 100644 --- a/Lib/site.py +++ b/Lib/site.py @@ -274,7 +274,8 @@ def _get_path(userbase): version = sys.version_info if os.name == 'nt': - return f'{userbase}\\Python{version[0]}{version[1]}\\site-packages' + ver_nodot = sys.winver.replace('.', '') + return f'{userbase}\\Python{ver_nodot}\\site-packages' if sys.platform == 'darwin' and sys._framework: return f'{userbase}/lib/python/site-packages' diff --git a/Lib/sysconfig.py b/Lib/sysconfig.py index bf04ac541e6b02..a770ffd2949204 100644 --- a/Lib/sysconfig.py +++ b/Lib/sysconfig.py @@ -53,12 +53,12 @@ }, # NOTE: When modifying "purelib" scheme, update site._get_path() too. 'nt_user': { - 'stdlib': '{userbase}/Python{py_version_nodot}', - 'platstdlib': '{userbase}/Python{py_version_nodot}', - 'purelib': '{userbase}/Python{py_version_nodot}/site-packages', - 'platlib': '{userbase}/Python{py_version_nodot}/site-packages', - 'include': '{userbase}/Python{py_version_nodot}/Include', - 'scripts': '{userbase}/Python{py_version_nodot}/Scripts', + 'stdlib': '{userbase}/Python{py_version_nodot_plat}', + 'platstdlib': '{userbase}/Python{py_version_nodot_plat}', + 'purelib': '{userbase}/Python{py_version_nodot_plat}/site-packages', + 'platlib': '{userbase}/Python{py_version_nodot_plat}/site-packages', + 'include': '{userbase}/Python{py_version_nodot_plat}/Include', + 'scripts': '{userbase}/Python{py_version_nodot_plat}/Scripts', 'data': '{userbase}', }, 'posix_user': { @@ -431,6 +431,8 @@ def _init_non_posix(vars): vars['EXE'] = '.exe' vars['VERSION'] = _PY_VERSION_SHORT_NO_DOT vars['BINDIR'] = os.path.dirname(_safe_realpath(sys.executable)) + vars['TZPATH'] = '' + vars['py_version_nodot_plat'] = sys.winver.replace('.', '') # # public APIs @@ -546,7 +548,6 @@ def get_config_vars(*args): if os.name == 'nt': _init_non_posix(_CONFIG_VARS) - _CONFIG_VARS['TZPATH'] = '' if os.name == 'posix': _init_posix(_CONFIG_VARS) # For backward compatibility, see issue19555 diff --git a/Misc/NEWS.d/next/Windows/2020-09-04-21-35-28.bpo-41627.sx2KN1.rst b/Misc/NEWS.d/next/Windows/2020-09-04-21-35-28.bpo-41627.sx2KN1.rst new file mode 100644 index 00000000000000..043bd5e9341c3c --- /dev/null +++ b/Misc/NEWS.d/next/Windows/2020-09-04-21-35-28.bpo-41627.sx2KN1.rst @@ -0,0 +1,2 @@ +The user site directory for 32-bit now includes a ``-32`` suffix to +distinguish it from the 64-bit interpreter's directory. From bdc676c922d43601a4e9aab17bf4dea299922d0e Mon Sep 17 00:00:00 2001 From: Steve Dower Date: Fri, 4 Sep 2020 21:56:22 +0100 Subject: [PATCH 2/3] Fix incorrect error message (fix for the bug coming next) --- Lib/sysconfig.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Lib/sysconfig.py b/Lib/sysconfig.py index a770ffd2949204..69a5565b549ff4 100644 --- a/Lib/sysconfig.py +++ b/Lib/sysconfig.py @@ -149,10 +149,10 @@ def is_python_build(check_home=False): def _subst_vars(s, local_vars): try: return s.format(**local_vars) - except KeyError: + except KeyError as var: try: return s.format(**os.environ) - except KeyError as var: + except KeyError: raise AttributeError('{%s}' % var) from None def _extend_dict(target_dict, other_dict): From 21823ba56e9c1d0d269a22113e997ed23df18187 Mon Sep 17 00:00:00 2001 From: Steve Dower Date: Fri, 4 Sep 2020 21:58:06 +0100 Subject: [PATCH 3/3] Ensure py_version_nodot_plat is always defined --- Lib/sysconfig.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/Lib/sysconfig.py b/Lib/sysconfig.py index 69a5565b549ff4..6c87b06634c457 100644 --- a/Lib/sysconfig.py +++ b/Lib/sysconfig.py @@ -432,7 +432,6 @@ def _init_non_posix(vars): vars['VERSION'] = _PY_VERSION_SHORT_NO_DOT vars['BINDIR'] = os.path.dirname(_safe_realpath(sys.executable)) vars['TZPATH'] = '' - vars['py_version_nodot_plat'] = sys.winver.replace('.', '') # # public APIs @@ -545,6 +544,10 @@ def get_config_vars(*args): except AttributeError: # sys.abiflags may not be defined on all platforms. _CONFIG_VARS['abiflags'] = '' + try: + _CONFIG_VARS['py_version_nodot_plat'] = sys.winver.replace('.', '') + except AttributeError: + _CONFIG_VARS['py_version_nodot_plat'] = '' if os.name == 'nt': _init_non_posix(_CONFIG_VARS)