Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP] Install schemas #7

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
72 changes: 40 additions & 32 deletions Lib/distutils/command/install.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@
Implements the Distutils 'install' command."""

import sys
import sysconfig
import os
import re

from distutils import log
from distutils.core import Command
Expand All @@ -20,33 +22,44 @@

HAS_USER_SITE = (USER_SITE is not None)

WINDOWS_SCHEME = {
'purelib': '$base/Lib/site-packages',
'platlib': '$base/Lib/site-packages',
'headers': '$base/Include/$dist_name',
'scripts': '$base/Scripts',
'data' : '$base',
}

INSTALL_SCHEMES = {
'unix_prefix': {
'purelib': '$base/lib/python$py_version_short/site-packages',
'platlib': '$platbase/$platlibdir/python$py_version_short/site-packages',
'headers': '$base/include/python$py_version_short$abiflags/$dist_name',
'scripts': '$base/bin',
'data' : '$base',
},
'unix_home': {
'purelib': '$base/lib/python',
'platlib': '$base/$platlibdir/python',
'headers': '$base/include/python/$dist_name',
'scripts': '$base/bin',
'data' : '$base',
},
'nt': WINDOWS_SCHEME,
}

# user site schemes
# The keys to an installation scheme; if any new types of files are to be
# installed, be sure to add an entry to every installation scheme above,
# and to SCHEME_KEYS here.
SCHEME_KEYS = ('purelib', 'platlib', 'headers', 'scripts', 'data')

# The following code provides backward-compatible INSTALL_SCHEMES
# while making the sysconfig module the single point of truth.
# This makes it easier for OS distributions where they need to
# alter locations for packages installations on single place.
# This module is depracated anyway (PEP 632) so if anything
# doesn't work for you, take a look at sysconfig.
INSTALL_SCHEMES = {"unix_prefix": {}, "unix_home": {}, "nt": {}}

# Copy from sysconfig._INSTALL_SCHEMES
for key in SCHEME_KEYS:
sys_key = key
if key == "headers":
sys_key = "include"
INSTALL_SCHEMES["unix_prefix"][key] = sysconfig._INSTALL_SCHEMES["posix_prefix"][sys_key]
INSTALL_SCHEMES["unix_home"][key] = sysconfig._INSTALL_SCHEMES["posix_home"][sys_key]
INSTALL_SCHEMES["nt"][key] = sysconfig._INSTALL_SCHEMES["nt"][sys_key]

# Transformation to different template format
for main_key in INSTALL_SCHEMES:
for key, value in INSTALL_SCHEMES[main_key].items():
# Change all ocurences of {variable} to $variable
value = re.sub(r"\{(.+?)\}", r"$\g<1>", value)
value = value.replace("$installed_base", "$base")
value = value.replace("$py_version_nodot_plat", "$py_version_nodot")
if key == "headers":
value += "/$dist_name"
if key == "platlib":
value = value.replace("/lib/", "/$platlibdir/")
INSTALL_SCHEMES[main_key][key] = value

# The following part of INSTALL_SCHEMES has different definition
# that the one in sysconfig but because both depends on site module
# the outcomes should be the same.
if HAS_USER_SITE:
INSTALL_SCHEMES['nt_user'] = {
'purelib': '$usersite',
Expand All @@ -65,11 +78,6 @@
'data' : '$userbase',
}

# The keys to an installation scheme; if any new types of files are to be
# installed, be sure to add an entry to every installation scheme above,
# and to SCHEME_KEYS here.
SCHEME_KEYS = ('purelib', 'platlib', 'headers', 'scripts', 'data')


class install(Command):

Expand Down
9 changes: 8 additions & 1 deletion Lib/site.py
Original file line number Diff line number Diff line change
Expand Up @@ -378,8 +378,15 @@ def getsitepackages(prefixes=None):
return sitepackages

def addsitepackages(known_paths, prefixes=None):
"""Add site-packages to sys.path"""
"""Add site-packages to sys.path

'/usr/local' is included in PREFIXES if RPM build is not detected
to make packages installed into this location visible.

"""
_trace("Processing global site-packages")
if ENABLE_USER_SITE and 'RPM_BUILD_ROOT' not in os.environ:
PREFIXES.insert(0, "/usr/local")
for sitedir in getsitepackages(prefixes):
if os.path.isdir(sitedir):
addsitedir(sitedir, known_paths)
Expand Down
22 changes: 16 additions & 6 deletions Lib/sysconfig.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,22 @@
}


if (not (hasattr(sys, 'real_prefix') or
sys.prefix != sys.base_prefix) and
'RPM_BUILD_ROOT' not in os.environ):
_INSTALL_SCHEMES['posix_prefix'] = {
'stdlib': '{installed_base}/local/{platlibdir}/python{py_version_short}',
'platstdlib': '{platbase}/local/{platlibdir}/python{py_version_short}',
'purelib': '{base}/local/lib/python{py_version_short}/site-packages',
'platlib': '{platbase}/local/{platlibdir}/python{py_version_short}/site-packages',
'include':
'{installed_base}/local/include/python{py_version_short}{abiflags}',
'platinclude':
'{installed_platbase}/local/include/python{py_version_short}{abiflags}',
'scripts': '{base}/local/bin',
'data': '{base}/local',
}

# NOTE: site.py has copy of this function.
# Sync it when modify this function.
def _getuserbase():
Expand Down Expand Up @@ -176,12 +192,6 @@ def is_python_build(check_home=False):

_PYTHON_BUILD = is_python_build(True)

if _PYTHON_BUILD:
for scheme in ('posix_prefix', 'posix_home'):
_INSTALL_SCHEMES[scheme]['include'] = '{srcdir}/Include'
_INSTALL_SCHEMES[scheme]['platinclude'] = '{projectbase}/.'


def _subst_vars(s, local_vars):
try:
return s.format(**local_vars)
Expand Down