summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorÉric Araujo <merwok@netwok.org>2011-09-12 15:47:48 (GMT)
committerÉric Araujo <merwok@netwok.org>2011-09-12 15:47:48 (GMT)
commitdcdc3ef5facabec526dff5f78dc3c0b9161184cb (patch)
treebf81e9afcb1cc3efc93e0c04e01c76f48c8f7838
parent6ebaca137fc25ee3616c48a5fa343628c5132497 (diff)
parenta13cd39533038b1d841acac5a0f37e55b2fdff53 (diff)
downloadcpython-dcdc3ef5facabec526dff5f78dc3c0b9161184cb.zip
cpython-dcdc3ef5facabec526dff5f78dc3c0b9161184cb.tar.gz
cpython-dcdc3ef5facabec526dff5f78dc3c0b9161184cb.tar.bz2
Branch merge
-rw-r--r--Lib/distutils/dist.py3
-rw-r--r--Lib/distutils/tests/test_dist.py117
-rw-r--r--Misc/NEWS6
3 files changed, 70 insertions, 56 deletions
diff --git a/Lib/distutils/dist.py b/Lib/distutils/dist.py
index 597909e..e025313 100644
--- a/Lib/distutils/dist.py
+++ b/Lib/distutils/dist.py
@@ -1111,7 +1111,8 @@ class DistributionMetadata:
"""Write the PKG-INFO format data to a file object.
"""
version = '1.0'
- if self.provides or self.requires or self.obsoletes:
+ if (self.provides or self.requires or self.obsoletes or
+ self.classifiers or self.download_url):
version = '1.1'
self._write_field(file, 'Metadata-Version', version)
diff --git a/Lib/distutils/tests/test_dist.py b/Lib/distutils/tests/test_dist.py
index ba60638..4b7bbeb 100644
--- a/Lib/distutils/tests/test_dist.py
+++ b/Lib/distutils/tests/test_dist.py
@@ -8,12 +8,13 @@ import unittest
import warnings
import textwrap
-from distutils.dist import Distribution, fix_help_options, DistributionMetadata
+from distutils.dist import Distribution, fix_help_options
from distutils.cmd import Command
import distutils.dist
from test.test_support import TESTFN, captured_stdout, run_unittest
from distutils.tests import support
+
class test_dist(Command):
"""Sample distutils extension command."""
@@ -61,7 +62,7 @@ class DistributionTestCase(support.TempdirManager,
def test_debug_mode(self):
with open(TESTFN, "w") as f:
- f.write("[global]")
+ f.write("[global]\n")
f.write("command_packages = foo.bar, splat")
files = [TESTFN]
@@ -97,7 +98,7 @@ class DistributionTestCase(support.TempdirManager,
self.assertEqual(d.get_command_packages(),
["distutils.command", "foo.bar", "distutils.tests"])
cmd = d.get_command_obj("test_dist")
- self.assertTrue(isinstance(cmd, test_dist))
+ self.assertIsInstance(cmd, test_dist)
self.assertEqual(cmd.sample_option, "sometext")
def test_command_packages_configfile(self):
@@ -105,8 +106,8 @@ class DistributionTestCase(support.TempdirManager,
self.addCleanup(os.unlink, TESTFN)
f = open(TESTFN, "w")
try:
- print >>f, "[global]"
- print >>f, "command_packages = foo.bar, splat"
+ print >> f, "[global]"
+ print >> f, "command_packages = foo.bar, splat"
finally:
f.close()
@@ -138,7 +139,6 @@ class DistributionTestCase(support.TempdirManager,
'description': u'Café torréfié',
'long_description': u'Héhéhé'})
-
# let's make sure the file can be written
# with Unicode fields. they are encoded with
# PKG_INFO_ENCODING
@@ -152,33 +152,28 @@ class DistributionTestCase(support.TempdirManager,
'long_description': 'Hehehe'})
my_file2 = os.path.join(tmp_dir, 'f2')
- dist.metadata.write_pkg_file(open(my_file, 'w'))
+ dist.metadata.write_pkg_file(open(my_file2, 'w'))
def test_empty_options(self):
# an empty options dictionary should not stay in the
# list of attributes
- klass = Distribution
# catching warnings
warns = []
+
def _warn(msg):
warns.append(msg)
- old_warn = warnings.warn
+ self.addCleanup(setattr, warnings, 'warn', warnings.warn)
warnings.warn = _warn
- try:
- dist = klass(attrs={'author': 'xxx',
- 'name': 'xxx',
- 'version': 'xxx',
- 'url': 'xxxx',
- 'options': {}})
- finally:
- warnings.warn = old_warn
+ dist = Distribution(attrs={'author': 'xxx', 'name': 'xxx',
+ 'version': 'xxx', 'url': 'xxxx',
+ 'options': {}})
self.assertEqual(len(warns), 0)
+ self.assertNotIn('options', dir(dist))
def test_finalize_options(self):
-
attrs = {'keywords': 'one,two',
'platforms': 'one,two'}
@@ -201,7 +196,6 @@ class DistributionTestCase(support.TempdirManager,
cmds = dist.get_command_packages()
self.assertEqual(cmds, ['distutils.command', 'one', 'two'])
-
def test_announce(self):
# make sure the level is known
dist = Distribution()
@@ -251,15 +245,44 @@ class MetadataTestCase(support.TempdirManager, support.EnvironGuard,
sys.argv[:] = self.argv[1]
super(MetadataTestCase, self).tearDown()
+ def test_classifier(self):
+ attrs = {'name': 'Boa', 'version': '3.0',
+ 'classifiers': ['Programming Language :: Python :: 3']}
+ dist = Distribution(attrs)
+ meta = self.format_metadata(dist)
+ self.assertIn('Metadata-Version: 1.1', meta)
+
+ def test_download_url(self):
+ attrs = {'name': 'Boa', 'version': '3.0',
+ 'download_url': 'http://example.org/boa'}
+ dist = Distribution(attrs)
+ meta = self.format_metadata(dist)
+ self.assertIn('Metadata-Version: 1.1', meta)
+
+ def test_long_description(self):
+ long_desc = textwrap.dedent("""\
+ example::
+ We start here
+ and continue here
+ and end here.""")
+ attrs = {"name": "package",
+ "version": "1.0",
+ "long_description": long_desc}
+
+ dist = Distribution(attrs)
+ meta = self.format_metadata(dist)
+ meta = meta.replace('\n' + 8 * ' ', '\n')
+ self.assertIn(long_desc, meta)
+
def test_simple_metadata(self):
attrs = {"name": "package",
"version": "1.0"}
dist = Distribution(attrs)
meta = self.format_metadata(dist)
- self.assertTrue("Metadata-Version: 1.0" in meta)
- self.assertTrue("provides:" not in meta.lower())
- self.assertTrue("requires:" not in meta.lower())
- self.assertTrue("obsoletes:" not in meta.lower())
+ self.assertIn("Metadata-Version: 1.0", meta)
+ self.assertNotIn("provides:", meta.lower())
+ self.assertNotIn("requires:", meta.lower())
+ self.assertNotIn("obsoletes:", meta.lower())
def test_provides(self):
attrs = {"name": "package",
@@ -271,9 +294,9 @@ class MetadataTestCase(support.TempdirManager, support.EnvironGuard,
self.assertEqual(dist.get_provides(),
["package", "package.sub"])
meta = self.format_metadata(dist)
- self.assertTrue("Metadata-Version: 1.1" in meta)
- self.assertTrue("requires:" not in meta.lower())
- self.assertTrue("obsoletes:" not in meta.lower())
+ self.assertIn("Metadata-Version: 1.1", meta)
+ self.assertNotIn("requires:", meta.lower())
+ self.assertNotIn("obsoletes:", meta.lower())
def test_provides_illegal(self):
self.assertRaises(ValueError, Distribution,
@@ -291,11 +314,11 @@ class MetadataTestCase(support.TempdirManager, support.EnvironGuard,
self.assertEqual(dist.get_requires(),
["other", "another (==1.0)"])
meta = self.format_metadata(dist)
- self.assertTrue("Metadata-Version: 1.1" in meta)
- self.assertTrue("provides:" not in meta.lower())
- self.assertTrue("Requires: other" in meta)
- self.assertTrue("Requires: another (==1.0)" in meta)
- self.assertTrue("obsoletes:" not in meta.lower())
+ self.assertIn("Metadata-Version: 1.1", meta)
+ self.assertNotIn("provides:", meta.lower())
+ self.assertIn("Requires: other", meta)
+ self.assertIn("Requires: another (==1.0)", meta)
+ self.assertNotIn("obsoletes:", meta.lower())
def test_requires_illegal(self):
self.assertRaises(ValueError, Distribution,
@@ -313,11 +336,11 @@ class MetadataTestCase(support.TempdirManager, support.EnvironGuard,
self.assertEqual(dist.get_obsoletes(),
["other", "another (<1.0)"])
meta = self.format_metadata(dist)
- self.assertTrue("Metadata-Version: 1.1" in meta)
- self.assertTrue("provides:" not in meta.lower())
- self.assertTrue("requires:" not in meta.lower())
- self.assertTrue("Obsoletes: other" in meta)
- self.assertTrue("Obsoletes: another (<1.0)" in meta)
+ self.assertIn("Metadata-Version: 1.1", meta)
+ self.assertNotIn("provides:", meta.lower())
+ self.assertNotIn("requires:", meta.lower())
+ self.assertIn("Obsoletes: other", meta)
+ self.assertIn("Obsoletes: another (<1.0)", meta)
def test_obsoletes_illegal(self):
self.assertRaises(ValueError, Distribution,
@@ -353,14 +376,14 @@ class MetadataTestCase(support.TempdirManager, support.EnvironGuard,
if sys.platform in ('linux', 'darwin'):
os.environ['HOME'] = temp_dir
files = dist.find_config_files()
- self.assertTrue(user_filename in files)
+ self.assertIn(user_filename, files)
# win32-style
if sys.platform == 'win32':
# home drive should be found
os.environ['HOME'] = temp_dir
files = dist.find_config_files()
- self.assertTrue(user_filename in files,
+ self.assertIn(user_filename, files,
'%r not found in %r' % (user_filename, files))
finally:
os.remove(user_filename)
@@ -382,22 +405,7 @@ class MetadataTestCase(support.TempdirManager, support.EnvironGuard,
output = [line for line in s.getvalue().split('\n')
if line.strip() != '']
- self.assertTrue(len(output) > 0)
-
- def test_long_description(self):
- long_desc = textwrap.dedent("""\
- example::
- We start here
- and continue here
- and end here.""")
- attrs = {"name": "package",
- "version": "1.0",
- "long_description": long_desc}
-
- dist = distutils.dist.Distribution(attrs)
- meta = self.format_metadata(dist)
- meta = meta.replace('\n' + 8 * ' ', '\n')
- self.assertTrue(long_desc in meta)
+ self.assertTrue(output)
def test_read_metadata(self):
attrs = {"name": "package",
@@ -426,6 +434,7 @@ class MetadataTestCase(support.TempdirManager, support.EnvironGuard,
self.assertEqual(metadata.obsoletes, None)
self.assertEqual(metadata.requires, ['foo'])
+
def test_suite():
suite = unittest.TestSuite()
suite.addTest(unittest.makeSuite(DistributionTestCase))
diff --git a/Misc/NEWS b/Misc/NEWS
index 8d448b0..41328fd 100644
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -39,7 +39,11 @@ Core and Builtins
Library
-------
-
+
+- Issue #8933: distutils' PKG-INFO files will now correctly report
+ Metadata-Version: 1.1 instead of 1.0 if a Classifier or Download-URL field is
+ present.
+
- Issue #8286: The distutils command sdist will print a warning message instead
of crashing when an invalid path is given in the manifest template.