summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author?ric Araujo <merwok@netwok.org>2012-02-05 11:52:01 +0100
committer?ric Araujo <merwok@netwok.org>2012-02-05 11:52:01 +0100
commit5fdd763dde6f8e93038be86edd59631a78de4734 (patch)
tree45b9bd7dd7e0efaba9653bece101585398228327
parentb6364865ba6d3036bad4cc2c2348436dd6654219 (diff)
downloaddisutils2-5fdd763dde6f8e93038be86edd59631a78de4734.tar.gz
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.
-rw-r--r--CHANGES.txt3
-rw-r--r--distutils2/config.py24
-rw-r--r--distutils2/tests/test_config.py37
3 files changed, 50 insertions, 14 deletions
diff --git a/CHANGES.txt b/CHANGES.txt
index f12d25d..1ca5200 100644
--- a/CHANGES.txt
+++ b/CHANGES.txt
@@ -9,7 +9,7 @@ their clones, and all changes that have a bug report. Contributors' first names
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 @@ CONTRIBUTORS.txt for full names. Bug numbers refer to http://bugs.python.org/.
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
index 5c3eaf1..cdd67bb 100644
--- a/distutils2/config.py
+++ b/distutils2/config.py
@@ -232,13 +232,25 @@ class Config(object):
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
index 6b25fd6..d3a0cc4 100644
--- a/distutils2/tests/test_config.py
+++ b/distutils2/tests/test_config.py
@@ -67,11 +67,15 @@ scripts =
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 @@ setup_hooks = %(setup-hooks)s
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 @@ class ConfigTestCase(support.TempdirManager,
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 @@ class ConfigTestCase(support.TempdirManager,
# 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 @@ class ConfigTestCase(support.TempdirManager,
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')