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.
diff --git a/Lib/packaging/command/bdist_dumb.py b/Lib/packaging/command/bdist_dumb.py
index ed83c8e..d5773f0 100644
--- a/Lib/packaging/command/bdist_dumb.py
+++ b/Lib/packaging/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/Lib/packaging/command/bdist_msi.py b/Lib/packaging/command/bdist_msi.py
index 493f8b3..eaeb458 100644
--- a/Lib/packaging/command/bdist_msi.py
+++ b/Lib/packaging/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/Lib/packaging/command/bdist_wininst.py b/Lib/packaging/command/bdist_wininst.py
index dbb74ea..7dbb39b 100644
--- a/Lib/packaging/command/bdist_wininst.py
+++ b/Lib/packaging/command/bdist_wininst.py
@@ -67,13 +67,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 +85,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/Lib/packaging/tests/test_command_bdist.py b/Lib/packaging/tests/test_command_bdist.py
index fa4093c..dd10188 100644
--- a/Lib/packaging/tests/test_command_bdist.py
+++ b/Lib/packaging/tests/test_command_bdist.py
@@ -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 @@
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 @@
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 @@
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)
diff --git a/Misc/NEWS b/Misc/NEWS
index 5106f1f..d08d94e 100644
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -269,7 +269,8 @@
-------
- 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.