Patch for util.py (was: Re: [Distutils] bdist broken under Windows)

Thomas Heller thomas.heller@ion-tof.com
Tue, 30 May 2000 20:22:57 +0200


[I was wondering about the purpose of change_root(), and Greg wrote]

>     The purpose of 'change_root()' is to change (eg.)
> "/usr/lib/python1.5/site-package/distutils" (where the "install" command
> would normally install the distutils on a Red Hat system) to
        ^^^^^^^^
> "build/bdist.linux2-i586/dumb/usr/lib/python1.5/site-packages/distutils"
> (where it gets installed to create a "dumb" built distribution -- we cd
> to "build/bdist.linux2-i586/dumb" and then create a tarball or zip file
> which is meant to be unpacked from the root directory).

What would the user do with such an archive when his python-site-packages
are to be installed into "/usr/local/lib/python1.5/site-packages" ?

Converting this into the windows world:

Normally python1.5 is installed into
"C:\Program Files\Python".
So the bdist-created archive would contain filenames like
"C:\Program Files\Python\distutils\..."

On a german windows installation Python would be installed
(per default) in
"C:\Programme\Python"
On the other hand, users would have been able to nstall it into
"D:\Work\Python\1.5" or whatever they like.

So to me it seems like a bad idea to create archives containing pathnames
relative to the root directory.

Anyway, here is the relevant part of the implementation
of change_root on windows:
--------------------------------------
    elif os.name == 'nt':
        (root_drive, root_path) = os.path.splitdrive (new_root)
        (drive, path) = os.path.splitdrive (pathname)
        if path[0] == '\\':
            path = path[1:]
        return os.path.join (new_root, path)

--------------------------------------

With this fix I'm at least able to create bdist archives again
(albeit unusable ones, see above).

Another minor nit:
distutils\archive_util.py, function make_zipfile: The (nested) function
visit
should normpath() the generated path names, otherwise the created zipfile
contains pathnames like ".\distutils\archive_util.py" (Not nice at least).
------------------------------------------
        def visit (z, dirname, names):
            for name in names:
                path = os.path.join (dirname, name)
                path = os.path.normpath (path)
                ^^^ added line
                if os.path.isfile (path):
                    z.write (path, path)
------------------------------------------

Question:
Zip-files created under windows contain backslashes as path-separators.
Do we have to care about this?

Thomas

PS: As soon as the above problems have been cleared, I will prepare
a first release of bdist_wininst.py as discussed before.