[Distutils] distutils 0.1 problem and fix

Greg Ward gward@cnri.reston.va.us
Thu, 30 Sep 1999 20:46:46 -0400


On 29 September 1999, Amos Latteier said:
> Three cheers for distutils 0.1!
> 
> Unfortunately it fails to install itself on my NT box.

Details, details.  You Windows people are so picky.  ;-)

> running install_py
> creating D:\Python1.5.2
> Traceback (innermost last):
>   File "setup.py", line 22, in ?
>     packages = ['distutils', 'distutils.command'],
[...yikes -- at least my tracebacks aren't as bad as JPython's...]
>   File "distutils\util.py", line 318, in copy_tree
>     mkpath (dst, verbose=verbose)
>   File "distutils\util.py", line 74, in mkpath
>     raise DistutilsFileError, "%s: %s" % (head, errstr)
> distutils.errors.DistutilsFileError: D:\Python1.5.2: File exists
> 
> 
> To fix this I changed line 317 of distutils/util.py to:
> 
>     if not dry_run and not os.path.exists(os.path.normpath(dst)):

Hmm, no, this is really mkpath's fault.  But thanks for reminding me
of the existence of normpath() -- somehow I forgot all about it.
Anyone on a Windows box with Python and the Distutils handy, please try
this out to see if I've fixed it.  First, verify the bug:

>>> from distutils.util import mkpath
>>> mkpath ("\blah\")

where "\blah" doesn't already exist on the current drive.  Should blow
up with that "File exists" error.  Try it without the trailing
backslash, too.

Now apply this patch (in "Distutils-0.1\distutils"):

*** util.py     1999/09/29 12:14:16     1.7
--- util.py     1999/10/01 00:25:18
***************
*** 39,40 ****
--- 39,42 ----

+     name = os.path.normpath (name)
+
      if os.path.isdir (name):
***************
*** 45,48 ****
      (head, tail) = os.path.split (name)
-     if not tail:                        # in case 'name' has trailing
slash
-         (head, tail) = os.path.split (head)
      tails = [tail]                      # stack of lone dirs to create
--- 47,48 ----

and try it again.  Try it with and without the trailing backslash, on
different and the same directories.

Of course, I'll do all this tomorrow at work, where I have access to a
Windows machine.  Let me know if you find other bugs in mkpath though -- 
this is a surprisingly tricky little thing to get right.

        Greg
-- 
Greg Ward - software developer                    gward@cnri.reston.va.us
Corporation for National Research Initiatives    
1895 Preston White Drive                           voice: +1-703-620-8990
Reston, Virginia, USA  20191-5434                    fax: +1-703-620-0913