classification
Title: bdist_dumb and --relative on Windows fails
Type: behavior Stage: resolved
Components: Distutils, Windows Versions: Python 3.4, Python 3.5, Python 2.7
process
Status: closed Resolution: out of date
Dependencies: Superseder:
Assigned To: tarek Nosy List: PatriceL, christopher.hogan, dstufft, eric.araujo, lacouture, mhammond, steve.dower, tarek, weck
Priority: normal Keywords:

Created on 2004-07-19 13:03 by mhammond, last changed 2021-02-03 18:16 by steve.dower. This issue is now closed.

Messages (8)
msg60531 - (view) Author: Mark Hammond (mhammond) * (Python committer) Date: 2004-07-19 13:03
The following setup.py file:
"""
from distutils.core import setup, Extension
setup(name="foo", scripts= ["foo.py"])
"""
(plus any 'foo.py') fails when creating a .zip binary
on windows:

>setup.py bdist_dumb --relative
running bdist_dumb
...
error: build\bdist.win32\dumb\e:src\python-2.3-cvs:
Invalid argument
msg60532 - (view) Author: Patrice LACOUTURE (lacouture) Date: 2005-02-02 16:43
Logged In: YES 
user_id=1120079

It seems related to the function ensure_relative
(distutils/dir_utils.py, line 217), that keeps the drive
name in the relative path built.

>>> ensure_relative("C:\\Python24")
"C:Python24"

It is called by bdist_dumb to manage the relative path
properly, but fails so.

I can't guess what was the original intent (maybe for some
other OS, maybe just a simple error?), but the following
change seems to fix the issue:

$ diff --from-file=dir_util.old.py dir_util.py
226c226
<             path = drive + path[1:]
---
>             path = path[1:]

(just skip the drive name and the initial os.sep if any).

The ensure_relative() function is only used by bdist_dumb,
so I believe this change is safe, unless the "bogus" line
had some hidden intent I couldn't figure (other OS???).
msg60533 - (view) Author: Patrice LACOUTURE (lacouture) Date: 2005-02-02 17:16
Logged In: YES 
user_id=1120079

BTW, the patch shown in my previous comment applies to
distutils/dir_util.py from Python 2.4.

226c226
<             path = drive + path[1:]
---
>             path = path[1:]
msg68816 - (view) Author: zouguangxian (weck) Date: 2008-06-27 05:44
I encounter the same problem of Mark Hammond. I check the code in
repository, the ensure_relative function in python25 is:

def ensure_relative (path):
    """Take the full path 'path', and make it a relative path so
    it can be the second argument to os.path.join().
    """
    drive, path = os.path.splitdrive(path)
    if sys.platform == 'mac':
        return os.sep + path
    else:
        if path[0:1] == os.sep:
            path = drive + path[1:]
        return path

I also checked python24, and didn't find the code which described by 
Patrice LACOUTURE in msg60533 (view).
msg227970 - (view) Author: Mark Lawrence (BreamoreBoy) * Date: 2014-09-30 18:35
Is this still a problem?  Normally I'd be perfectly happy to try something on Windows but the mere mention of distutils sends shivers down my spine :(
msg227992 - (view) Author: Patrice LACOUTURE (PatriceL) Date: 2014-09-30 19:59
I don't have any Windows box around to check, but I can see that there has been no change since then in this portion of code in branches 2.4, 2.7 and 3.4.

Therefore, this issue is very likely still there.
msg248968 - (view) Author: Chris Hogan (christopher.hogan) * Date: 2015-08-21 18:16
I think ensure_relative is incorrect. The comment in the function states:

 "Take the full path 'path', and make it a relative path. This is useful to make 'path' the second argument to os.path.join()."

However, according to the docs for os.path.join, if a component contains a drive letter, all previous components are thrown away and the drive letter is reset.  This makes the result from ensure_relative a poor candidate as a "second argument to os.path.join" on Windows because it will always contain a drive letter which will always wipe out the first argument.

>>> os.path.join('bar', 'c:foo')
'c:foo'

This is what happens when I try to build a simple distro with the command python setup.py bdist_dumb --relative. In Lib/distutils/command/bdist_dumb.py:bdist_dumb.run:

archive_root = os.path.join(self.bdist_dir, ensure_relative(install.install_base))

the call is

>>> os.path.join('build\\bdist.win-amd64\\dumb', 'C:path\\to\\python')
'C:path\\to\\python'

It seems to me that the intention is to return

'build\\bdist.win-amd64\\dumb\\path\\to\\python27'

Later in distutils.archive_util.make_archive, it tries to os.chdir into 'C:path\\to\\python', which it can't do because that's not an absolute path (it's missing a '\' after 'C:').
As far as I can tell, the only thing the --relative flag does is to append the python install path onto the build location and build the archive there. However, this build location is temporary and gets deleted at the end of the process, so I don't really see the point.

I think there are two options here: 
1) Get rid of ensure_relative and do it like this:

archive_root = os.path.join(self.bdist_dir, os.path.splitdrive(install.install_base)[1].lstrip(os.sep))

This is the only place ensure_relative is ever used anyway.

2) Keep ensure_relative and do it like this:

archive_root = os.path.join(self.bdist_dir, os.path.splitdrive(ensure_relative(install.install_base))[1])
msg386312 - (view) Author: Steve Dower (steve.dower) * (Python committer) Date: 2021-02-03 18:16
Distutils is now deprecated (see PEP 632) and all tagged issues are being closed. From now until removal, only release blocking issues will be considered for distutils.

If this issue does not relate to distutils, please remove the component and reopen it. If you believe it still requires a fix, most likely the issue should be re-reported at https://github.com/pypa/setuptools
History
Date User Action Args
2021-02-03 18:16:26steve.dowersetstatus: open -> closed

nosy: + steve.dower
messages: + msg386312

resolution: out of date
stage: needs patch -> resolved
2019-02-24 22:44:07BreamoreBoysetnosy: - BreamoreBoy
2015-08-21 18:16:14christopher.hogansetnosy: + christopher.hogan
messages: + msg248968
2014-09-30 19:59:37PatriceLsetnosy: + PatriceL
messages: + msg227992
2014-09-30 18:35:19BreamoreBoysetversions: + Python 3.4, Python 3.5, - Python 3.1, Python 3.2
nosy: + eric.araujo, dstufft, BreamoreBoy

messages: + msg227970

components: + Windows
2010-08-19 15:26:51BreamoreBoysetstage: needs patch
type: behavior
versions: + Python 3.1, Python 2.7, Python 3.2
2009-02-11 02:55:24ajaksu2setassignee: tarek
nosy: + tarek
2008-06-27 05:44:26wecksetnosy: + weck
messages: + msg68816
2004-07-19 13:03:59mhammondcreate