Proposed bdist_dumb fix

Here's a proposed patch to alleviate the bdist_dumb problem. (Patch also attached to bug #410541.) It adds a --from-root Boolean option to bdist_dumb. from-root defaults to true, in which case you get the current behaviour. If you set it to false, the archive is built from $base, not /, so you end up with an archive containing ./lib/python2.3/site-packages/my-package on Unix. On Windows you should end up with ./Lib/site-packages/mypackage, ./Include/mypackage.h, etc. Ditto for the Mac. The only problem is on Unix if $platbase is different from $base. For example, you're installing Python code into /usr/share and C extensions into /usr/local/. Here the code simply throws up its hands and raises an exception. Thoughts? Is this a good solution? Does it work as I expect on Windows and MacOS 9? --amk (www.amk.ca) I'll never be cruel to an electron in a particle accelerator again. -- The Doctor, in "The Pirate Planet" Index: bdist_dumb.py =================================================================== RCS file: /cvsroot/python/python/dist/src/Lib/distutils/command/bdist_dumb.py,v retrieving revision 1.22 diff -u -r1.22 bdist_dumb.py --- bdist_dumb.py 19 Nov 2002 13:12:28 -0000 1.22 +++ bdist_dumb.py 21 Nov 2002 19:35:10 -0000 @@ -33,9 +33,13 @@ "directory to put final built distributions in"), ('skip-build', None, "skip rebuilding everything (for testing/debugging)"), + ('from-root=', None, + "build the archive using paths from the root directory " + "and not relative paths " + "(default: true)"), ] - boolean_options = ['keep-temp', 'skip-build'] + boolean_options = ['keep-temp', 'skip-build', 'from-root'] default_format = { 'posix': 'gztar', 'nt': 'zip', @@ -49,7 +53,8 @@ self.keep_temp = 0 self.dist_dir = None self.skip_build = 0 - + self.from_root = 1 + # initialize_options() @@ -97,9 +102,29 @@ if os.name == "os2": archive_basename = archive_basename.replace(":", "-") - self.make_archive(os.path.join(self.dist_dir, archive_basename), - self.format, - root_dir=self.bdist_dir) + pseudoinstall_root = os.path.join(self.dist_dir, archive_basename) + if self.from_root: + archive_root = self.bdist_dir + else: + if (self.distribution.has_ext_modules() and + (install.install_base != install.install_platbase)): + raise DistutilsPlatformError, \ + ("can't make a dumb built distribution where " + "base and platbase are different (%s, %s)" + % (repr(install.install_base), + repr(install.install_platbase))) + else: + # install_base usually is a full path; we need to + # make it a relative path so it can be the second argument + # to os.path.join(). + t = install.install_base + if t[0:1] == os.sep: + t = t[1:] + archive_root = os.path.join(self.bdist_dir, t) + + # Make the archive + self.make_archive(pseudoinstall_root, + self.format, root_dir=archive_root) if not self.keep_temp: remove_tree(self.bdist_dir, dry_run=self.dry_run)

