[Python-checkins] distutils2: Allow multiple values for package_data in setup.cfg (#11805).
eric.araujo
python-checkins at python.org
Sun Feb 5 12:23:57 CET 2012
http://hg.python.org/distutils2/rev/83a0985c7aad
changeset: 1272:83a0985c7aad
user: Éric Araujo <merwok at netwok.org>
date: Sun Feb 05 11:52:01 2012 +0100
summary:
Allow multiple values for package_data in setup.cfg (#11805).
Even though the resources system obsoletes data_files and package_data
(see bug discussion), package_data still exists to allow compatibility
with distutils and thus an easier transition. In setup.py, the values
are lists of glob patterns, so the setup.cfg syntax needed a way to
express multiple values too.
Reported by Erik Bray.
files:
CHANGES.txt | 3 +-
distutils2/config.py | 24 ++++++++++---
distutils2/tests/test_config.py | 37 +++++++++++++++++---
3 files changed, 50 insertions(+), 14 deletions(-)
diff --git a/CHANGES.txt b/CHANGES.txt
--- a/CHANGES.txt
+++ b/CHANGES.txt
@@ -9,7 +9,7 @@
CONTRIBUTORS.txt for full names. Bug numbers refer to http://bugs.python.org/.
-1.0a4 - 2011-12-??
+1.0a4 - 2012-02-??
------------------
- Remove type check for commands in favor of minimal duck type check [tarek]
@@ -161,6 +161,7 @@
functions, obsoleted by logging [éric]
- #12659: Add tests for tests.support [francisco]
- #13901: Prevent test failure on OS X for Python built in shared mode [ned]
+- #11805: Add multiple value syntax for package_data in setup.cfg [éric]
1.0a3 - 2010-10-08
diff --git a/distutils2/config.py b/distutils2/config.py
--- a/distutils2/config.py
+++ b/distutils2/config.py
@@ -232,13 +232,25 @@
self.dist.scripts = [self.dist.scripts]
self.dist.package_data = {}
+ # bookkeeping for the loop below
+ firstline = True
+ prev = None
+
for line in files.get('package_data', []):
- data = line.split('=')
- if len(data) != 2:
- raise ValueError('invalid line for package_data: %s '
- '(misses "=")' % line)
- key, value = data
- self.dist.package_data[key.strip()] = value.strip()
+ if '=' in line:
+ # package name -- file globs or specs
+ key, value = line.split('=')
+ prev = self.dist.package_data[key.strip()] = value.split()
+ elif firstline:
+ # invalid continuation on the first line
+ raise PackagingOptionError(
+ 'malformed package_data first line: %r (misses "=")' %
+ line)
+ else:
+ # continuation, add to last seen package name
+ prev.extend(line.split())
+
+ firstline = False
self.dist.data_files = []
for data in files.get('data_files', []):
diff --git a/distutils2/tests/test_config.py b/distutils2/tests/test_config.py
--- a/distutils2/tests/test_config.py
+++ b/distutils2/tests/test_config.py
@@ -67,11 +67,15 @@
bin/taunt
package_data =
- cheese = data/templates/*
+ cheese = data/templates/* doc/*
+ doc/images/*.png
+
extra_files = %(extra-files)s
# Replaces MANIFEST.in
+# FIXME no, it's extra_files
+# (but sdist_extra is a better name, should use it)
sdist_extra =
include THANKS HACKING
recursive-include examples *.txt *.py
@@ -97,6 +101,17 @@
sub_commands = foo
"""
+SETUP_CFG_PKGDATA_BUGGY_1 = """
+[files]
+package_data = foo.*
+"""
+
+SETUP_CFG_PKGDATA_BUGGY_2 = """
+[files]
+package_data =
+ foo.*
+"""
+
# Can not be merged with SETUP_CFG else install_dist
# command will fail when trying to compile C sources
# TODO use a DummyCommand to mock build_ext
@@ -277,13 +292,14 @@
self.assertEqual(dist.packages, ['one', 'two', 'three'])
self.assertEqual(dist.py_modules, ['haven'])
- self.assertEqual(dist.package_data, {'cheese': 'data/templates/*'})
- self.assertEqual(
+ self.assertEqual(dist.package_data,
+ {'cheese': ['data/templates/*', 'doc/*',
+ 'doc/images/*.png']})
+ self.assertEqual(dist.data_files,
{'bm/b1.gif': '{icon}/b1.gif',
'bm/b2.gif': '{icon}/b2.gif',
'Cfg/data.CFG': '{config}/baBar/data.CFG',
- 'init_script': '{script}/JunGle/init_script'},
- dist.data_files)
+ 'init_script': '{script}/JunGle/init_script'})
self.assertEqual(dist.package_dir, 'src')
@@ -294,8 +310,8 @@
# this file would be __main__.Foo when run as "python test_config.py".
# The name FooBarBazTest should be unique enough to prevent
# collisions.
- self.assertEqual('FooBarBazTest',
- dist.get_command_obj('foo').__class__.__name__)
+ self.assertEqual(dist.get_command_obj('foo').__class__.__name__,
+ 'FooBarBazTest')
# did the README got loaded ?
self.assertEqual(dist.metadata['description'], 'yeah')
@@ -305,6 +321,13 @@
d = new_compiler(compiler='d')
self.assertEqual(d.description, 'D Compiler')
+ # check error reporting for invalid package_data value
+ self.write_file('setup.cfg', SETUP_CFG_PKGDATA_BUGGY_1)
+ self.assertRaises(PackagingOptionError, self.get_dist)
+
+ self.write_file('setup.cfg', SETUP_CFG_PKGDATA_BUGGY_2)
+ self.assertRaises(PackagingOptionError, self.get_dist)
+
def test_multiple_description_file(self):
self.write_setup({'description-file': 'README CHANGES'})
self.write_file('README', 'yeah')
--
Repository URL: http://hg.python.org/distutils2
More information about the Python-checkins
mailing list