From 84b8ed8a945aa010be33ec2ce033fe9172844d9d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=89ric=20Araujo?= Date: Mon, 29 Aug 2011 21:42:47 +0200 Subject: [PATCH 1/8] 3.3 whatsnew: fix markup, add stub for new crypt features --- Doc/whatsnew/3.3.rst | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/Doc/whatsnew/3.3.rst b/Doc/whatsnew/3.3.rst index de3f2ed2a0c..6fdc5aa9c15 100644 --- a/Doc/whatsnew/3.3.rst +++ b/Doc/whatsnew/3.3.rst @@ -91,6 +91,13 @@ versions. (:issue:`12100`) +crypt +----- + +Addition of salf and modular crypt format to the :mod:`crypt` module. + +(:issue:`10924`) + curses ------ @@ -184,7 +191,7 @@ in Python 3.2. sys --- -* The :mod:`sys` module has a new :func:`~sys.thread_info` :term:`struct +* The :mod:`sys` module has a new :data:`~sys.thread_info` :term:`struct sequence` holding informations about the thread implementation. (:issue:`11223`) From b741313ca80bad9f173a15ba6a1a1a28326ab5ce Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=89ric=20Araujo?= Date: Mon, 29 Aug 2011 21:43:48 +0200 Subject: [PATCH 2/8] Cleanup: use sys.version_info instead of convoluted hexversion lshifts --- Lib/packaging/command/build_ext.py | 17 ++++++----------- 1 file changed, 6 insertions(+), 11 deletions(-) diff --git a/Lib/packaging/command/build_ext.py b/Lib/packaging/command/build_ext.py index b0c3f16e836..c16b116afdd 100644 --- a/Lib/packaging/command/build_ext.py +++ b/Lib/packaging/command/build_ext.py @@ -606,8 +606,7 @@ class build_ext(Command): template = "python%d%d" if self.debug: template = template + '_d' - pythonlib = (template % - (sys.hexversion >> 24, (sys.hexversion >> 16) & 0xff)) + pythonlib = template % sys.version_info[:2] # don't extend ext.libraries, it may be shared with other # extensions, it is a reference to the original list return ext.libraries + [pythonlib] @@ -621,22 +620,19 @@ class build_ext(Command): # not at this time - AIM Apr01 #if self.debug: # template = template + '_d' - pythonlib = (template % - (sys.hexversion >> 24, (sys.hexversion >> 16) & 0xff)) + pythonlib = template % sys.version_info[:2] # don't extend ext.libraries, it may be shared with other # extensions, it is a reference to the original list return ext.libraries + [pythonlib] elif sys.platform[:6] == "cygwin": template = "python%d.%d" - pythonlib = (template % - (sys.hexversion >> 24, (sys.hexversion >> 16) & 0xff)) + pythonlib = template % sys.version_info[:2] # don't extend ext.libraries, it may be shared with other # extensions, it is a reference to the original list return ext.libraries + [pythonlib] elif sys.platform[:6] == "atheos": template = "python%d.%d" - pythonlib = (template % - (sys.hexversion >> 24, (sys.hexversion >> 16) & 0xff)) + pythonlib = template % sys.version_info[:2] # Get SHLIBS from Makefile extra = [] for lib in sysconfig.get_config_var('SHLIBS').split(): @@ -654,9 +650,8 @@ class build_ext(Command): else: if sysconfig.get_config_var('Py_ENABLE_SHARED'): - pythonlib = 'python{}.{}{}'.format( - sys.hexversion >> 24, (sys.hexversion >> 16) & 0xff, - sys.abiflags) + template = 'python%d%d' + sys.abiflags + pythonlib = template % sys.version_info[:2] return ext.libraries + [pythonlib] else: return ext.libraries From fbe37dfffe501973b1e998bca948748097857179 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=89ric=20Araujo?= Date: Mon, 29 Aug 2011 21:48:39 +0200 Subject: [PATCH 3/8] Make bdist_* commands respect --skip-build passed to bdist (#10946) --- Lib/distutils/command/bdist_dumb.py | 5 +-- Lib/distutils/command/bdist_msi.py | 6 +++- Lib/distutils/command/bdist_wininst.py | 6 +++- Lib/distutils/tests/test_bdist.py | 48 +++++++++++++++----------- Misc/NEWS | 3 ++ 5 files changed, 43 insertions(+), 25 deletions(-) diff --git a/Lib/distutils/command/bdist_dumb.py b/Lib/distutils/command/bdist_dumb.py index 170e8894616..1ab09d16163 100644 --- a/Lib/distutils/command/bdist_dumb.py +++ b/Lib/distutils/command/bdist_dumb.py @@ -47,7 +47,7 @@ class bdist_dumb(Command): self.format = None self.keep_temp = 0 self.dist_dir = None - self.skip_build = 0 + self.skip_build = None self.relative = 0 def finalize_options(self): @@ -65,7 +65,8 @@ class bdist_dumb(Command): self.set_undefined_options('bdist', ('dist_dir', 'dist_dir'), - ('plat_name', 'plat_name')) + ('plat_name', 'plat_name'), + ('skip_build', 'skip_build')) def run(self): if not self.skip_build: diff --git a/Lib/distutils/command/bdist_msi.py b/Lib/distutils/command/bdist_msi.py index b11957a7dc4..b3cfe9ceff7 100644 --- a/Lib/distutils/command/bdist_msi.py +++ b/Lib/distutils/command/bdist_msi.py @@ -130,18 +130,22 @@ class bdist_msi(Command): self.no_target_optimize = 0 self.target_version = None self.dist_dir = None - self.skip_build = 0 + 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', '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/distutils/command/bdist_wininst.py b/Lib/distutils/command/bdist_wininst.py index b7916e31a1e..e3ed3ad82c1 100644 --- a/Lib/distutils/command/bdist_wininst.py +++ b/Lib/distutils/command/bdist_wininst.py @@ -65,13 +65,15 @@ class bdist_wininst(Command): self.dist_dir = None self.bitmap = None self.title = None - self.skip_build = 0 + 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', '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 @@ -81,8 +83,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: diff --git a/Lib/distutils/tests/test_bdist.py b/Lib/distutils/tests/test_bdist.py index 94d40cc25b3..503a6e857df 100644 --- a/Lib/distutils/tests/test_bdist.py +++ b/Lib/distutils/tests/test_bdist.py @@ -1,41 +1,47 @@ """Tests for distutils.command.bdist.""" -import unittest -import sys import os -import tempfile -import shutil +import unittest from test.support import run_unittest -from distutils.core import Distribution from distutils.command.bdist import bdist from distutils.tests import support -from distutils.spawn import find_executable -from distutils import spawn -from distutils.errors import DistutilsExecError + class BuildTestCase(support.TempdirManager, unittest.TestCase): def test_formats(self): - # let's create a command and make sure - # we can fix the format - pkg_pth, dist = self.create_dist() + # we can set the format + dist = self.create_dist()[1] cmd = bdist(dist) cmd.formats = ['msi'] cmd.ensure_finalized() self.assertEqual(cmd.formats, ['msi']) - # what format bdist offers ? - # XXX an explicit list in bdist is - # not the best way to bdist_* commands - # we should add a registry - formats = ['rpm', 'zip', 'gztar', 'bztar', 'ztar', - 'tar', 'wininst', 'msi'] - formats.sort() - founded = list(cmd.format_command.keys()) - founded.sort() - self.assertEqual(founded, formats) + # what formats does bdist offer? + formats = ['bztar', 'gztar', 'msi', 'rpm', 'tar', + 'wininst', 'zip', 'ztar'] + found = sorted(cmd.format_command) + self.assertEqual(found, formats) + + def test_skip_build(self): + # bug #10946: bdist --skip-build should trickle down to subcommands + dist = self.create_dist()[1] + cmd = bdist(dist) + cmd.skip_build = 1 + cmd.ensure_finalized() + dist.command_obj['bdist'] = cmd + + names = ['bdist_dumb', 'bdist_wininst'] # bdist_rpm does not support --skip-build + 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_suite(): return unittest.makeSuite(BuildTestCase) diff --git a/Misc/NEWS b/Misc/NEWS index 4d285a3d7b8..c97a5a56f19 100644 --- a/Misc/NEWS +++ b/Misc/NEWS @@ -22,6 +22,9 @@ Core and Builtins Library ------- +- Issue #10946: The distutils commands bdist_dumb, bdist_wininst and bdist_msi + now respect a --skip-build option given to bdist. + - Issue #12287: Fix a stack corruption in ossaudiodev module when the FD is greater than FD_SETSIZE. From fb639295ac48ba22d89a12f0368c1877f3035bbe Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=89ric=20Araujo?= Date: Mon, 29 Aug 2011 22:03:46 +0200 Subject: [PATCH 4/8] =?UTF-8?q?Print=20all=20fields=20when=20calling=20?= =?UTF-8?q?=E2=80=9Cpysetup=20metadata=E2=80=9D=20without=20options.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit When called without option (“-f field” or “--all”), “pysetup metadata” didn’t do anything useful. Now it prints out all metadata fields. The “--all” option is removed. --- Doc/install/pysetup.rst | 2 +- Lib/packaging/run.py | 18 +++++++----------- 2 files changed, 8 insertions(+), 12 deletions(-) diff --git a/Doc/install/pysetup.rst b/Doc/install/pysetup.rst index b88c8e1780f..08ba08ed2e5 100644 --- a/Doc/install/pysetup.rst +++ b/Doc/install/pysetup.rst @@ -76,7 +76,7 @@ argument. :: Name: virtualenv - $ pysetup metadata virtualenv --all + $ pysetup metadata virtualenv Metadata-Version: 1.0 Name: diff --git a/Lib/packaging/run.py b/Lib/packaging/run.py index 8e117ed36b7..5b335831faf 100644 --- a/Lib/packaging/run.py +++ b/Lib/packaging/run.py @@ -71,8 +71,8 @@ positional arguments: """ metadata_usage = """\ -Usage: pysetup metadata [dist] [-f field ...] - or: pysetup metadata [dist] [--all] +Usage: pysetup metadata [dist] + or: pysetup metadata [dist] [-f field ...] or: pysetup metadata --help Print metadata for the distribution. @@ -81,8 +81,7 @@ positional arguments: dist installed distribution name optional arguments: - -f metadata field to print - --all print all metadata fields + -f metadata field to print; omit to get all fields """ remove_usage = """\ @@ -252,7 +251,7 @@ def _install(dispatcher, args, **kw): @action_help(metadata_usage) def _metadata(dispatcher, args, **kw): - opts = _parse_args(args[1:], 'f:', ['all']) + opts = _parse_args(args[1:], 'f:', []) if opts['args']: name = opts['args'][0] dist = get_distribution(name, use_egg_info=True) @@ -269,13 +268,10 @@ def _metadata(dispatcher, args, **kw): metadata = dist.metadata - if 'all' in opts: - keys = metadata.keys() + if 'f' in opts: + keys = (k for k in opts['f'] if k in metadata) else: - if 'f' in opts: - keys = (k for k in opts['f'] if k in metadata) - else: - keys = () + keys = metadata.keys() for key in keys: if key in metadata: From acddb38602d71aded42e53d89b78b82c617e117d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=89ric=20Araujo?= Date: Tue, 30 Aug 2011 00:45:59 +0200 Subject: [PATCH 5/8] Cleanup: move code out of a try block --- Lib/packaging/command/__init__.py | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/Lib/packaging/command/__init__.py b/Lib/packaging/command/__init__.py index 6a3785061b9..2b52190b013 100644 --- a/Lib/packaging/command/__init__.py +++ b/Lib/packaging/command/__init__.py @@ -30,6 +30,8 @@ _COMMANDS = { 'upload': 'packaging.command.upload.upload', 'upload_docs': 'packaging.command.upload_docs.upload_docs'} +# XXX use OrderedDict to preserve the grouping (build-related, install-related, +# distribution-related) STANDARD_COMMANDS = set(_COMMANDS) @@ -48,9 +50,9 @@ def get_command_class(name): """Return the registered command""" try: cls = _COMMANDS[name] - if isinstance(cls, str): - cls = resolve_name(cls) - _COMMANDS[name] = cls - return cls except KeyError: raise PackagingModuleError("Invalid command %s" % name) + if isinstance(cls, str): + cls = resolve_name(cls) + _COMMANDS[name] = cls + return cls From 5e48c78ecfca75199b250a5d31577ef0f89db800 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=89ric=20Araujo?= Date: Tue, 30 Aug 2011 00:55:02 +0200 Subject: [PATCH 6/8] Remove display options (--name, etc.) from the Distribution class. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit These options were used to implement “setup.py --name”, “setup.py --version”, etc. which are now handled by the pysetup metadata action or direct parsing of the setup.cfg file. As a side effect, the Distribution class no longer accepts a 'url' key in its *attrs* argument: it has to be 'home-page' to be recognized as a valid metadata field and passed down to the dist.metadata object. I cleaned up some comments, docstrings and code along the way. --- Lib/packaging/dist.py | 106 +++++------------- .../tests/test_command_bdist_dumb.py | 2 +- Lib/packaging/tests/test_command_register.py | 2 +- Lib/packaging/tests/test_command_sdist.py | 2 +- Lib/packaging/tests/test_dist.py | 8 +- 5 files changed, 34 insertions(+), 86 deletions(-) diff --git a/Lib/packaging/dist.py b/Lib/packaging/dist.py index 7b431acc8b6..f1441d14cb8 100644 --- a/Lib/packaging/dist.py +++ b/Lib/packaging/dist.py @@ -1,20 +1,21 @@ -"""Class representing the distribution being built/installed/etc.""" +"""Class representing the project being built/installed/etc.""" import os import re +from packaging import logger +from packaging.util import strtobool, resolve_name +from packaging.config import Config from packaging.errors import (PackagingOptionError, PackagingArgError, PackagingModuleError, PackagingClassError) -from packaging.fancy_getopt import FancyGetopt -from packaging.util import strtobool, resolve_name -from packaging import logger -from packaging.metadata import Metadata -from packaging.config import Config from packaging.command import get_command_class, STANDARD_COMMANDS +from packaging.command.cmd import Command +from packaging.metadata import Metadata +from packaging.fancy_getopt import FancyGetopt # Regex to define acceptable Packaging command names. This is not *quite* -# the same as a Python NAME -- I don't allow leading underscores. The fact -# that they're very similar is no coincidence; the default naming scheme is +# the same as a Python name -- leading underscores are not allowed. The fact +# that they're very similar is no coincidence: the default naming scheme is # to look for a Python module named after the command. command_re = re.compile(r'^[a-zA-Z]([a-zA-Z0-9_]*)$') @@ -32,22 +33,16 @@ def gen_usage(script_name): class Distribution: - """The core of the Packaging. Most of the work hiding behind 'setup' - is really done within a Distribution instance, which farms the work out - to the Packaging commands specified on the command line. + """Class used to represent a project and work with it. - Setup scripts will almost never instantiate Distribution directly, - unless the 'setup()' function is totally inadequate to their needs. - However, it is conceivable that a setup script might wish to subclass - Distribution for some specialized purpose, and then pass the subclass - to 'setup()' as the 'distclass' keyword argument. If so, it is - necessary to respect the expectations that 'setup' has of Distribution. - See the code for 'setup()', in run.py, for details. + Most of the work hiding behind 'pysetup run' is really done within a + Distribution instance, which farms the work out to the commands + specified on the command line. """ # 'global_options' describes the command-line options that may be # supplied to the setup script prior to any actual commands. - # Eg. "pysetup -n" or "pysetup --dry-run" both take advantage of + # Eg. "pysetup run -n" or "pysetup run --dry-run" both take advantage of # these global options. This list should be kept to a bare minimum, # since every global option is also valid as a command option -- and we # don't want to pollute the commands with too many options that they @@ -63,55 +58,14 @@ class Distribution: common_usage = """\ Common commands: (see '--help-commands' for more) - pysetup run build will build the package underneath 'build/' - pysetup run install will install the package + pysetup run build will build the project underneath 'build/' + pysetup run install will install the project """ # options that are not propagated to the commands display_options = [ ('help-commands', None, "list all available commands"), - # XXX this is obsoleted by the pysetup metadata action - ('name', None, - "print package name"), - ('version', 'V', - "print package version"), - ('fullname', None, - "print -"), - ('author', None, - "print the author's name"), - ('author-email', None, - "print the author's email address"), - ('maintainer', None, - "print the maintainer's name"), - ('maintainer-email', None, - "print the maintainer's email address"), - ('contact', None, - "print the maintainer's name if known, else the author's"), - ('contact-email', None, - "print the maintainer's email address if known, else the author's"), - ('url', None, - "print the URL for this package"), - ('license', None, - "print the license of the package"), - ('licence', None, - "alias for --license"), - ('description', None, - "print the package description"), - ('long-description', None, - "print the long package description"), - ('platforms', None, - "print the list of platforms"), - ('classifier', None, - "print the list of classifiers"), - ('keywords', None, - "print the list of keywords"), - ('provides', None, - "print the list of packages/modules provided"), - ('requires', None, - "print the list of packages/modules required"), - ('obsoletes', None, - "print the list of packages/modules made obsolete"), ('use-2to3', None, "use 2to3 to make source python 3.x compatible"), ('convert-2to3-doctests', None, @@ -347,7 +301,6 @@ Common commands: (see '--help-commands' for more) self.commands = [] parser = FancyGetopt(toplevel_options + self.display_options) parser.set_negative_aliases(self.negative_opt) - parser.set_aliases({'licence': 'license'}) args = parser.getopt(args=self.script_args, object=self) option_order = parser.get_option_order() @@ -372,7 +325,7 @@ Common commands: (see '--help-commands' for more) commands=self.commands) return - return 1 + return True def _get_toplevel_options(self): """Return the non-display options recognized at the top level. @@ -496,13 +449,10 @@ Common commands: (see '--help-commands' for more) If 'global_options' is true, lists the global options: --dry-run, etc. If 'display_options' is true, lists - the "display-only" options: --name, --version, etc. Finally, + the "display-only" options: --help-commands. Finally, lists per-command help for every command name or command class in 'commands'. """ - # late import because of mutual dependence between these modules - from packaging.command.cmd import Command - if global_options: if display_options: options = self._get_toplevel_options() @@ -536,9 +486,8 @@ Common commands: (see '--help-commands' for more) def handle_display_options(self, option_order): """If there were any non-global "display-only" options - (--help-commands or the metadata display options) on the command - line, display the requested info and return true; else return - false. + (--help-commands) on the command line, display the requested info and + return true; else return false. """ # User just wants a list of commands -- we'll print it out and stop # processing now (ie. if they ran "setup --help-commands foo bar", @@ -547,7 +496,7 @@ Common commands: (see '--help-commands' for more) self.print_commands() print() print(gen_usage(self.script_name)) - return 1 + return True # If user supplied any of the "display metadata" options, then # display that metadata in the order in which the user supplied the @@ -628,18 +577,17 @@ Common commands: (see '--help-commands' for more) """ cmd_obj = self.command_obj.get(command) if not cmd_obj and create: - logger.debug("Distribution.get_command_obj(): " \ + logger.debug("Distribution.get_command_obj(): " "creating %r command object", command) cls = get_command_class(command) cmd_obj = self.command_obj[command] = cls(self) self.have_run[command] = 0 - # Set any options that were supplied in config files - # or on the command line. (NB. support for error - # reporting is lame here: any errors aren't reported - # until 'finalize_options()' is called, which means - # we won't report the source of the error.) + # Set any options that were supplied in config files or on the + # command line. (XXX support for error reporting is suboptimal + # here: errors aren't reported until finalize_options is called, + # which means we won't report the source of the error.) options = self.command_options.get(command) if options: self._set_command_options(cmd_obj, options) @@ -707,7 +655,6 @@ Common commands: (see '--help-commands' for more) Returns the reinitialized command object. """ - from packaging.command.cmd import Command if not isinstance(command, Command): command_name = command command = self.get_command_obj(command_name) @@ -716,6 +663,7 @@ Common commands: (see '--help-commands' for more) if not command.finalized: return command + command.initialize_options() self.have_run[command_name] = 0 command.finalized = False diff --git a/Lib/packaging/tests/test_command_bdist_dumb.py b/Lib/packaging/tests/test_command_bdist_dumb.py index 25f3276b0c8..cc03fa53c68 100644 --- a/Lib/packaging/tests/test_command_bdist_dumb.py +++ b/Lib/packaging/tests/test_command_bdist_dumb.py @@ -35,7 +35,7 @@ class BuildDumbTestCase(support.TempdirManager, dist = Distribution({'name': 'foo', 'version': '0.1', 'py_modules': ['foo'], - 'url': 'xxx', 'author': 'xxx', + 'home-page': 'xxx', 'author': 'xxx', 'author_email': 'xxx'}) os.chdir(pkg_dir) cmd = bdist_dumb(dist) diff --git a/Lib/packaging/tests/test_command_register.py b/Lib/packaging/tests/test_command_register.py index 183f84e3152..9c64e2dd29a 100644 --- a/Lib/packaging/tests/test_command_register.py +++ b/Lib/packaging/tests/test_command_register.py @@ -99,7 +99,7 @@ class RegisterTestCase(support.TempdirManager, def _get_cmd(self, metadata=None): if metadata is None: - metadata = {'url': 'xxx', 'author': 'xxx', + metadata = {'home-page': 'xxx', 'author': 'xxx', 'author_email': 'xxx', 'name': 'xxx', 'version': 'xxx'} pkg_info, dist = self.create_dist(**metadata) diff --git a/Lib/packaging/tests/test_command_sdist.py b/Lib/packaging/tests/test_command_sdist.py index bcaa63087ae..ddc6bf7039e 100644 --- a/Lib/packaging/tests/test_command_sdist.py +++ b/Lib/packaging/tests/test_command_sdist.py @@ -72,7 +72,7 @@ class SDistTestCase(support.TempdirManager, """Returns a cmd""" if metadata is None: metadata = {'name': 'fake', 'version': '1.0', - 'url': 'xxx', 'author': 'xxx', + 'home_page': 'xxx', 'author': 'xxx', 'author_email': 'xxx'} dist = Distribution(metadata) dist.packages = ['somecode'] diff --git a/Lib/packaging/tests/test_dist.py b/Lib/packaging/tests/test_dist.py index 01a11caa4c5..1d78fa9b986 100644 --- a/Lib/packaging/tests/test_dist.py +++ b/Lib/packaging/tests/test_dist.py @@ -98,7 +98,7 @@ class DistributionTestCase(support.TempdirManager, Distribution(attrs={'author': 'xxx', 'name': 'xxx', 'version': '1.2', - 'url': 'xxxx', + 'home-page': 'xxxx', 'badoptname': 'xxx'}) logs = self.get_logs(logging.WARNING) self.assertEqual(1, len(logs)) @@ -108,7 +108,7 @@ class DistributionTestCase(support.TempdirManager, Distribution(attrs={'author': 'xxx', 'name': 'xxx', 'version': 'xxx', - 'url': 'xxxx'}) + 'home-page': 'xxxx'}) logs = self.get_logs(logging.WARNING) self.assertEqual(1, len(logs)) self.assertIn('not a valid version', logs[0]) @@ -119,7 +119,7 @@ class DistributionTestCase(support.TempdirManager, Distribution(attrs={'author': 'xxx', 'name': 'xxx', 'version': '1.2', - 'url': 'xxxx', + 'home-page': 'xxxx', 'options': {}}) self.assertEqual([], self.get_logs(logging.WARNING)) @@ -135,7 +135,7 @@ class DistributionTestCase(support.TempdirManager, dist = Distribution(attrs={'author': 'xxx', 'name': 'xxx', 'version': 'xxx', - 'url': 'xxxx', + 'home-page': 'xxxx', 'options': {'sdist': {'owner': 'root'}}}) self.assertIn('owner', dist.get_option_dict('sdist')) From 83ab3f319b3b83c84c4df72349b6ce7d5ec936da Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=89ric=20Araujo?= Date: Tue, 30 Aug 2011 01:19:02 +0200 Subject: [PATCH 7/8] Remove obsolete mentions of the compress program and .Z archives. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Packaging uses the shutil.make_archive function copied from distutils, which does not support compress. There is no test to check that “bdist --format whatever” works, so this slipped by. --- Doc/packaging/builtdist.rst | 11 ++++------- Doc/packaging/sourcedist.rst | 9 +-------- Lib/packaging/command/bdist.py | 13 ++++++------- Lib/packaging/command/bdist_dumb.py | 15 ++++++++------- Lib/packaging/tests/test_command_bdist.py | 19 ++++++++----------- 5 files changed, 27 insertions(+), 40 deletions(-) diff --git a/Doc/packaging/builtdist.rst b/Doc/packaging/builtdist.rst index 3f3e7908445..b1e5e935514 100644 --- a/Doc/packaging/builtdist.rst +++ b/Doc/packaging/builtdist.rst @@ -75,9 +75,6 @@ The available formats for built distributions are: | ``gztar`` | gzipped tar file | (1),(3) | | | (:file:`.tar.gz`) | | +-------------+------------------------------+---------+ -| ``ztar`` | compressed tar file | \(3) | -| | (:file:`.tar.Z`) | | -+-------------+------------------------------+---------+ | ``tar`` | tar file (:file:`.tar`) | \(3) | +-------------+------------------------------+---------+ | ``zip`` | zip file (:file:`.zip`) | (2),(4) | @@ -98,8 +95,8 @@ Notes: default on Windows (3) - requires external utilities: :program:`tar` and possibly one of :program:`gzip`, - :program:`bzip2`, or :program:`compress` + requires external utilities: :program:`tar` and possibly one of :program:`gzip` + or :program:`bzip2` (4) requires either external :program:`zip` utility or :mod:`zipfile` module (part @@ -109,14 +106,14 @@ You don't have to use the :command:`bdist` command with the :option:`--formats` option; you can also use the command that directly implements the format you're interested in. Some of these :command:`bdist` "sub-commands" actually generate several similar formats; for instance, the :command:`bdist_dumb` command -generates all the "dumb" archive formats (``tar``, ``ztar``, ``gztar``, and +generates all the "dumb" archive formats (``tar``, ``gztar``, and ``zip``). The :command:`bdist` sub-commands, and the formats generated by each, are: +--------------------------+-----------------------+ | Command | Formats | +==========================+=======================+ -| :command:`bdist_dumb` | tar, ztar, gztar, zip | +| :command:`bdist_dumb` | tar, gztar, zip | +--------------------------+-----------------------+ | :command:`bdist_wininst` | wininst | +--------------------------+-----------------------+ diff --git a/Doc/packaging/sourcedist.rst b/Doc/packaging/sourcedist.rst index 0cd4df3f815..2cedc15ea90 100644 --- a/Doc/packaging/sourcedist.rst +++ b/Doc/packaging/sourcedist.rst @@ -32,9 +32,6 @@ to create a gzipped tarball and a zip file. The available formats are: | ``bztar`` | bzip2'ed tar file | | | | (:file:`.tar.bz2`) | | +-----------+-------------------------+---------+ -| ``ztar`` | compressed tar file | \(4) | -| | (:file:`.tar.Z`) | | -+-----------+-------------------------+---------+ | ``tar`` | tar file (:file:`.tar`) | | +-----------+-------------------------+---------+ @@ -50,11 +47,7 @@ Notes: requires either external :program:`zip` utility or :mod:`zipfile` module (part of the standard Python library since Python 1.6) -(4) - requires the :program:`compress` program. Notice that this format is now - pending for deprecation and will be removed in the future versions of Python. - -When using any ``tar`` format (``gztar``, ``bztar``, ``ztar`` or +When using any ``tar`` format (``gztar``, ``bztar`` or ``tar``) under Unix, you can specify the ``owner`` and ``group`` names that will be set for each member of the archive. diff --git a/Lib/packaging/command/bdist.py b/Lib/packaging/command/bdist.py index e8c023dc072..b9d550b86b3 100644 --- a/Lib/packaging/command/bdist.py +++ b/Lib/packaging/command/bdist.py @@ -64,20 +64,18 @@ class bdist(Command): 'os2': 'zip'} # Establish the preferred order (for the --help-formats option). - format_commands = ['gztar', 'bztar', 'ztar', 'tar', + format_commands = ['gztar', 'bztar', 'tar', 'wininst', 'zip', 'msi'] # And the real information. format_command = {'gztar': ('bdist_dumb', "gzip'ed tar file"), 'bztar': ('bdist_dumb', "bzip2'ed tar file"), - 'ztar': ('bdist_dumb', "compressed tar file"), 'tar': ('bdist_dumb', "tar file"), 'wininst': ('bdist_wininst', "Windows executable installer"), 'zip': ('bdist_dumb', "ZIP file"), - 'msi': ('bdist_msi', "Microsoft Installer") - } - + 'msi': ('bdist_msi', "Microsoft Installer"), + } def initialize_options(self): self.bdist_base = None @@ -109,8 +107,9 @@ class bdist(Command): try: self.formats = [self.default_format[os.name]] except KeyError: - raise PackagingPlatformError("don't know how to create built distributions " + \ - "on platform %s" % os.name) + raise PackagingPlatformError( + "don't know how to create built distributions " + "on platform %s" % os.name) if self.dist_dir is None: self.dist_dir = "dist" diff --git a/Lib/packaging/command/bdist_dumb.py b/Lib/packaging/command/bdist_dumb.py index f74b7209254..ed83c8ec951 100644 --- a/Lib/packaging/command/bdist_dumb.py +++ b/Lib/packaging/command/bdist_dumb.py @@ -13,6 +13,7 @@ from packaging.command.cmd import Command from packaging.errors import PackagingPlatformError from packaging import logger + class bdist_dumb(Command): description = 'create a "dumb" built distribution' @@ -23,7 +24,7 @@ class bdist_dumb(Command): "platform name to embed in generated filenames " "(default: %s)" % get_platform()), ('format=', 'f', - "archive format to create (tar, ztar, gztar, zip)"), + "archive format to create (tar, gztar, zip)"), ('keep-temp', 'k', "keep the pseudo-installation tree around after " + "creating the distribution archive"), @@ -44,10 +45,9 @@ class bdist_dumb(Command): boolean_options = ['keep-temp', 'skip-build', 'relative'] - default_format = { 'posix': 'gztar', - 'nt': 'zip', - 'os2': 'zip' } - + default_format = {'posix': 'gztar', + 'nt': 'zip', + 'os2': 'zip'} def initialize_options(self): self.bdist_dir = None @@ -69,8 +69,9 @@ class bdist_dumb(Command): try: self.format = self.default_format[os.name] except KeyError: - raise PackagingPlatformError(("don't know how to create dumb built distributions " + - "on platform %s") % os.name) + raise PackagingPlatformError( + "don't know how to create dumb built distributions " + "on platform %s" % os.name) self.set_undefined_options('bdist', 'dist_dir', 'plat_name') diff --git a/Lib/packaging/tests/test_command_bdist.py b/Lib/packaging/tests/test_command_bdist.py index 1522b7e2142..fa4093cf3ca 100644 --- a/Lib/packaging/tests/test_command_bdist.py +++ b/Lib/packaging/tests/test_command_bdist.py @@ -27,33 +27,30 @@ class BuildTestCase(support.TempdirManager, util.get_platform = self._get_platform def test_formats(self): - # let's create a command and make sure - # we can fix the format - pkg_pth, dist = self.create_dist() + # we can set the format + dist = self.create_dist()[1] cmd = bdist(dist) cmd.formats = ['msi'] cmd.ensure_finalized() self.assertEqual(cmd.formats, ['msi']) - # what format bdist offers ? - # XXX an explicit list in bdist is - # not the best way to bdist_* commands - # we should add a registry - formats = sorted(('zip', 'gztar', 'bztar', 'ztar', - 'tar', 'wininst', 'msi')) + # what format 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'] found = sorted(cmd.format_command) self.assertEqual(found, formats) def test_skip_build(self): - pkg_pth, dist = self.create_dist() + dist = self.create_dist()[1] cmd = bdist(dist) cmd.skip_build = False cmd.formats = ['ztar'] cmd.ensure_finalized() self.assertFalse(self._get_platform_called) - pkg_pth, dist = self.create_dist() + dist = self.create_dist()[1] cmd = bdist(dist) cmd.skip_build = True cmd.formats = ['ztar'] From b9fe54cccc3798f089489ef1e7f9026a35d16d6b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=89ric=20Araujo?= Date: Tue, 30 Aug 2011 01:42:50 +0200 Subject: [PATCH 8/8] 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. --- Lib/packaging/command/bdist_dumb.py | 5 +-- Lib/packaging/command/bdist_msi.py | 6 +++- Lib/packaging/command/bdist_wininst.py | 6 +++- Lib/packaging/tests/test_command_bdist.py | 42 +++++++---------------- Misc/NEWS | 3 +- 5 files changed, 28 insertions(+), 34 deletions(-) diff --git a/Lib/packaging/command/bdist_dumb.py b/Lib/packaging/command/bdist_dumb.py index ed83c8ec951..d5773f01a72 100644 --- a/Lib/packaging/command/bdist_dumb.py +++ b/Lib/packaging/command/bdist_dumb.py @@ -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: diff --git a/Lib/packaging/command/bdist_msi.py b/Lib/packaging/command/bdist_msi.py index 493f8b34e34..eaeb458a8fc 100644 --- a/Lib/packaging/command/bdist_msi.py +++ b/Lib/packaging/command/bdist_msi.py @@ -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()\ diff --git a/Lib/packaging/command/bdist_wininst.py b/Lib/packaging/command/bdist_wininst.py index dbb74eaeadb..7dbb39b3117 100644 --- a/Lib/packaging/command/bdist_wininst.py +++ b/Lib/packaging/command/bdist_wininst.py @@ -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: diff --git a/Lib/packaging/tests/test_command_bdist.py b/Lib/packaging/tests/test_command_bdist.py index fa4093cf3ca..dd101883914 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 @@ 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) diff --git a/Misc/NEWS b/Misc/NEWS index 5106f1fda7c..d08d94ec696 100644 --- 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.