[Distutils] Re: Distutil BUG in RC1 !!

Guido van Rossum guido@digicool.com
Sat Apr 14 12:16:02 2001


> i'm guessing this is kind of urgent, i just found a bug in
> the distutils that came with my recently downloaded Python2.1C1
> i installed on windows, using the win-installer for 2.1c1
> 
> here's the quick and dirty details...
> 
> in the file "lib/distutils/archive-util.py" line 103, it creates
> a ZIP archive with the following command...
> 
> ZipFile(zip_filename, "wb", compression=zipfile.ZIP_DEFLATED)
> 
> 
> the problem here is the file mode, "wb". the zipfile.py that comes
> with 2.1c1 only allows the following file modes; "r", "w", or "a".
> this can be seen at line 166 in "lib/zipfile.py"
> 
>             modeDict = {'r' : 'rb', 'w': 'wb', 'a' : 'r+b'}
>             self.fp = open(file, modeDict[mode])
> 
> 
> 
> personally, i would think it better to make the zipfile smart enough
> to handle "wb" as a mode, but it certainly does not. anyways, the 
> "sdist" command fails when building a zipfile because of this.
> 
> 
> please, someone tell me this won't be found when the final Python-2.1
> is released in a few days. i'll mail out a full scale assault-style
> warning if there's still no news by the 16th. but i figure it can be
> handled most quickly and cleanly right here and now in disutils-sig

Thanks for reporting.  Fixing modeDict in zipfile.py isn't enough,
because there are other places where it relies on the key being one of
'r', 'w', or 'a'.  So I propose this fix to archive-util.py:

*** archive_util.py	2000/09/26 02:13:49	1.9
--- archive_util.py	2001/04/14 16:15:14
***************
*** 100,106 ****
                      z.write(path, path)
  
          if not dry_run:
!             z = zipfile.ZipFile(zip_filename, "wb",
                                  compression=zipfile.ZIP_DEFLATED)
  
              os.path.walk(base_dir, visit, z)
--- 100,106 ----
                      z.write(path, path)
  
          if not dry_run:
!             z = zipfile.ZipFile(zip_filename, "w",
                                  compression=zipfile.ZIP_DEFLATED)
  
              os.path.walk(base_dir, visit, z)

I will check this in now.  I can't test it though, so please let me
know whether this solves the problem.

--Guido van Rossum (home page: http://www.python.org/~guido/)