[Distutils] pypi and easy_install

Phillip J. Eby pje at telecommunity.com
Sat Jan 19 20:08:20 CET 2008

At 01:46 PM 1/19/2008 -0500, Phillip J. Eby wrote:
>At 04:44 AM 1/19/2008 +0100, Giampaolo Rodola' wrote:
> >Ok, I tried to implement this and it is seems I made it.
> >The change permit to use the distutils "--formats=tar,gztar,bztar"
> >option without need of having tar/gzip/bzip2 utilities installed on
> >the system.
> >Don't know if distutils test suite includes tests for the part of code
> >I modified but Lib/test/test_distutils.py run successfully on Python
> >2.5.1.
> >
> >The only compression format currently left out is ztar.
> >I may be wrong but I haven't seen modules able to work with that
> >format in the Python stdlib.
> >
> >I'll wait for your review.
> >Tell me if you want me to open a ticket on the Python bug tracker to
> >let also other users review the patch, modify something or throw the
> >whole thing away. :-)
>That would probably be a good idea.  In the meantime, my only comment
>is that for consistency with make_zipfile, the code should work even
>if gzip, tarfile, or bz2 aren't importable.  That is, falling back to
>the old spawn-based methods if the relevant library or libraries are
>not available.  The comment at the top, after all, says "This module
>should be kept compatible with Python 2.1," and the tarfile and bz2
>modules weren't added until 2.3.  (I'm not sure when gzip was added.)

Oh, and if tarfile is present, you can open a tarfile for writing 
with 'w:gz' or 'w:bz2' to have it apply the compression while 
building, which is probably more efficient.  However, if the 
appropriate module isn't available, it'll raise a 
tarfile.CompressionError at creation time.  So the code could be 
something like:

         import tarfile
     except ImportError:
         tarfile = None

     if tarfile is not None:
         ext = compress_ext.get(compress, '')
             tar = tarfile.open(archive_name+ext, "w"+ext.replace('.',':'))
         except tarfile.CompressionError:
             tar = tarfile.open(archive_name, "w")
         if tar.name == archive_name+ext:
             return tar.name  # we're done
         # ... fall through to old compression code
         # old spawn() code to create tar

     # everything from here on is just the old archive_util code...

     if compress:

More information about the Distutils-SIG mailing list