[Distutils] Patch for new install options

Harry Henry Gebel hgebel@inet.net
Tue, 25 Apr 2000 05:29:16 -0400


--YD3LsXFS42OYHhNZ
Content-Type: text/plain; charset=us-ascii
Content-Disposition: inline

It doesn't look like I will be done with bdist_rpm tonight, here is the
patch for the now install options; they are both intended to be run by RPM
or other packaging systems from within a .spec file (or equivalent)
(although the RPM process may have been launched by another setup.py) Some
things I would like different:

A better name for the file containing a list of installed files, or change
it to allow a file to be specified as part of the option.

Better help strings (I'm not good at help strings)

Mac and Windows support for --package-prefix, I didn't implement them
because I don't know the proper format for Windows and Mac paths to put in
INSTALL_SCHEME .

Is there a better way than using glob() to get a list of compiled
byte-code files? I know glob() is available in Windows Python because I
used it in a script I wrote for a friend of mine, but is it available in
Mac Python?

-- 
Harry Henry Gebel, Senior Developer, Landon House SBS
West Dover Hundred, Delaware

"Why do you look for the living among the dead?
He is not here, but has risen." 
Luke 24:5 (NRSV)

--YD3LsXFS42OYHhNZ
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment; filename="install_options.patch"

Index: distutils/command/install.py
===================================================================
RCS file: /projects/cvsroot/distutils/distutils/command/install.py,v
retrieving revision 1.21
diff -u -r1.21 install.py
--- install.py	2000/03/31 02:52:02	1.21
+++ install.py	2000/04/25 09:21:08
@@ -11,6 +11,7 @@
 from distutils.core import Command
 from distutils.util import write_file, native_path, subst_vars
 from distutils.errors import DistutilsOptionError
+from glob import glob
 
 INSTALL_SCHEMES = {
     'unix_prefix': {
@@ -19,6 +20,12 @@
         'scripts': '$base/bin',
         'data'   : '$base/share',
         },
+    'unix_package_prefix': {
+        'purelib': '$root/$base/lib/python$py_version_short/site-packages',
+        'platlib': '$root/$platbase/lib/python$py_version_short/site-packages',
+        'scripts': '$root/$base/bin',
+        'data'   : '$root/$base/share',
+        },
     'unix_home': {
         'purelib': '$base/lib/python',
         'platlib': '$base/lib/python',
@@ -53,6 +60,11 @@
         ('home=', None,
          "(Unix only) home directory to install under"),
 
+        # treats package prefix like root directory
+        ('package-prefix=', None,
+         "(For use by packaging systems) prefix is treated like " \
+         "root directory"),
+
         # Or, just set the base director(y|ies)
         ('install-base=', None,
          "base installation directory (instead of --prefix or --home)"),
@@ -79,6 +91,9 @@
         #('install-man=', None, "directory for Unix man pages"),
         #('install-html=', None, "directory for HTML documentation"),
         #('install-info=', None, "directory for GNU info files"),
+
+        ('record-install', None,
+         "make a record of installation")
         ]
 
 
@@ -113,6 +128,7 @@
         self.install_lib = None         # set to either purelib or platlib
         self.install_scripts = None
         self.install_data = None
+        self.package_prefix = None      # will be prepended to any other dirs
 
         # These two are for putting non-packagized distributions into their
         # own directory and creating a .pth file if it makes sense.
@@ -137,6 +153,7 @@
         #self.install_html = None
         #self.install_info = None
 
+        self.record_install = None
 
     def finalize_options (self):
 
@@ -166,6 +183,9 @@
                 raise DistutilsOptionError, \
                       ("must supply either home or prefix/exec-prefix -- " +
                        "not both")
+            if self.home and self.package_prefix:
+                 raise DistutilsOptionError, \
+                      ("cannot supply both home and package prefix")
         else:
             if self.exec_prefix:
                 self.warn ("exec-prefix option ignored on this platform")
@@ -173,6 +193,9 @@
             if self.home:
                 self.warn ("home option ignored on this platform")
                 self.home = None
+            if self.package_prefix: # for now
+                self.warn ("package-prefix option ignored on this platform")
+                self.package_prefix = None
 
         # Now the interesting logic -- so interesting that we farm it out
         # to other methods.  The goal of these methods is to set the final
@@ -263,7 +286,10 @@
 
             self.install_base = self.prefix
             self.install_platbase = self.exec_prefix
-            self.select_scheme ("unix_prefix")
+            if self.package_prefix:
+                self.select_scheme("unix_package_prefix")
+            else:
+                self.select_scheme ("unix_prefix")
 
     # finalize_unix ()
 
@@ -300,6 +326,7 @@
 
         vars = { 'base': self.install_base,
                  'platbase': self.install_platbase,
+                 'root': self.package_prefix,
                  'py_version_short': sys.version[0:3],
                }
 
@@ -379,6 +406,22 @@
                         "Python's module search path (sys.path) -- " +
                         "you'll have to change the search path yourself") %
                        self.install_lib)
+
+        # write list of installed files, if requested.
+        if self.record_install:
+            outputs = self.get_outputs()
+            for counter in xrange (len (outputs)): # include ".pyc" and ".pyo"
+                if outputs[counter][-3:] == ".py":
+                    byte_code = glob(outputs[counter] + '[co]')
+                    outputs.extend(byte_code)
+            outputs.sort() # just makes it look nicer
+            if self.package_prefix: # strip any package prefix
+                prefix_len = len(self.package_prefix) + 1
+                for counter in xrange (len (outputs)):
+                    outputs[counter] = outputs[counter][prefix_len:]
+            self.execute(write_file,
+                         ("INSTALLED_FILES", outputs),
+                         "Writing list of installed files")
 
     # run ()
 

--YD3LsXFS42OYHhNZ--