[Distutils] some small bugs

Thomas Heller thomas.heller@ion-tof.com
Wed Aug 30 09:41:02 2000


> > > If your distribution directory for bdist
> > > doesn't exist, distutils doesn't create
> > > it. (Even the default 'dist', so distutils
> > > fails if you use bdist for the first time.)
> >
> > Oops!  Only a problem in bdist_dumb, because the other bdist commands
> > just happen to use sdist, which did call 'mkpath()' properly.  Anyways,
> > I've fixed the problem by adding a couple of 'mkpath()' calls to
> > archive_util.py, which should handle all future tarball-and-zip-file-
> > generating commands.
>
> bdist_wininst has the same problem.
>
> The patch fixes this. It also changes two other problems.
> First it raises an PlatformException if you try to use it with
> modules which contain compiled C-extensions. Distutils doesn't
> support crosscompiling.
> The second changes the directory of the ini-file which is
> created. It is now created in the dist directory instead in
> the current.

Thanks for finding this (and for looking at bdist_wininst at all).
I've applied your patches to my version of bdist_wininst, with one
exception: The ini-data is no longer written to a separate file at all,
this was more or less for debugging.

Thomas

The patch now is:
Index: bdist_wininst.py
===================================================================
RCS file: /cvsroot/python/distutils/distutils/command/bdist_wininst.py,v
retrieving revision 1.7
diff -c -r1.7 bdist_wininst.py
*** bdist_wininst.py 2000/08/27 20:44:13 1.7
--- bdist_wininst.py 2000/08/30 13:39:23
***************
*** 63,68 ****
--- 63,77 ----


      def run (self):
+         if (sys.platform <> "win32" and
+             ( self.distribution.has_ext_modules()
+               or self.distribution.has_c_libraries()
+               or self.distribution.has_scripts())):
+             raise DistutilsPlatformError (
+                 # first line is shorter because it is
+                 # preceeded by the exception class
+                 """*** If your module contains compiled
+ extensions, you have to build the win32 installer on a win32 platform.""")

          self.run_command ('build')

***************
*** 103,123 ****

      # run()

!     def create_inifile (self):
!         # Create an inifile containing data describing the installation.
!         # This could be done without creating a real file, but
!         # a file is (at least) useful for debugging bdist_wininst.

          metadata = self.distribution.metadata
-         ini_name = "%s.ini" % metadata.get_fullname()

-         self.announce ("creating %s" % ini_name)
-         inifile = open (ini_name, "w")
-
          # Write the [metadata] section.  Values are written with
          # repr()[1:-1], so they do not contain unprintable characters, and
          # are not surrounded by quote chars.
!         inifile.write ("[metadata]\n")

          # 'info' will be displayed in the installer's dialog box,
          # describing the items to be installed.
--- 112,127 ----

      # run()

!     def get_inidata (self):
!         # Return data describing the installation.

+         lines = []
          metadata = self.distribution.metadata

          # Write the [metadata] section.  Values are written with
          # repr()[1:-1], so they do not contain unprintable characters, and
          # are not surrounded by quote chars.
!         lines.append ("[metadata]")

          # 'info' will be displayed in the installer's dialog box,
          # describing the items to be installed.
***************
*** 129,155 ****
                  if data:
                     info = info + ("\n    %s: %s" % \
                                    (string.capitalize (name), data))
!                    inifile.write ("%s=%s\n" % (name, repr (data)[1:-1]))

          # The [setup] section contains entries controlling
          # the installer runtime.
!         inifile.write ("\n[Setup]\n")
!         inifile.write ("info=%s\n" % repr (info)[1:-1])
!         inifile.write ("pthname=%s.%s\n" % (metadata.name,
metadata.version))
          if self.target_version:
!             inifile.write ("target_version=%s\n" % self.target_version)

          title = self.distribution.get_fullname()
!         inifile.write ("title=%s\n" % repr (title)[1:-1])
!         inifile.close()
!         return ini_name

!     # create_inifile()

      def create_exe (self, arcname, fullname):
!         import struct#, zlib

!         cfgdata = open (self.create_inifile()).read()

          installer_name = os.path.join(self.dist_dir,
                                        "%s.win32.exe" % fullname)
--- 133,160 ----
                  if data:
                     info = info + ("\n    %s: %s" % \
                                    (string.capitalize (name), data))
!                    lines.append ("%s=%s" % (name, repr (data)[1:-1]))

          # The [setup] section contains entries controlling
          # the installer runtime.
!         lines.append ("\n[Setup]")
!         lines.append ("info=%s" % repr (info)[1:-1])
!         lines.append ("pthname=%s.%s" % (metadata.name, metadata.version))
          if self.target_version:
!             lines.append ("target_version=%s" % self.target_version)

          title = self.distribution.get_fullname()
!         lines.append ("title=%s" % repr (title)[1:-1])
!         return string.join (lines, "\n")

!     # get_inidata()

      def create_exe (self, arcname, fullname):
!         import struct
!
!         self.mkpath(self.dist_dir)

!         cfgdata = self.get_inidata()

          installer_name = os.path.join(self.dist_dir,
                                        "%s.win32.exe" % fullname)