Skip to content

Commit

Permalink
Change user site-packages path to include the environment info
Browse files Browse the repository at this point in the history
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
  • Loading branch information
naveen521kk committed Dec 27, 2024
1 parent ed53bd2 commit e7fb3ba
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 14 deletions.
28 changes: 25 additions & 3 deletions Lib/site.py
Original file line number Diff line number Diff line change
Expand Up @@ -314,6 +314,26 @@ def joinuser(*args):

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

# Copy of sysconfig.get_platform() but only for MinGW
def _get_platform():
if os.name == 'nt':
if 'gcc' in sys.version.lower():
if 'ucrt' in sys.version.lower():
if 'amd64' in sys.version.lower():
return 'mingw_x86_64_ucrt'
return 'mingw_i686_ucrt'
if 'clang' in sys.version.lower():
if 'amd64' in sys.version.lower():
return 'mingw_x86_64_clang'
if 'arm64' in sys.version.lower():
return 'mingw_aarch64'
if 'arm' in sys.version.lower():
return 'mingw_armv7'
return 'mingw_i686_clang'
if 'amd64' in sys.version.lower():
return 'mingw_x86_64'
return 'mingw_i686'
return sys.platform

# Same to sysconfig.get_path('purelib', os.name+'_user')
def _get_path(userbase):
Expand All @@ -325,9 +345,11 @@ def _get_path(userbase):

implementation = _get_implementation()
implementation_lower = implementation.lower()
if os.name == 'nt' and not _POSIX_BUILD:
ver_nodot = sys.winver.replace('.', '')
return f'{userbase}\\{implementation}{ver_nodot}\\site-packages'
if os.name == 'nt':
if not _POSIX_BUILD:
ver_nodot = sys.winver.replace('.', '')
return f'{userbase}\\{implementation}{ver_nodot}\\site-packages'
return f'{userbase}/lib/{implementation_lower}{version[0]}.{version[1]}-{_get_platform()}{abi_thread}/site-packages'

if sys.platform == 'darwin' and sys._framework:
return f'{userbase}/lib/{implementation_lower}/site-packages'
Expand Down
26 changes: 15 additions & 11 deletions Lib/sysconfig/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -144,20 +144,20 @@ def joinuser(*args):
_INSTALL_SCHEMES |= {
# NOTE: When modifying "purelib" scheme, update site._get_path() too.
'nt_user': {
'stdlib': '{userbase}/lib/{implementation}{py_version_short}{abi_thread}',
'platstdlib': '{userbase}/lib/{implementation}{py_version_short}{abi_thread}',
'purelib': '{userbase}/lib/{implementation}{py_version_short}{abi_thread}/site-packages',
'platlib': '{userbase}/lib/{implementation}{py_version_short}{abi_thread}/site-packages',
'include': '{userbase}/include/{implementation}{py_version_short}{abi_thread}',
'stdlib': '{userbase}/lib/{implementation}{py_version_short_plat}{abi_thread}',
'platstdlib': '{userbase}/lib/{implementation}{py_version_short_plat}{abi_thread}',
'purelib': '{userbase}/lib/{implementation}{py_version_short_plat}{abi_thread}/site-packages',
'platlib': '{userbase}/lib/{implementation}{py_version_short_plat}{abi_thread}/site-packages',
'include': '{userbase}/include/{implementation}{py_version_short_plat}{abi_thread}',
'scripts': '{userbase}/bin',
'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}',
},
Expand Down Expand Up @@ -493,6 +493,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 _POSIX_BUILD:
_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 _POSIX_BUILD:
_init_non_posix(_CONFIG_VARS)
Expand Down Expand Up @@ -583,7 +587,7 @@ def get_config_var(name):
"""
return get_config_vars().get(name)


# make sure to change site._get_platform() while changing this function
def get_platform():
"""Return a string that identifies the current platform.
Expand Down

0 comments on commit e7fb3ba

Please sign in to comment.