diff options
author | Tarek Ziadé <ziade.tarek@gmail.com> | 2010-07-22 12:50:05 (GMT) |
---|---|---|
committer | Tarek Ziadé <ziade.tarek@gmail.com> | 2010-07-22 12:50:05 (GMT) |
commit | 3679727939a9d25ccfe057e71e8a4b8be73d47ce (patch) | |
tree | 88326b8ec80cf57f51d2e093143e233ec4ce1be5 /Lib/distutils/command/install.py | |
parent | 5db0c94072abad10c9d2df99eefd1f51eb84f2bc (diff) | |
download | cpython-3679727939a9d25ccfe057e71e8a4b8be73d47ce.zip cpython-3679727939a9d25ccfe057e71e8a4b8be73d47ce.tar.gz cpython-3679727939a9d25ccfe057e71e8a4b8be73d47ce.tar.bz2 |
reverted distutils its 3.1 state. All new work is now happening in disutils2, and distutils is now feature-frozen.
Diffstat (limited to 'Lib/distutils/command/install.py')
-rw-r--r-- | Lib/distutils/command/install.py | 129 |
1 files changed, 74 insertions, 55 deletions
diff --git a/Lib/distutils/command/install.py b/Lib/distutils/command/install.py index e3e387a..2a905d9 100644 --- a/Lib/distutils/command/install.py +++ b/Lib/distutils/command/install.py @@ -7,17 +7,26 @@ __revision__ = "$Id$" import sys import os -from sysconfig import get_config_vars, get_paths, get_path, get_config_var - from distutils import log from distutils.core import Command from distutils.debug import DEBUG +from distutils.sysconfig import get_config_vars from distutils.errors import DistutilsPlatformError from distutils.file_util import write_file -from distutils.util import convert_path, change_root, get_platform +from distutils.util import convert_path, subst_vars, change_root +from distutils.util import get_platform from distutils.errors import DistutilsOptionError -# kept for backward compat, will be removed in 3.2 +# this keeps compatibility from 2.3 to 2.5 +if sys.version < "2.6": + USER_BASE = None + USER_SITE = None + HAS_USER_SITE = False +else: + from site import USER_BASE + from site import USER_SITE + HAS_USER_SITE = True + if sys.version < "2.2": WINDOWS_SCHEME = { 'purelib': '$base', @@ -50,21 +59,15 @@ INSTALL_SCHEMES = { 'scripts': '$base/bin', 'data' : '$base', }, - 'unix_user': { - 'purelib': '$usersite', - 'platlib': '$usersite', - 'headers': '$userbase/include/python$py_version_short/$dist_name', - 'scripts': '$userbase/bin', - 'data' : '$userbase', - }, 'nt': WINDOWS_SCHEME, - 'nt_user': { - 'purelib': '$usersite', - 'platlib': '$usersite', - 'headers': '$userbase/Python$py_version_nodot/Include/$dist_name', - 'scripts': '$userbase/Scripts', - 'data' : '$userbase', + 'mac': { + 'purelib': '$base/Lib/site-packages', + 'platlib': '$base/Lib/site-packages', + 'headers': '$base/Include/$dist_name', + 'scripts': '$base/Scripts', + 'data' : '$base', }, + 'os2': { 'purelib': '$base/Lib/site-packages', 'platlib': '$base/Lib/site-packages', @@ -72,26 +75,47 @@ INSTALL_SCHEMES = { 'scripts': '$base/Scripts', 'data' : '$base', }, - 'os2_home': { + } + +# user site schemes +if HAS_USER_SITE: + INSTALL_SCHEMES['nt_user'] = { + 'purelib': '$usersite', + 'platlib': '$usersite', + 'headers': '$userbase/Python$py_version_nodot/Include/$dist_name', + 'scripts': '$userbase/Scripts', + 'data' : '$userbase', + } + + INSTALL_SCHEMES['unix_user'] = { 'purelib': '$usersite', 'platlib': '$usersite', 'headers': '$userbase/include/python$py_version_short/$dist_name', 'scripts': '$userbase/bin', 'data' : '$userbase', - }, - } + } + + INSTALL_SCHEMES['mac_user'] = { + 'purelib': '$usersite', + 'platlib': '$usersite', + 'headers': '$userbase/$py_version_short/include/$dist_name', + 'scripts': '$userbase/bin', + 'data' : '$userbase', + } + INSTALL_SCHEMES['os2_home'] = { + 'purelib': '$usersite', + 'platlib': '$usersite', + 'headers': '$userbase/include/python$py_version_short/$dist_name', + 'scripts': '$userbase/bin', + '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') -# end of backward compat -def _subst_vars(s, local_vars): - try: - return s.format(**local_vars) - except KeyError: - try: - return s.format(**os.environ) - except KeyError as var: - raise AttributeError('{%s}' % var) class install(Command): @@ -158,10 +182,11 @@ class install(Command): boolean_options = ['compile', 'force', 'skip-build'] - user_options.append(('user', None, - "install in user site-package '%s'" % \ - get_path('purelib', '%s_user' % os.name))) - boolean_options.append('user') + if HAS_USER_SITE: + user_options.append(('user', None, + "install in user site-package '%s'" % USER_SITE)) + boolean_options.append('user') + negative_opt = {'no-compile' : 'compile'} @@ -191,8 +216,8 @@ class install(Command): self.install_lib = None # set to either purelib or platlib self.install_scripts = None self.install_data = None - self.install_userbase = get_config_var('userbase') - self.install_usersite = get_path('purelib', '%s_user' % os.name) + self.install_userbase = USER_BASE + self.install_usersite = USER_SITE self.compile = None self.optimize = None @@ -302,9 +327,7 @@ class install(Command): # about needing recursive variable expansion (shudder). py_version = sys.version.split()[0] - prefix, exec_prefix, srcdir, projectbase = get_config_vars('prefix', 'exec_prefix', - 'srcdir', 'projectbase') - + (prefix, exec_prefix) = get_config_vars('prefix', 'exec_prefix') self.config_vars = {'dist_name': self.distribution.get_name(), 'dist_version': self.distribution.get_version(), 'dist_fullname': self.distribution.get_fullname(), @@ -315,12 +338,12 @@ class install(Command): 'prefix': prefix, 'sys_exec_prefix': exec_prefix, 'exec_prefix': exec_prefix, - 'srcdir': srcdir, - 'projectbase': projectbase, } - self.config_vars['userbase'] = self.install_userbase - self.config_vars['usersite'] = self.install_usersite + if HAS_USER_SITE: + self.config_vars['userbase'] = self.install_userbase + self.config_vars['usersite'] = self.install_usersite + self.expand_basedirs() self.dump_dirs("post-expand_basedirs()") @@ -424,10 +447,10 @@ class install(Command): raise DistutilsPlatformError( "User base directory is not specified") self.install_base = self.install_platbase = self.install_userbase - self.select_scheme("posix_user") + self.select_scheme("unix_user") elif self.home is not None: self.install_base = self.install_platbase = self.home - self.select_scheme("posix_home") + self.select_scheme("unix_home") else: if self.prefix is None: if self.exec_prefix is not None: @@ -443,7 +466,7 @@ class install(Command): self.install_base = self.prefix self.install_platbase = self.exec_prefix - self.select_scheme("posix_prefix") + self.select_scheme("unix_prefix") def finalize_other(self): """Finalizes options for non-posix platforms""" @@ -455,7 +478,7 @@ class install(Command): self.select_scheme(os.name + "_user") elif self.home is not None: self.install_base = self.install_platbase = self.home - self.select_scheme("posix_home") + self.select_scheme("unix_home") else: if self.prefix is None: self.prefix = os.path.normpath(sys.prefix) @@ -470,15 +493,11 @@ class install(Command): def select_scheme(self, name): """Sets the install directories by applying the install schemes.""" # it's the caller's problem if they supply a bad name! - scheme = get_paths(name, expand=False) - for key, value in scheme.items(): - if key == 'platinclude': - key = 'headers' - value = os.path.join(value, self.distribution.get_name()) + scheme = INSTALL_SCHEMES[name] + for key in SCHEME_KEYS: attrname = 'install_' + key - if hasattr(self, attrname): - if getattr(self, attrname) is None: - setattr(self, attrname, value) + if getattr(self, attrname) is None: + setattr(self, attrname, scheme[key]) def _expand_attrs(self, attrs): for attr in attrs: @@ -486,7 +505,7 @@ class install(Command): if val is not None: if os.name == 'posix' or os.name == 'nt': val = os.path.expanduser(val) - val = _subst_vars(val, self.config_vars) + val = subst_vars(val, self.config_vars) setattr(self, attr, val) def expand_basedirs(self): |