]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
Make bdist_* commands respect --skip-build passed to bdist (#10946).
authorÉric Araujo <merwok@netwok.org>
Mon, 29 Aug 2011 23:42:50 +0000 (01:42 +0200)
committerÉric Araujo <merwok@netwok.org>
Mon, 29 Aug 2011 23:42:50 +0000 (01:42 +0200)
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.

Lib/packaging/command/bdist_dumb.py
Lib/packaging/command/bdist_msi.py
Lib/packaging/command/bdist_wininst.py
Lib/packaging/tests/test_command_bdist.py
Misc/NEWS

index ed83c8ec9511acb91e91fe6bff967dd294685a0f..d5773f01a7249d0963ea98a9bc7915264f2511fe 100644 (file)
@@ -55,7 +55,7 @@ class bdist_dumb(Command):
         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 @@ class bdist_dumb(Command):
                     "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:
index 493f8b34e346a62ea95da811a3e2544b2f2e4b78..eaeb458a8fc27bcf1388dc9fc24d32f29387dd20 100644 (file)
@@ -139,18 +139,22 @@ class bdist_msi(Command):
         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()\
index dbb74eaeadb54c352a77fce2dcd8fc48bcedb121..7dbb39b31170140d5a064ea8202fe2bec343bf66 100644 (file)
@@ -67,13 +67,15 @@ class bdist_wininst(Command):
         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 +85,10 @@ class bdist_wininst(Command):
                 # 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:
index fa4093cf3ca7531d80645095cf9d524e768453e6..dd10188391418aaa1e47a9050a5b3caecb3da31d 100644 (file)
@@ -1,8 +1,6 @@
 """Tests for distutils.command.bdist."""
-
-from packaging import util
+import os
 from packaging.command.bdist import bdist, show_formats
-
 from packaging.tests import unittest, support, captured_stdout
 
 
@@ -10,22 +8,6 @@ class BuildTestCase(support.TempdirManager,
                     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
@@ -35,7 +17,7 @@ class BuildTestCase(support.TempdirManager,
         cmd.ensure_finalized()
         self.assertEqual(cmd.formats, ['msi'])
 
-        # what format does bdist offer?
+        # what formats does bdist offer?
         # XXX hard-coded lists are not the best way to find available bdist_*
         # commands; we should add a registry
         formats = ['bztar', 'gztar', 'msi', 'tar', 'wininst', 'zip']
@@ -43,19 +25,21 @@ class BuildTestCase(support.TempdirManager,
         self.assertEqual(found, formats)
 
     def test_skip_build(self):
-        dist = self.create_dist()[1]
-        cmd = bdist(dist)
-        cmd.skip_build = False
-        cmd.formats = ['ztar']
-        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 = ['ztar']
         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)
index 5106f1fda7ca3bd7e054a7b043d39241008b709e..d08d94ec6966a05f83424261eb3dee6366ae779f 100644 (file)
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -269,7 +269,8 @@ Library
 -------
 
 - Issue #10946: The distutils commands bdist_dumb, bdist_wininst and bdist_msi
-  now respect a --skip-build option given to bdist.
+  now respect a --skip-build option given to bdist.  The packaging commands
+  were fixed too.
 
 - Issue #12287: Fix a stack corruption in ossaudiodev module when the FD is
   greater than FD_SETSIZE.