From 505f0ebf8839cc0a44d06b2cef96a20e5e693e74 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=89ric=20Araujo?= Date: Mon, 19 Sep 2011 15:12:23 +0200 Subject: [PATCH] Final bag of small changes coming from distutils2. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - minor cleanup in Metadata - trigger creation of the sysconfig._CONFIG_VARS dict - home_page is used over home-page: it’s not a compound word, it’s an escaped space Distutils2 is now synchronized with Packaging. --- Lib/packaging/command/bdist_dumb.py | 4 ++-- Lib/packaging/compat.py | 8 +------- Lib/packaging/metadata.py | 7 ++++--- Lib/packaging/pypi/simple.py | 7 +++---- Lib/packaging/tests/test_command_bdist_dumb.py | 2 +- Lib/packaging/tests/test_command_build_ext.py | 11 +++++------ Lib/packaging/tests/test_command_register.py | 2 +- Lib/packaging/tests/test_dist.py | 6 +++--- Lib/packaging/tests/test_metadata.py | 4 ++-- 9 files changed, 22 insertions(+), 29 deletions(-) diff --git a/Lib/packaging/command/bdist_dumb.py b/Lib/packaging/command/bdist_dumb.py index d5773f01a72..309f64fe1f7 100644 --- a/Lib/packaging/command/bdist_dumb.py +++ b/Lib/packaging/command/bdist_dumb.py @@ -5,9 +5,9 @@ sys.prefix or sys.exec_prefix. """ import os - from shutil import rmtree from sysconfig import get_python_version + from packaging.util import get_platform from packaging.command.cmd import Command from packaging.errors import PackagingPlatformError @@ -24,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, gztar, zip)"), + "archive format to create (tar, gztar, bztar, zip)"), ('keep-temp', 'k', "keep the pseudo-installation tree around after " + "creating the distribution archive"), diff --git a/Lib/packaging/compat.py b/Lib/packaging/compat.py index a82efd3691b..dcb58f527ee 100644 --- a/Lib/packaging/compat.py +++ b/Lib/packaging/compat.py @@ -1,8 +1,4 @@ -"""Compatibility helpers. - -This module provides classes, variables and imports which are used to -support packaging across Python 2.x and 3.x. -""" +"""Compatibility helpers.""" from packaging import logger @@ -10,8 +6,6 @@ from packaging import logger # XXX Having two classes with the same name is not a good thing. # XXX 2to3-related code should move from util to this module -# TODO Move common code here: PY3 (bool indicating if we're on 3.x), any, etc. - try: from packaging.util import Mixin2to3 as _Mixin2to3 _CONVERT = True diff --git a/Lib/packaging/metadata.py b/Lib/packaging/metadata.py index a3db51c1124..c13acbe3acf 100644 --- a/Lib/packaging/metadata.py +++ b/Lib/packaging/metadata.py @@ -552,16 +552,17 @@ class Metadata: return data # Mapping API + # XXX these methods should return views or sets in 3.x def keys(self): - return _version2fieldlist(self['Metadata-Version']) + return list(_version2fieldlist(self['Metadata-Version'])) def __iter__(self): for key in self.keys(): yield key def values(self): - return [self[key] for key in list(self.keys())] + return [self[key] for key in self.keys()] def items(self): - return [(key, self[key]) for key in list(self.keys())] + return [(key, self[key]) for key in self.keys()] diff --git a/Lib/packaging/pypi/simple.py b/Lib/packaging/pypi/simple.py index 76aad02416d..9faabaa6b6b 100644 --- a/Lib/packaging/pypi/simple.py +++ b/Lib/packaging/pypi/simple.py @@ -23,12 +23,11 @@ from packaging.version import get_version_predicate from packaging import __version__ as packaging_version from packaging.pypi.base import BaseClient from packaging.pypi.dist import (ReleasesList, EXTENSIONS, - get_infos_from_url, MD5_HASH) + get_infos_from_url, MD5_HASH) from packaging.pypi.errors import (PackagingPyPIError, DownloadError, - UnableToDownload, CantParseArchiveName, - ReleaseNotFound, ProjectNotFound) + UnableToDownload, CantParseArchiveName, + ReleaseNotFound, ProjectNotFound) from packaging.pypi.mirrors import get_mirrors -from packaging.metadata import Metadata __all__ = ['Crawler', 'DEFAULT_SIMPLE_INDEX_URL'] diff --git a/Lib/packaging/tests/test_command_bdist_dumb.py b/Lib/packaging/tests/test_command_bdist_dumb.py index cc03fa53c68..8e2d497d79e 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'], - 'home-page': '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_build_ext.py b/Lib/packaging/tests/test_command_build_ext.py index c84631c2a81..2926c37e875 100644 --- a/Lib/packaging/tests/test_command_build_ext.py +++ b/Lib/packaging/tests/test_command_build_ext.py @@ -4,14 +4,13 @@ import site import sysconfig import textwrap from io import StringIO -from sysconfig import _CONFIG_VARS from packaging.dist import Distribution from packaging.errors import (UnknownFileError, CompileError, PackagingPlatformError) from packaging.command.build_ext import build_ext from packaging.compiler.extension import Extension -from test.script_helper import assert_python_ok +from test.script_helper import assert_python_ok from packaging.tests import support, unittest, verbose @@ -75,16 +74,16 @@ class BuildExtTestCase(support.TempdirManager, sys.platform = 'sunos' # fooling finalize_options - old_var = _CONFIG_VARS.get('Py_ENABLE_SHARED') - _CONFIG_VARS['Py_ENABLE_SHARED'] = 1 + old_var = sysconfig.get_config_var('Py_ENABLE_SHARED') + sysconfig._CONFIG_VARS['Py_ENABLE_SHARED'] = 1 try: cmd.ensure_finalized() finally: sys.platform = old if old_var is None: - del _CONFIG_VARS['Py_ENABLE_SHARED'] + del sysconfig._CONFIG_VARS['Py_ENABLE_SHARED'] else: - _CONFIG_VARS['Py_ENABLE_SHARED'] = old_var + sysconfig._CONFIG_VARS['Py_ENABLE_SHARED'] = old_var # make sure we get some library dirs under solaris self.assertGreater(len(cmd.library_dirs), 0) diff --git a/Lib/packaging/tests/test_command_register.py b/Lib/packaging/tests/test_command_register.py index 9c64e2dd29a..9872e2e6dc3 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 = {'home-page': '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_dist.py b/Lib/packaging/tests/test_dist.py index 8d91a92a27c..f912c6fff25 100644 --- a/Lib/packaging/tests/test_dist.py +++ b/Lib/packaging/tests/test_dist.py @@ -72,7 +72,7 @@ class DistributionTestCase(support.TempdirManager, Distribution(attrs={'author': 'xxx', 'name': 'xxx', 'version': '1.2', - 'home-page': 'xxxx', + 'home_page': 'xxxx', 'badoptname': 'xxx'}) logs = self.get_logs(logging.WARNING) self.assertEqual(len(logs), 1) @@ -82,7 +82,7 @@ class DistributionTestCase(support.TempdirManager, # an empty options dictionary should not stay in the # list of attributes dist = Distribution(attrs={'author': 'xxx', 'name': 'xxx', - 'version': '1.2', 'home-page': 'xxxx', + 'version': '1.2', 'home_page': 'xxxx', 'options': {}}) self.assertEqual([], self.get_logs(logging.WARNING)) @@ -99,7 +99,7 @@ class DistributionTestCase(support.TempdirManager, dist = Distribution(attrs={'author': 'xxx', 'name': 'xxx', 'version': 'xxx', - 'home-page': 'xxxx', + 'home_page': 'xxxx', 'options': {'sdist': {'owner': 'root'}}}) self.assertIn('owner', dist.get_option_dict('sdist')) diff --git a/Lib/packaging/tests/test_metadata.py b/Lib/packaging/tests/test_metadata.py index 68b3d9722ad..6b7dd389e45 100644 --- a/Lib/packaging/tests/test_metadata.py +++ b/Lib/packaging/tests/test_metadata.py @@ -101,7 +101,7 @@ class MetadataTestCase(LoggingCatcher, # XXX caveat: the keys method and friends are not 3.x-style views # should be changed or documented - self.assertEqual(list(metadata), list(metadata.keys())) + self.assertEqual(list(metadata), metadata.keys()) def test_read_metadata(self): fields = {'name': 'project', @@ -301,7 +301,7 @@ class MetadataTestCase(LoggingCatcher, Metadata(mapping={'author': 'xxx', 'name': 'xxx', 'version': 'xxx', - 'home-page': 'xxxx'}) + 'home_page': 'xxxx'}) logs = self.get_logs(logging.WARNING) self.assertEqual(1, len(logs)) self.assertIn('not a valid version', logs[0])