Skip to content

Commit

Permalink
pythongh-103708: Make directory layout in sysconfig implementation co…
Browse files Browse the repository at this point in the history
…nfigurable (python#103709)
  • Loading branch information
itsankitkp authored Dec 29, 2023
1 parent cf34b77 commit f46987b
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 39 deletions.
16 changes: 12 additions & 4 deletions Lib/site.py
Original file line number Diff line number Diff line change
Expand Up @@ -260,6 +260,10 @@ def check_enableusersite():
#
# See https://bugs.python.org/issue29585

# Copy of sysconfig._get_implementation()
def _get_implementation():
return 'Python'

# Copy of sysconfig._getuserbase()
def _getuserbase():
env_base = os.environ.get("PYTHONUSERBASE", None)
Expand All @@ -275,7 +279,7 @@ def joinuser(*args):

if os.name == "nt":
base = os.environ.get("APPDATA") or "~"
return joinuser(base, "Python")
return joinuser(base, _get_implementation())

if sys.platform == "darwin" and sys._framework:
return joinuser("~", "Library", sys._framework,
Expand All @@ -288,12 +292,14 @@ def joinuser(*args):
def _get_path(userbase):
version = sys.version_info

implementation = _get_implementation()
implementation_lower = implementation.lower()
if os.name == 'nt':
ver_nodot = sys.winver.replace('.', '')
return f'{userbase}\\Python{ver_nodot}\\site-packages'
return f'{userbase}\\{implementation}{ver_nodot}\\site-packages'

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

return f'{userbase}/lib/python{version[0]}.{version[1]}/site-packages'

Expand Down Expand Up @@ -361,14 +367,16 @@ def getsitepackages(prefixes=None):
continue
seen.add(prefix)

implementation = _get_implementation().lower()
ver = sys.version_info
if os.sep == '/':
libdirs = [sys.platlibdir]
if sys.platlibdir != "lib":
libdirs.append("lib")

for libdir in libdirs:
path = os.path.join(prefix, libdir,
"python%d.%d" % sys.version_info[:2],
f"{implementation}{ver[0]}.{ver[1]}",
"site-packages")
sitepackages.append(path)
else:
Expand Down
74 changes: 39 additions & 35 deletions Lib/sysconfig/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,24 +26,24 @@

_INSTALL_SCHEMES = {
'posix_prefix': {
'stdlib': '{installed_base}/{platlibdir}/python{py_version_short}',
'platstdlib': '{platbase}/{platlibdir}/python{py_version_short}',
'purelib': '{base}/lib/python{py_version_short}/site-packages',
'platlib': '{platbase}/{platlibdir}/python{py_version_short}/site-packages',
'stdlib': '{installed_base}/{platlibdir}/{implementation_lower}{py_version_short}',
'platstdlib': '{platbase}/{platlibdir}/{implementation_lower}{py_version_short}',
'purelib': '{base}/lib/{implementation_lower}{py_version_short}/site-packages',
'platlib': '{platbase}/{platlibdir}/{implementation_lower}{py_version_short}/site-packages',
'include':
'{installed_base}/include/python{py_version_short}{abiflags}',
'{installed_base}/include/{implementation_lower}{py_version_short}{abiflags}',
'platinclude':
'{installed_platbase}/include/python{py_version_short}{abiflags}',
'{installed_platbase}/include/{implementation_lower}{py_version_short}{abiflags}',
'scripts': '{base}/bin',
'data': '{base}',
},
'posix_home': {
'stdlib': '{installed_base}/lib/python',
'platstdlib': '{base}/lib/python',
'purelib': '{base}/lib/python',
'platlib': '{base}/lib/python',
'include': '{installed_base}/include/python',
'platinclude': '{installed_base}/include/python',
'stdlib': '{installed_base}/lib/{implementation_lower}',
'platstdlib': '{base}/lib/{implementation_lower}',
'purelib': '{base}/lib/{implementation_lower}',
'platlib': '{base}/lib/{implementation_lower}',
'include': '{installed_base}/include/{implementation_lower}',
'platinclude': '{installed_base}/include/{implementation_lower}',
'scripts': '{base}/bin',
'data': '{base}',
},
Expand Down Expand Up @@ -75,14 +75,14 @@
# Downstream distributors who patch posix_prefix/nt scheme are encouraged to
# leave the following schemes unchanged
'posix_venv': {
'stdlib': '{installed_base}/{platlibdir}/python{py_version_short}',
'platstdlib': '{platbase}/{platlibdir}/python{py_version_short}',
'purelib': '{base}/lib/python{py_version_short}/site-packages',
'platlib': '{platbase}/{platlibdir}/python{py_version_short}/site-packages',
'stdlib': '{installed_base}/{platlibdir}/{implementation_lower}{py_version_short}',
'platstdlib': '{platbase}/{platlibdir}/{implementation_lower}{py_version_short}',
'purelib': '{base}/lib/{implementation_lower}{py_version_short}/site-packages',
'platlib': '{platbase}/{platlibdir}/{implementation_lower}{py_version_short}/site-packages',
'include':
'{installed_base}/include/python{py_version_short}{abiflags}',
'{installed_base}/include/{implementation_lower}{py_version_short}{abiflags}',
'platinclude':
'{installed_platbase}/include/python{py_version_short}{abiflags}',
'{installed_platbase}/include/{implementation_lower}{py_version_short}{abiflags}',
'scripts': '{base}/bin',
'data': '{base}',
},
Expand All @@ -104,6 +104,8 @@
else:
_INSTALL_SCHEMES['venv'] = _INSTALL_SCHEMES['posix_venv']

def _get_implementation():
return 'Python'

# NOTE: site.py has copy of this function.
# Sync it when modify this function.
Expand All @@ -121,7 +123,7 @@ def joinuser(*args):

if os.name == "nt":
base = os.environ.get("APPDATA") or "~"
return joinuser(base, "Python")
return joinuser(base, _get_implementation())

if sys.platform == "darwin" and sys._framework:
return joinuser("~", "Library", sys._framework,
Expand All @@ -135,29 +137,29 @@ def joinuser(*args):
_INSTALL_SCHEMES |= {
# NOTE: When modifying "purelib" scheme, update site._get_path() too.
'nt_user': {
'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',
'stdlib': '{userbase}/{implementation}{py_version_nodot_plat}',
'platstdlib': '{userbase}/{implementation}{py_version_nodot_plat}',
'purelib': '{userbase}/{implementation}{py_version_nodot_plat}/site-packages',
'platlib': '{userbase}/{implementation}{py_version_nodot_plat}/site-packages',
'include': '{userbase}/{implementation}{py_version_nodot_plat}/Include',
'scripts': '{userbase}/{implementation}{py_version_nodot_plat}/Scripts',
'data': '{userbase}',
},
'posix_user': {
'stdlib': '{userbase}/{platlibdir}/python{py_version_short}',
'platstdlib': '{userbase}/{platlibdir}/python{py_version_short}',
'purelib': '{userbase}/lib/python{py_version_short}/site-packages',
'platlib': '{userbase}/lib/python{py_version_short}/site-packages',
'include': '{userbase}/include/python{py_version_short}',
'stdlib': '{userbase}/{platlibdir}/{implementation_lower}{py_version_short}',
'platstdlib': '{userbase}/{platlibdir}/{implementation_lower}{py_version_short}',
'purelib': '{userbase}/lib/{implementation_lower}{py_version_short}/site-packages',
'platlib': '{userbase}/lib/{implementation_lower}{py_version_short}/site-packages',
'include': '{userbase}/include/{implementation_lower}{py_version_short}',
'scripts': '{userbase}/bin',
'data': '{userbase}',
},
'osx_framework_user': {
'stdlib': '{userbase}/lib/python',
'platstdlib': '{userbase}/lib/python',
'purelib': '{userbase}/lib/python/site-packages',
'platlib': '{userbase}/lib/python/site-packages',
'include': '{userbase}/include/python{py_version_short}',
'stdlib': '{userbase}/lib/{implementation_lower}',
'platstdlib': '{userbase}/lib/{implementation_lower}',
'purelib': '{userbase}/lib/{implementation_lower}/site-packages',
'platlib': '{userbase}/lib/{implementation_lower}/site-packages',
'include': '{userbase}/include/{implementation_lower}{py_version_short}',
'scripts': '{userbase}/bin',
'data': '{userbase}',
},
Expand Down Expand Up @@ -459,6 +461,8 @@ def _init_config_vars():
_CONFIG_VARS['platbase'] = _EXEC_PREFIX
_CONFIG_VARS['projectbase'] = _PROJECT_BASE
_CONFIG_VARS['platlibdir'] = sys.platlibdir
_CONFIG_VARS['implementation'] = _get_implementation()
_CONFIG_VARS['implementation_lower'] = _get_implementation().lower()
try:
_CONFIG_VARS['abiflags'] = sys.abiflags
except AttributeError:
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Make hardcoded python name, a configurable parameter so that different implementations of python can override it instead of making huge diffs in sysconfig.py

0 comments on commit f46987b

Please sign in to comment.