Final bag of small changes coming from distutils2.

- 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.
This commit is contained in:
Éric Araujo 2011-09-19 15:12:23 +02:00
parent c1b7e7f8bb
commit 505f0ebf88
9 changed files with 22 additions and 29 deletions

View File

@ -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"),

View File

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

View File

@ -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()]

View File

@ -28,7 +28,6 @@ from packaging.pypi.errors import (PackagingPyPIError, DownloadError,
UnableToDownload, CantParseArchiveName,
ReleaseNotFound, ProjectNotFound)
from packaging.pypi.mirrors import get_mirrors
from packaging.metadata import Metadata
__all__ = ['Crawler', 'DEFAULT_SIMPLE_INDEX_URL']

View File

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

View File

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

View File

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

View File

@ -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'))

View File

@ -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])