diff -r af7bc95e5b1e -r 82136b377981 Lib/packaging/config.py --- a/Lib/packaging/config.py Thu Jun 09 14:10:07 2011 +0200 +++ b/Lib/packaging/config.py Thu Jun 09 12:31:51 2011 -0400 @@ -9,7 +9,8 @@ from packaging import logger from packaging.errors import PackagingOptionError from packaging.compiler.extension import Extension -from packaging.util import check_environ, iglob, resolve_name, strtobool +from packaging.util import (check_environ, iglob, resolve_name, strtobool, + split_multiline) from packaging.compiler import set_compiler from packaging.command import set_command from packaging.markers import interpret @@ -124,12 +125,6 @@ # XXX return value - def _multiline(self, value): - value = [v for v in - [v.strip() for v in value.split('\n')] - if v != ''] - return value - def _read_setup_cfg(self, parser, cfg_filename): cfg_directory = os.path.dirname(os.path.abspath(cfg_filename)) content = {} @@ -155,7 +150,7 @@ for key, value in content['metadata'].items(): key = key.replace('_', '-') if metadata.is_multi_field(key): - value = self._multiline(value) + value = split_multiline(value) if key == 'project-url': value = [(label.strip(), url.strip()) @@ -192,7 +187,7 @@ files = content['files'] self.dist.package_dir = files.pop('packages_root', None) - files = dict((key, self._multiline(value)) for key, value in + files = dict((key, split_multiline(value)) for key, value in files.items()) self.dist.packages = [] @@ -310,7 +305,7 @@ opt = opt.replace('-', '_') if opt == 'sub_commands': - val = self._multiline(val) + val = split_multiline(val) if isinstance(val, str): val = [val] @@ -348,14 +343,14 @@ raise PackagingOptionError(msg) def _load_compilers(self, compilers): - compilers = self._multiline(compilers) + compilers = split_multiline(compilers) if isinstance(compilers, str): compilers = [compilers] for compiler in compilers: set_compiler(compiler.strip()) def _load_commands(self, commands): - commands = self._multiline(commands) + commands = split_multiline(commands) if isinstance(commands, str): commands = [commands] for command in commands: diff -r af7bc95e5b1e -r 82136b377981 Lib/packaging/tests/test_util.py --- a/Lib/packaging/tests/test_util.py Thu Jun 09 14:10:07 2011 +0200 +++ b/Lib/packaging/tests/test_util.py Thu Jun 09 12:31:51 2011 -0400 @@ -8,16 +8,18 @@ from io import StringIO from packaging.tests import support, unittest +from packaging.tests.test_config import SETUP_CFG from packaging.errors import ( PackagingPlatformError, PackagingByteCompileError, PackagingFileError, PackagingExecError, InstallationException) from packaging import util +from packaging.dist import Distribution from packaging.util import ( convert_path, change_root, split_quoted, strtobool, rfc822_escape, get_compiler_versions, _MAC_OS_X_LD_VERSION, byte_compile, find_packages, spawn, get_pypirc_path, generate_pypirc, read_pypirc, resolve_name, iglob, RICH_GLOB, egginfo_to_distinfo, is_setuptools, is_distutils, is_packaging, - get_install_method) + get_install_method, cfg_to_args) PYPIRC = """\ @@ -92,9 +94,13 @@ def setUp(self): super(UtilTestCase, self).setUp() - self.tmp_dir = self.mkdtemp() - self.rc = os.path.join(self.tmp_dir, '.pypirc') - os.environ['HOME'] = self.tmp_dir + + self.addCleanup(os.chdir, os.getcwd()) + tempdir = self.mkdtemp() + os.chdir(tempdir) + self.tempdir = tempdir + self.rc = os.path.join(self.tempdir, '.pypirc') + os.environ['HOME'] = self.tempdir # saving the environment self.name = os.name self.platform = sys.platform @@ -492,6 +498,39 @@ self.assertEqual(content, WANTED) + def test_cfg_to_args(self): + opts = {'description-file': 'README', 'extra-files': '', + 'setup-hook': 'packaging.tests.test_config.hook'} + self.write_file('setup.cfg', SETUP_CFG % opts) + self.write_file('README', 'loooong description') + + args = cfg_to_args() + dist = Distribution() + dist.parse_config_files() + + metadata = dist.metadata + + # Just compare what's in the Distribution to the setup() args + self.assertEqual(args['name'], metadata['Name']) + # + .dev1 because the test SETUP_CFG also tests a hook function in + # test_config.py for appending to the version string. + self.assertEqual(args['version'] + '.dev1', metadata['Version']) + self.assertEqual(args['author'], metadata['Author']) + self.assertEqual(args['author_email'], metadata['Author-Email']) + self.assertEqual(args['maintainer'], metadata['Maintainer']) + self.assertEqual(args['maintainer_email'], metadata['Maintainer-Email']) + self.assertEqual(args['description'], metadata['Summary']) + self.assertEqual(args['long_description'], metadata['Description']) + self.assertEqual(args['classifiers'], metadata['Classifier']) + self.assertEqual(args['requires'], metadata['Requires-Dist']) + self.assertEqual(args['provides'], metadata['Provides-Dist']) + + self.assertEqual(args['package_dir'].get(''), dist.package_dir) + self.assertEqual(args['packages'], dist.packages) + self.assertEqual(args['scripts'], dist.scripts) + self.assertEqual(args['py_modules'], dist.py_modules) + + class GlobTestCaseBase(support.TempdirManager, support.LoggingCatcher, unittest.TestCase): diff -r af7bc95e5b1e -r 82136b377981 Lib/packaging/util.py --- a/Lib/packaging/util.py Thu Jun 09 14:10:07 2011 +0200 +++ b/Lib/packaging/util.py Thu Jun 09 12:31:51 2011 -0400 @@ -250,6 +250,14 @@ return words +def split_multiline(value): + """Split a multiline string into a list, excluding blank lines.""" + + return [v for v in + [v.strip() for v in value.split('\n')] + if v != ''] + + def execute(func, args, msg=None, verbose=0, dry_run=False): """Perform some action that affects the outside world. @@ -1010,16 +1018,20 @@ "requires": ("metadata", "requires_dist"), "provides": ("metadata", "provides_dist"), # ** "obsoletes": ("metadata", "obsoletes_dist"), # ** + "package_dir": ("files", 'packages_root'), "packages": ("files",), "scripts": ("files",), "py_modules": ("files", "modules"), # ** } MULTI_FIELDS = ("classifiers", + "platforms", "requires", - "platforms", + "provides", + "obsoletes", "packages", - "scripts") + "scripts", + "py_modules") def has_get_option(config, section, option): if config.has_option(section, option): @@ -1031,9 +1043,9 @@ # The real code starts here config = RawConfigParser() - if not os.path.exists(file): + if not os.path.exists(path): raise PackagingFileError("file '%s' does not exist" % - os.path.abspath(file)) + os.path.abspath(path)) config.read(path) kwargs = {} @@ -1050,17 +1062,24 @@ in_cfg_value = has_get_option(config, section, option) if not in_cfg_value: # There is no such option in the setup.cfg - if arg == "long_description": - filename = has_get_option(config, section, "description_file") - if filename: - with open(filename) as fp: - in_cfg_value = fp.read() + if arg == 'long_description': + filenames = has_get_option(config, section, 'description-file') + if filenames: + filenames = split_multiline(filenames) + in_cfg_value = [] + for filename in filenames: + with open(filename) as fp: + in_cfg_value.append(fp.read()) + in_cfg_value = '\n\n'.join(in_cfg_value) else: continue + if arg == 'package_dir' and in_cfg_value: + in_cfg_value = {'': in_cfg_value} + if arg in MULTI_FIELDS: # support multiline options - in_cfg_value = in_cfg_value.strip().split('\n') + in_cfg_value = split_multiline(in_cfg_value) kwargs[arg] = in_cfg_value