Files
MINGW-packages/mingw-w64-python/0027-site-Change-user-site-packages-path-to-include-the-e.patch
2026-01-07 22:17:09 +01:00

102 lines
4.4 KiB
Diff

From 468712d39838b44c88c819be0fc5809e5f87a804 Mon Sep 17 00:00:00 2001
From: Naveen M K <naveen521kk@gmail.com>
Date: Wed, 19 Jan 2022 20:01:45 +0530
Subject: [PATCH 027/N] site: Change user site-packages path to include the
environment info
This should avoid mixing of user site-packages between python
from various environments. Previously, the user site-packages
should be located at `~/.local/lib/python3.12` for all environment
including 32-bits variants which caused problems with 64-bit trying to
load 32-bit extensions. Now this path will be changed to
`~/.local/lib/python3.12-<platform tag here>`, for example, in
CLANG64 this would be `~/.local/lib/python3.12-mingw_x86_64_ucrt_llvm`.
Fixes https://github.com/msys2-contrib/cpython-mingw/issues/40
---
Lib/site.py | 31 ++++++++++++++++++++++++++++++-
Lib/sysconfig/__init__.py | 14 +++++++++-----
2 files changed, 39 insertions(+), 6 deletions(-)
diff --git a/Lib/site.py b/Lib/site.py
index b87f05c..939f45a 100644
--- a/Lib/site.py
+++ b/Lib/site.py
@@ -309,6 +309,32 @@ def _getuserbase():
return joinuser("~", ".local")
+# Copy of sysconfig.get_platform() but only for MinGW
+def _get_platform():
+ if os.name == 'nt':
+ if sys._is_mingw:
+ platform = 'mingw'
+ if 'amd64' in sys.version.lower():
+ platform += '_x86_64'
+ elif 'arm64' in sys.version.lower():
+ platform += '_aarch64'
+ elif 'arm' in sys.version.lower():
+ platform += '_armv7'
+ else:
+ platform += '_i686'
+
+ if 'ucrt' in sys.version.lower():
+ platform += '_ucrt'
+ else:
+ platform += "_msvcrt"
+
+ if 'clang' in sys.version.lower():
+ platform += "_llvm"
+ else:
+ platform += "_gnu"
+
+ return platform
+ return sys.platform
# Same to sysconfig.get_path('purelib', os.name+'_user')
def _get_path(userbase):
@@ -320,7 +346,10 @@ def _get_path(userbase):
implementation = _get_implementation()
implementation_lower = implementation.lower()
- if os.name == 'nt' and not sys._is_mingw:
+ if os.name == 'nt':
+ if sys._is_mingw:
+ return f'{userbase}/lib/{implementation_lower}{version[0]}.{version[1]}-{_get_platform()}{abi_thread}/site-packages'
+
ver_nodot = sys.winver.replace('.', '')
return f'{userbase}\\{implementation}{ver_nodot}\\site-packages'
diff --git a/Lib/sysconfig/__init__.py b/Lib/sysconfig/__init__.py
index 20e18ae..fb40ef6 100644
--- a/Lib/sysconfig/__init__.py
+++ b/Lib/sysconfig/__init__.py
@@ -148,11 +148,11 @@ if _HAS_USER_BASE:
'data': '{userbase}',
},
'posix_user': {
- 'stdlib': '{userbase}/{platlibdir}/{implementation_lower}{py_version_short}{abi_thread}',
- 'platstdlib': '{userbase}/{platlibdir}/{implementation_lower}{py_version_short}{abi_thread}',
- 'purelib': '{userbase}/lib/{implementation_lower}{py_version_short}{abi_thread}/site-packages',
- 'platlib': '{userbase}/lib/{implementation_lower}{py_version_short}{abi_thread}/site-packages',
- 'include': '{userbase}/include/{implementation_lower}{py_version_short}{abi_thread}',
+ 'stdlib': '{userbase}/{platlibdir}/{implementation_lower}{py_version_short_plat}{abi_thread}',
+ 'platstdlib': '{userbase}/{platlibdir}/{implementation_lower}{py_version_short_plat}{abi_thread}',
+ 'purelib': '{userbase}/lib/{implementation_lower}{py_version_short_plat}{abi_thread}/site-packages',
+ 'platlib': '{userbase}/lib/{implementation_lower}{py_version_short_plat}{abi_thread}/site-packages',
+ 'include': '{userbase}/include/{implementation_lower}{py_version_short_plat}{abi_thread}',
'scripts': '{userbase}/bin',
'data': '{userbase}',
},
@@ -495,6 +495,10 @@ def _init_config_vars():
_CONFIG_VARS['py_version_nodot_plat'] = sys.winver.replace('.', '')
except AttributeError:
_CONFIG_VARS['py_version_nodot_plat'] = ''
+ if os.name == 'nt' and sys._is_mingw:
+ _CONFIG_VARS['py_version_short_plat'] = f'{_PY_VERSION_SHORT}-{get_platform()}'
+ else:
+ _CONFIG_VARS['py_version_short_plat'] = _PY_VERSION_SHORT
if os.name == 'nt' and not sys._is_mingw:
_init_non_posix(_CONFIG_VARS)