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.
This commit is contained in:
Éric Araujo 2011-08-30 01:42:50 +02:00
parent 83ab3f319b
commit b9fe54cccc
5 changed files with 28 additions and 34 deletions

View 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:

View 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()\

View 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:

View 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)

View File

@ -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.