Andrew Kuchling <akuchlin@mems-exchange.org> writes:
Here's a proposed patch to alleviate the bdist_dumb problem. (Patch also attached to bug #410541.)
It adds a --from-root Boolean option to bdist_dumb. from-root defaults to true, in which case you get the current behaviour. If you set it to false, the archive is built from $base, not /, so you end up with an archive containing ./lib/python2.3/site-packages/my-package on Unix. On Windows you should end up with ./Lib/site-packages/mypackage, ./Include/mypackage.h, etc. Ditto for the Mac.
The only problem is on Unix if $platbase is different from $base. For example, you're installing Python code into /usr/share and C extensions into /usr/local/. Here the code simply throws up its hands and raises an exception.
Thoughts? Is this a good solution? Does it work as I expect on Windows and MacOS 9?
--amk (www.amk.ca) I'll never be cruel to an electron in a particle accelerator again. -- The Doctor, in "The Pirate Planet"
Index: bdist_dumb.py =================================================================== RCS file: /cvsroot/python/python/dist/src/Lib/distutils/command/bdist_dumb.py,v retrieving revision 1.22 diff -u -r1.22 bdist_dumb.py --- bdist_dumb.py 19 Nov 2002 13:12:28 -0000 1.22 +++ bdist_dumb.py 21 Nov 2002 19:35:10 -0000 @@ -33,9 +33,13 @@ "directory to put final built distributions in"), ('skip-build', None, "skip rebuilding everything (for testing/debugging)"), + ('from-root=', None, + "build the archive using paths from the root directory " + "and not relative paths " + "(default: true)"), ]
- boolean_options = ['keep-temp', 'skip-build'] + boolean_options = ['keep-temp', 'skip-build', 'from-root']
default_format = { 'posix': 'gztar', 'nt': 'zip', @@ -49,7 +53,8 @@ self.keep_temp = 0 self.dist_dir = None self.skip_build = 0 - + self.from_root = 1 + # initialize_options()
@@ -97,9 +102,29 @@ if os.name == "os2": archive_basename = archive_basename.replace(":", "-")
- self.make_archive(os.path.join(self.dist_dir, archive_basename), - self.format, - root_dir=self.bdist_dir) + pseudoinstall_root = os.path.join(self.dist_dir, archive_basename) + if self.from_root: + archive_root = self.bdist_dir + else: + if (self.distribution.has_ext_modules() and + (install.install_base != install.install_platbase)): + raise DistutilsPlatformError, \ + ("can't make a dumb built distribution where " + "base and platbase are different (%s, %s)" + % (repr(install.install_base), + repr(install.install_platbase))) + else: + # install_base usually is a full path; we need to + # make it a relative path so it can be the second argument + # to os.path.join(). + t = install.install_base + if t[0:1] == os.sep: + t = t[1:] + archive_root = os.path.join(self.bdist_dir, t) + + # Make the archive + self.make_archive(pseudoinstall_root, + self.format, root_dir=archive_root)
if not self.keep_temp: remove_tree(self.bdist_dir, dry_run=self.dry_run)
_______________________________________________ Distutils-SIG maillist - Distutils-SIG@python.org http://mail.python.org/mailman/listinfo/distutils-sig

[Sorry for the previous one, still sometimes having problems with gnus] Andrew Kuchling <akuchlin@mems-exchange.org> writes:
Here's a proposed patch to alleviate the bdist_dumb problem. (Patch also attached to bug #410541.)
This code doesn't work unchanged on Windows:
+ else: + # install_base usually is a full path; we need to + # make it a relative path so it can be the second argument + # to os.path.join(). + t = install.install_base + if t[0:1] == os.sep: + t = t[1:] + archive_root = os.path.join(self.bdist_dir, t)
't[0:1] == os.sep' is not a valid test for an absolute pathname, those contain drive letters on Windows. This will work, and should also work on other platforms if I understand the docs for splitdrive() correctly. else: # install_base usually is a full path; we need to # make it a relative path so it can be the second argument # to os.path.join(). t = install.install_base # on systems where a drive letter is used, split it off _, t = os.path.splitdrive(t) if t[0:1] == os.sep: t = t[1:] archive_root = os.path.join(self.bdist_dir, t) I has to use '--from-root 0' command-line flag, is it supposed to work this way, needing an argument? The paths in the zip then start with 'Lib/site-packages' and 'Scripts'. Haven't yet tried older python versions, where Lib/site-packages was not yet used, see PEP 250. Thomas

On Thu, Nov 21, 2002 at 09:28:28PM +0100, Thomas Heller wrote:
This will work, and should also work on other platforms if I understand the docs for splitdrive() correctly.
Incorporated in an updated version of the patch; thanks!
I has to use '--from-root 0' command-line flag, is it supposed to work this way, needing an argument?
Well, if we want to stay backward compatible with the old behaviour, from-root has to default to true, so you need to supply an argument of 0 to turn it off. Do we feel comfortable changing the default to false? (I don't have a problem with that, and have done so in the revised patch.) Or we could turn the option around and have it be a --relative option instead.
The paths in the zip then start with 'Lib/site-packages' and 'Scripts'. Haven't yet tried older python versions, where Lib/site-packages was not yet used, see PEP 250.

I has to use '--from-root 0' command-line flag, is it supposed to work this way, needing an argument?
Well, if we want to stay backward compatible with the old behaviour, from-root has to default to true, so you need to supply an argument of 0 to turn it off. Do we feel comfortable changing the default to false? (I don't have a problem with that, and have done so in the revised patch.) Or we could turn the option around and have it be a --relative option instead. I don't care too much - won't use it anyway. Otherwise I would probably like --relative more.
What surprised me is that you have to supply an argument to a boolean option. bdist_wininst has a --keep-temp boolean flag, but this doesn't need an argument. Neither does --verbose or --quiet. Thomas

't[0:1] == os.sep' is not a valid test for an absolute pathname, those contain drive letters on Windows. This will work, and should also work on other platforms if I understand the docs for splitdrive() correctly.
else: # install_base usually is a full path; we need to # make it a relative path so it can be the second argument # to os.path.join(). t = install.install_base # on systems where a drive letter is used, split it off _, t = os.path.splitdrive(t) if t[0:1] == os.sep: t = t[1:] archive_root = os.path.join(self.bdist_dir, t)
This still isn't completely correct. To really identify an absolute pathname, you should use the os.path.isabs() function provided for that purpose: _, t = os.path.splitdrive(t) if os.path.isabs(t): t = t[1:] archive_root = os.path.join(self.bdist_dir, t) Directly examining the first character loses on some systems. Old MacOS path names use a leading separator (:) to specify a *relative* path name, for example. --SK

On Thu, Nov 21, 2002 at 03:05:25PM -0600, Steven Knight wrote:
_, t = os.path.splitdrive(t) if os.path.isabs(t): t = t[1:] archive_root = os.path.join(self.bdist_dir, t)
Directly examining the first character loses on some systems. Old MacOS path names use a leading separator (:) to specify a *relative* path name, for example.
Hm, so won't this code still be incorrect on the Mac? Will it have to be something like this? if os.path.isabs(t): if platform == 'macos': t = os.sep + t else: t = t[1:] --amk

_, t = os.path.splitdrive(t) if os.path.isabs(t): t = t[1:] archive_root = os.path.join(self.bdist_dir, t)
Directly examining the first character loses on some systems. Old MacOS path names use a leading separator (:) to specify a *relative* path name, for example.
Hm, so won't this code still be incorrect on the Mac? Will it have to be something like this?
if os.path.isabs(t): if platform == 'macos': t = os.sep + t else: t = t[1:]
You're right. I paid too much attention to the problem with the test and didn't think through the solution properly. Good catch; apologies for the oversight on my part. --SK
participants (4)
-
A.M. Kuchling
-
Andrew Kuchling
-
Steven Knight
-
Thomas Heller