[Python-checkins] CVS: distutils/distutils/command install.py,1.21,1.22

Greg Ward python-dev@python.org
Tue, 25 Apr 2000 22:38:05 -0400 (EDT)


Update of /projects/cvsroot/distutils/distutils/command
In directory newcnri:/tmp/cvs-serv22560/distutils/command

Modified Files:
	install.py 
Log Message:
Hacked things up a bit so that configuration variables are expanded
in command-line options, and in two phases at that: first, we expand
'install_base' and 'install_platbase', and then the other 'install_*'
options.  This lets us do tricky stuff like
    install --prefix='/tmp$sys_prefix'
...oooh, neat.

Simplified 'select_scheme()' -- it's no longer responsible for expanding
config vars, tildes, etc.

Define installation-specific config vars in 'self.config_vars', rather than
in a local dictionary of one method.  Also factored '_expand_attrs()' out
of 'expand_dirs()' and added 'expand_basedirs()'.

Added a bunch of debugging output so I (and others) can judge the
success of this crazy scheme through direct feedback.


Index: install.py
===================================================================
RCS file: /projects/cvsroot/distutils/distutils/command/install.py,v
retrieving revision 1.21
retrieving revision 1.22
diff -C2 -r1.21 -r1.22
*** install.py	2000/03/31 02:52:02	1.21
--- install.py	2000/04/26 02:38:01	1.22
***************
*** 5,13 ****
  # created 1999/03/13, Greg Ward
  
! __revision__ = "$Id: install.py,v 1.21 2000/03/31 02:52:02 gward Exp $"
  
  import sys, os, string
  from types import *
  from distutils.core import Command
  from distutils.util import write_file, native_path, subst_vars
  from distutils.errors import DistutilsOptionError
--- 5,14 ----
  # created 1999/03/13, Greg Ward
  
! __revision__ = "$Id: install.py,v 1.22 2000/04/26 02:38:01 gward Exp $"
  
  import sys, os, string
  from types import *
  from distutils.core import Command
+ from distutils import sysconfig
  from distutils.util import write_file, native_path, subst_vars
  from distutils.errors import DistutilsOptionError
***************
*** 183,186 ****
--- 184,191 ----
          # INSTALL_SCHEME dictionary above.  Phew!
  
+         from pprint import pprint
+         print "pre-finalize:"
+         pprint (self.__dict__)
+ 
          if os.name == 'posix':
              self.finalize_unix ()
***************
*** 188,195 ****
--- 193,228 ----
              self.finalize_other ()
  
+         print "post-finalize:"
+         pprint (self.__dict__)
+ 
+         # Expand configuration variables, tilde, etc. in self.install_base
+         # and self.install_platbase -- that way, we can use $base or
+         # $platbase in the other installation directories and not worry
+         # about needing recursive variable expansion (shudder).
+ 
+         self.config_vars = {'py_version_short': sys.version[0:3],
+                             'sys_prefix': sysconfig.PREFIX,
+                             'sys_exec_prefix': sysconfig.EXEC_PREFIX,
+                            }
+         self.expand_basedirs ()
+ 
+         print "post-expand_basedirs:"
+         pprint (self.__dict__)
+ 
+         # Now define config vars for the base directories so we can expand
+         # everything else.
+         self.config_vars['base'] = self.install_base
+         self.config_vars['platbase'] = self.install_platbase
+ 
+         print "config vars:"
+         pprint (self.config_vars)
+ 
          # Expand "~" and configuration variables in the installation
          # directories.
          self.expand_dirs ()
  
+         print "post-expand:"
+         pprint (self.__dict__)
+ 
          # Pick the actual directory to install all modules to: either
          # install_purelib or install_platlib, depending on whether this
***************
*** 289,326 ****
  
      def select_scheme (self, name):
- 
-         # "select a scheme" means:
-         #   - set install-base and install-platbase
-         #   - subst. base/platbase/version into the values of the
-         #     particular scheme dictionary
-         #   - use the resultings strings to set install-lib, etc.
- 
          # it's the caller's problem if they supply a bad name!
          scheme = INSTALL_SCHEMES[name]
  
-         vars = { 'base': self.install_base,
-                  'platbase': self.install_platbase,
-                  'py_version_short': sys.version[0:3],
-                }
  
!         for key in ('purelib', 'platlib', 'scripts', 'data'):
!             val = subst_vars (scheme[key], vars)
!             setattr (self, 'install_' + key, val)
  
  
!     def expand_dirs (self):
  
!         # XXX probably don't want to 'expanduser()' on Windows or Mac
!         # XXX should use 'util.subst_vars()' with our own set of
!         #     configuration variables
! 
!         for att in ('base', 'platbase',
!                     'purelib', 'platlib', 'lib',
!                     'scripts', 'data'):
!             fullname = "install_" + att
!             val = getattr (self, fullname)
!             if val is not None:
!                 setattr (self, fullname,
!                          os.path.expandvars (os.path.expanduser (val)))
  
  
--- 322,351 ----
  
      def select_scheme (self, name):
          # it's the caller's problem if they supply a bad name!
          scheme = INSTALL_SCHEMES[name]
+         for key in ('purelib', 'platlib', 'scripts', 'data'):
+             setattr (self, 'install_' + key, scheme[key])
  
  
!     def _expand_attrs (self, attrs):
!         for attr in attrs:
!             val = getattr (self, attr)
!             if val is not None:
!                 if os.name == 'posix':
!                     val = os.path.expanduser (val)
!                 val = subst_vars (val, self.config_vars)
!                 setattr (self, attr, val)
  
  
!     def expand_basedirs (self):
!         self._expand_attrs (['install_base',
!                              'install_platbase'])        
  
!     def expand_dirs (self):
!         self._expand_attrs (['install_purelib',
!                              'install_platlib',
!                              'install_lib',
!                              'install_scripts',
!                              'install_data',])