Skip to content

Commit 95a06c4

Browse files
committed
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.10` 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.10-<platform tag here>`, for example, in CLANG64 this would be `~/.local/lib/python3.10-mingw_x86_64_clang`. Fixes msys2-contrib#40
1 parent 6f50989 commit 95a06c4

2 files changed

Lines changed: 40 additions & 14 deletions

File tree

Lib/site.py

Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -289,14 +289,36 @@ def joinuser(*args):
289289

290290
return joinuser("~", ".local")
291291

292+
# Copy of sysconfig.get_platform() but only for MinGW
293+
def _get_platform():
294+
if os.name == 'nt':
295+
if 'gcc' in sys.version.lower():
296+
if 'ucrt' in sys.version.lower():
297+
if 'amd64' in sys.version.lower():
298+
return 'mingw_x86_64_ucrt'
299+
return 'mingw_i686_ucrt'
300+
if 'clang' in sys.version.lower():
301+
if 'amd64' in sys.version.lower():
302+
return 'mingw_x86_64_clang'
303+
if 'arm64' in sys.version.lower():
304+
return 'mingw_aarch64'
305+
if 'arm' in sys.version.lower():
306+
return 'mingw_armv7'
307+
return 'mingw_i686_clang'
308+
if 'amd64' in sys.version.lower():
309+
return 'mingw_x86_64'
310+
return 'mingw_i686'
311+
return sys.platform
292312

293313
# Same to sysconfig.get_path('purelib', os.name+'_user')
294314
def _get_path(userbase):
295315
version = sys.version_info
296316

297-
if os.name == 'nt' and not _POSIX_BUILD:
298-
ver_nodot = sys.winver.replace('.', '')
299-
return f'{userbase}\\Python{ver_nodot}\\site-packages'
317+
if os.name == 'nt':
318+
if not _POSIX_BUILD:
319+
ver_nodot = sys.winver.replace('.', '')
320+
return f'{userbase}\\Python{ver_nodot}\\site-packages'
321+
return f'{userbase}/lib/python{version[0]}.{version[1]}-{_get_platform()}/site-packages'
300322

301323
if sys.platform == 'darwin' and sys._framework:
302324
return f'{userbase}/lib/python/site-packages'

Lib/sysconfig.py

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -141,20 +141,20 @@ def joinuser(*args):
141141
_INSTALL_SCHEMES |= {
142142
# NOTE: When modifying "purelib" scheme, update site._get_path() too.
143143
'nt_user': {
144-
'stdlib': '{userbase}/lib/python{py_version_short}',
145-
'platstdlib': '{userbase}/lib/python{py_version_short}',
146-
'purelib': '{userbase}/lib/python{py_version_short}/site-packages',
147-
'platlib': '{userbase}/lib/python{py_version_short}/site-packages',
148-
'include': '{userbase}/include/python{py_version_short}',
144+
'stdlib': '{userbase}/lib/python{py_version_short_plat}',
145+
'platstdlib': '{userbase}/lib/python{py_version_short_plat}',
146+
'purelib': '{userbase}/lib/python{py_version_short_plat}/site-packages',
147+
'platlib': '{userbase}/lib/python{py_version_short_plat}/site-packages',
148+
'include': '{userbase}/include/python{py_version_short_plat}',
149149
'scripts': '{userbase}/bin',
150150
'data': '{userbase}',
151151
},
152152
'posix_user': {
153-
'stdlib': '{userbase}/{platlibdir}/python{py_version_short}',
154-
'platstdlib': '{userbase}/{platlibdir}/python{py_version_short}',
155-
'purelib': '{userbase}/lib/python{py_version_short}/site-packages',
156-
'platlib': '{userbase}/lib/python{py_version_short}/site-packages',
157-
'include': '{userbase}/include/python{py_version_short}',
153+
'stdlib': '{userbase}/{platlibdir}/python{py_version_short_plat}',
154+
'platstdlib': '{userbase}/{platlibdir}/python{py_version_short_plat}',
155+
'purelib': '{userbase}/lib/python{py_version_short_plat}/site-packages',
156+
'platlib': '{userbase}/lib/python{py_version_short_plat}/site-packages',
157+
'include': '{userbase}/include/python{py_version_short_plat}',
158158
'scripts': '{userbase}/bin',
159159
'data': '{userbase}',
160160
},
@@ -695,6 +695,10 @@ def _init_config_vars():
695695
_CONFIG_VARS['py_version_nodot_plat'] = sys.winver.replace('.', '')
696696
except AttributeError:
697697
_CONFIG_VARS['py_version_nodot_plat'] = ''
698+
if os.name == 'nt' and _POSIX_BUILD:
699+
_CONFIG_VARS['py_version_short_plat'] = f'{_PY_VERSION_SHORT}-{get_platform()}'
700+
else:
701+
_CONFIG_VARS['py_version_short_plat'] = _PY_VERSION_SHORT
698702

699703
if os.name == 'nt' and not _POSIX_BUILD:
700704
_init_non_posix(_CONFIG_VARS)
@@ -772,7 +776,7 @@ def get_config_var(name):
772776
"""
773777
return get_config_vars().get(name)
774778

775-
779+
# make sure to change site._get_platform() while changing this function
776780
def get_platform():
777781
"""Return a string that identifies the current platform.
778782

0 commit comments

Comments
 (0)