[Python-checkins] distutils2: Make bdist_* commands respect --skip-build passed to bdist (#10946).

eric.araujo python-checkins at python.org
Mon Sep 19 15:12:39 CEST 2011


http://hg.python.org/distutils2/rev/95172b1c5498
changeset:   1166:95172b1c5498
user:        Éric Araujo <merwok at netwok.org>
date:        Mon Sep 19 03:58:52 2011 +0200
summary:
  Make bdist_* commands respect --skip-build passed to bdist (#10946).

There was already a test for this, but it was complicated and had a
subtle bug (custom command objects need to be put in dist.command_obj so
that other command objects may see them) that rendered it moot.

files:
  distutils2/command/bdist_dumb.py       |   5 +-
  distutils2/command/bdist_msi.py        |   6 +-
  distutils2/command/bdist_wininst.py    |   7 ++-
  distutils2/tests/test_command_bdist.py |  40 ++++---------
  4 files changed, 26 insertions(+), 32 deletions(-)


diff --git a/distutils2/command/bdist_dumb.py b/distutils2/command/bdist_dumb.py
--- a/distutils2/command/bdist_dumb.py
+++ b/distutils2/command/bdist_dumb.py
@@ -55,7 +55,7 @@
         self.format = None
         self.keep_temp = False
         self.dist_dir = None
-        self.skip_build = False
+        self.skip_build = None
         self.relative = False
         self.owner = None
         self.group = None
@@ -73,7 +73,8 @@
                     "don't know how to create dumb built distributions "
                     "on platform %s" % os.name)
 
-        self.set_undefined_options('bdist', 'dist_dir', 'plat_name')
+        self.set_undefined_options('bdist',
+                                   'dist_dir', 'plat_name', 'skip_build')
 
     def run(self):
         if not self.skip_build:
diff --git a/distutils2/command/bdist_msi.py b/distutils2/command/bdist_msi.py
--- a/distutils2/command/bdist_msi.py
+++ b/distutils2/command/bdist_msi.py
@@ -139,18 +139,22 @@
         self.no_target_optimize = False
         self.target_version = None
         self.dist_dir = None
-        self.skip_build = False
+        self.skip_build = None
         self.install_script = None
         self.pre_install_script = None
         self.versions = None
 
     def finalize_options(self):
+        self.set_undefined_options('bdist', 'skip_build')
+
         if self.bdist_dir is None:
             bdist_base = self.get_finalized_command('bdist').bdist_base
             self.bdist_dir = os.path.join(bdist_base, 'msi')
+
         short_version = get_python_version()
         if (not self.target_version) and self.distribution.has_ext_modules():
             self.target_version = short_version
+
         if self.target_version:
             self.versions = [self.target_version]
             if not self.skip_build and self.distribution.has_ext_modules()\
diff --git a/distutils2/command/bdist_wininst.py b/distutils2/command/bdist_wininst.py
--- a/distutils2/command/bdist_wininst.py
+++ b/distutils2/command/bdist_wininst.py
@@ -6,6 +6,7 @@
 import os
 
 from shutil import rmtree
+
 from distutils2.command.cmd import Command
 from distutils2.errors import PackagingOptionError, PackagingPlatformError
 from distutils2 import logger
@@ -67,13 +68,15 @@
         self.dist_dir = None
         self.bitmap = None
         self.title = None
-        self.skip_build = False
+        self.skip_build = None
         self.install_script = None
         self.pre_install_script = None
         self.user_access_control = None
 
 
     def finalize_options(self):
+        self.set_undefined_options('bdist', 'skip_build')
+
         if self.bdist_dir is None:
             if self.skip_build and self.plat_name:
                 # If build is skipped and plat_name is overridden, bdist will
@@ -83,8 +86,10 @@
                 # next the command will be initialized using that name
             bdist_base = self.get_finalized_command('bdist').bdist_base
             self.bdist_dir = os.path.join(bdist_base, 'wininst')
+
         if not self.target_version:
             self.target_version = ""
+
         if not self.skip_build and self.distribution.has_ext_modules():
             short_version = get_python_version()
             if self.target_version and self.target_version != short_version:
diff --git a/distutils2/tests/test_command_bdist.py b/distutils2/tests/test_command_bdist.py
--- a/distutils2/tests/test_command_bdist.py
+++ b/distutils2/tests/test_command_bdist.py
@@ -1,8 +1,6 @@
 """Tests for distutils.command.bdist."""
-
-from distutils2 import util
+import os
 from distutils2.command.bdist import bdist, show_formats
-
 from distutils2.tests import unittest, support, captured_stdout
 
 
@@ -10,22 +8,6 @@
                     support.LoggingCatcher,
                     unittest.TestCase):
 
-    def _mock_get_platform(self):
-        self._get_platform_called = True
-        return self._get_platform()
-
-    def setUp(self):
-        super(BuildTestCase, self).setUp()
-
-        # mock util.get_platform
-        self._get_platform_called = False
-        self._get_platform = util.get_platform
-        util.get_platform = self._mock_get_platform
-
-    def tearDown(self):
-        super(BuildTestCase, self).tearDown()
-        util.get_platform = self._get_platform
-
     def test_formats(self):
         # let's create a command and make sure
         # we can set the format
@@ -43,19 +25,21 @@
         self.assertEqual(found, formats)
 
     def test_skip_build(self):
-        dist = self.create_dist()[1]
-        cmd = bdist(dist)
-        cmd.skip_build = False
-        cmd.formats = ['zip']
-        cmd.ensure_finalized()
-        self.assertFalse(self._get_platform_called)
-
+        # bug #10946: bdist --skip-build should trickle down to subcommands
         dist = self.create_dist()[1]
         cmd = bdist(dist)
         cmd.skip_build = True
-        cmd.formats = ['zip']
         cmd.ensure_finalized()
-        self.assertTrue(self._get_platform_called)
+        dist.command_obj['bdist'] = cmd
+
+        names = ['bdist_dumb', 'bdist_wininst']
+        if os.name == 'nt':
+            names.append('bdist_msi')
+
+        for name in names:
+            subcmd = cmd.get_finalized_command(name)
+            self.assertTrue(subcmd.skip_build,
+                            '%s should take --skip-build from bdist' % name)
 
     def test_show_formats(self):
         __, stdout = captured_stdout(show_formats)

-- 
Repository URL: http://hg.python.org/distutils2


More information about the Python-checkins mailing list