diff options
Diffstat (limited to 'src/setup.py')
-rw-r--r-- | src/setup.py | 173 |
1 files changed, 145 insertions, 28 deletions
diff --git a/src/setup.py b/src/setup.py index 3c240a9..6aa673a 100644 --- a/src/setup.py +++ b/src/setup.py @@ -25,6 +25,7 @@ __revision__ = "__FILE__ __REVISION__ __DATE__ __DEVELOPER__" import os import os.path +import string import sys (head, tail) = os.path.split(sys.argv[0]) @@ -34,8 +35,10 @@ if head: sys.argv[0] = tail try: - from distutils.core import setup - from distutils.command.install_lib import install_lib + import distutils.core + import distutils.command.install + import distutils.command.install_lib + import distutils.command.install_scripts except ImportError: sys.stderr.write("""Could not import distutils. @@ -46,34 +49,141 @@ your system, or on how to install SCons from a different package. """) sys.exit(1) -class my_install_lib(install_lib): +_install = distutils.command.install.install +_install_lib = distutils.command.install_lib.install_lib +_install_scripts = distutils.command.install_scripts.install_scripts + +standard_lib = 0 +standalone_lib = 0 +version_lib = 0 + +installed_lib_dir = None +installed_scripts_dir = None + +def set_explicitly(name, args): + """ + Return if the installation directory was set explicitly by the + user on the command line. This is complicated by the fact that + "install --install-lib=/foo" gets turned into "install_lib + --install-dir=/foo" internally. + """ + if args[0] == "install_" + name: + s = "--install-dir=" + else: + # The command is something else (usually "install") + s = "--install-%s=" % name + set = 0 + length = len(s) + for a in args[1:]: + if a[:length] == s: + set = 1 + break + return set + +class install(_install): + user_options = _install.user_options + [ + ('standard-lib', None, + "install SCons library in standard Python location"), + ('standalone-lib', None, + "install SCons library in separate standalone directory"), + ('version-lib', None, + "install SCons library in version-specific directory") + ] + boolean_options = _install.boolean_options + [ + 'standard-lib', + 'standalone-lib', + 'version-lib' + ] + + def initialize_options(self): + _install.initialize_options(self) + self.standard_lib = 0 + self.standalone_lib = 0 + self.version_lib = 0 + def finalize_options(self): - install_lib.finalize_options(self) - head = self.install_dir - drive, head = os.path.splitdrive(self.install_dir) - while head: - if head == os.sep: - head = None - break - else: - head, tail = os.path.split(head) - if tail[:6] == "python": - self.install_dir = os.path.join(drive + head, "scons") - # Our original packaging scheme placed the build engine - # in a private library directory that contained the SCons - # version number in the directory name. Here's how this - # was supported here. See the Construct file for details - # on other files that would need to be changed to support - # this as well. - #self.install_dir = os.path.join(drive + head, "scons-__VERSION__") - return - elif tail[:6] == "Python": - self.install_dir = os.path.join(drive + head, tail) - return + _install.finalize_options(self) + global standard_lib, standalone_lib, version_lib + standard_lib = self.standard_lib + standalone_lib = self.standalone_lib + version_lib = self.version_lib + +def get_scons_prefix(libdir): + """ + Return the right prefix for SCons library installation. Find + this by starting with the library installation directory + (.../site-packages, most likely) and crawling back up until we reach + a directory name beginning with "python" (or "Python"). + """ + drive, head = os.path.splitdrive(libdir) + while head: + if head == os.sep: + break + head, tail = os.path.split(head) + if string.lower(tail)[:6] == "python": + # Found the Python library directory... + if sys.platform == "win32": + # ...on Win32 systems, "scons" goes in the directory: + # C:\PythonXX => C:\PythonXX\scons + return os.path.join(drive + head, tail) + else: + # ...on other systems, "scons" goes above the directory: + # /usr/lib/pythonX.X => /usr/lib/scons + return os.path.join(drive + head) + return libdir + +class install_lib(_install_lib): + def initialize_options(self): + _install_lib.initialize_options(self) + global standard_lib, standalone_lib, version_lib + self.standard_lib = standard_lib + self.standalone_lib = standalone_lib + self.version_lib = version_lib + + def finalize_options(self): + _install_lib.finalize_options(self) + if not set_explicitly("lib", self.distribution.script_args): + # They didn't explicitly specify the installation + # directory for libraries... + prefix = get_scons_prefix(self.install_dir) + standard_dir = os.path.join(self.install_dir, "SCons") + version_dir = os.path.join(prefix, "scons-0.11") + standalone_dir = os.path.join(prefix, "scons") + if self.version_lib: + # ...but they asked for a version-specific directory. + self.install_dir = version_dir + elif self.standalone_lib: + # ...but they asked for a standalone directory. + self.install_dir = standalone_dir + elif not self.standard_lib: + # ...and they didn't explicitly ask for the standard + # directory, so guess based on what's out there. + try: + e = filter(lambda x: x[:6] == "scons-", os.listdir(prefix)) + except: + e = None + if e: + # We found a path name (e.g.) /usr/lib/scons-XXX, + # so pick the version-specific directory. + self.install_dir = version_dir + elif os.path.exists(standalone_dir) or \ + not os.path.exists(standard_dir): + # There's already a standalone directory, or + # there's no SCons library in the standard + # directory, so go with the standalone. + self.install_dir = standalone_dir + global installed_lib_dir + installed_lib_dir = self.install_dir + +class install_scripts(_install_scripts): + def finalize_options(self): + _install_scripts.finalize_options(self) + global installed_scripts_dir + installed_scripts_dir = self.install_dir arguments = { 'name' : "scons", - 'version' : "__VERSION__", + 'version' : "0.11", 'packages' : ["SCons", "SCons.Node", "SCons.Optik", @@ -84,7 +194,9 @@ arguments = { "SCons.Tool"], 'package_dir' : {'' : 'engine'}, 'scripts' : ["script/scons"], - 'cmdclass' : {'install_lib' : my_install_lib} + 'cmdclass' : {'install' : install, + 'install_lib' : install_lib, + 'install_scripts' : install_scripts} } try: @@ -93,4 +205,9 @@ try: except IndexError: pass -apply(setup, (), arguments) +apply(distutils.core.setup, (), arguments) + +if installed_lib_dir: + print "Installed SCons library modules into %s" % installed_lib_dir +if installed_scripts_dir: + print "Installed SCons script into %s" % installed_scripts_dir |