diff options
| author | Pierre-Yves David <pierre-yves.david@ens-lyon.org> | 2011-02-06 18:23:06 +0100 |
|---|---|---|
| committer | Pierre-Yves David <pierre-yves.david@ens-lyon.org> | 2011-02-06 18:23:06 +0100 |
| commit | efc095cc5bf7c04a605e8a5bc60a940b4554d264 (patch) | |
| tree | 45f1cf827efe2f9089d62ea9e4e18ff2f1013982 | |
| parent | d081a9fd2569a3c70e96b0857930ea14b0488efd (diff) | |
| download | disutils2-efc095cc5bf7c04a605e8a5bc60a940b4554d264.tar.gz | |
Change resource files declaration in setup.cfg
Resource files declaration move from they own section ``[resources]`` to a
``resources`` key in the ``[files]`` section. The format of the declaration in
the ``resources`` key stay the same::
[<base-glob>] <glob> = {dispatch}/destination/
this change is motivated by the fact that config parser "key" are always
lower case and can't hold file path information propertly.
| -rw-r--r-- | distutils2/config.py | 26 | ||||
| -rw-r--r-- | distutils2/mkcfg.py | 6 | ||||
| -rw-r--r-- | distutils2/tests/test_config.py | 19 | ||||
| -rw-r--r-- | distutils2/tests/test_mkcfg.py | 17 |
4 files changed, 35 insertions, 33 deletions
diff --git a/distutils2/config.py b/distutils2/config.py index 86016d8..5b6e54e 100644 --- a/distutils2/config.py +++ b/distutils2/config.py @@ -106,6 +106,7 @@ class Config(object): return value def _read_setup_cfg(self, parser, cfg_filename): + cfg_directory = os.path.dirname(os.path.abspath(cfg_filename)) content = {} for section in parser.sections(): content[section] = dict(parser.items(section)) @@ -197,24 +198,21 @@ class Config(object): # manifest template self.dist.extra_files = files.get('extra_files', []) - if 'resources' in content: resources = [] - for glob, destination in content['resources'].iteritems(): - splitted_glob = glob.split(' ', 1) - if len(splitted_glob) == 1: - prefix = '' - suffix = splitted_glob[0] + for rule in files.get('resources', []): + glob , destination = rule.split('=', 1) + rich_glob = glob.strip().split(' ', 1) + if len(rich_glob) == 2: + prefix, suffix = rich_glob else: - prefix = splitted_glob[0] - suffix = splitted_glob[1] + assert len(rich_glob) == 1 + prefix = '' + suffix = glob if destination == '<exclude>': destination = None - resources.append((prefix, suffix, destination)) - - directory = os.path.dirname(os.path.join(os.getcwd(), cfg_filename)) - data_files = resources_dests(directory, resources) - self.dist.data_files = data_files - + resources.append((prefix.strip(), suffix.strip(), destination.strip())) + self.dist.data_files = resources_dests(cfg_directory, resources) + ext_modules = self.dist.ext_modules for section_key in content: labels = section_key.split('=') diff --git a/distutils2/mkcfg.py b/distutils2/mkcfg.py index c475358..4cb6e30 100644 --- a/distutils2/mkcfg.py +++ b/distutils2/mkcfg.py @@ -629,9 +629,11 @@ class MainProgram(object): continue fp.write('%s = %s\n' % (name, '\n '.join(self.data[name]).strip())) - fp.write('\n[resources]\n') + fp.write('\nresources =\n') for src, dest in self.data['resources']: - fp.write('%s = %s\n' % (src, dest)) + fp.write(' %s = %s\n' % (src, dest)) + fp.write('\n') + finally: fp.close() diff --git a/distutils2/tests/test_config.py b/distutils2/tests/test_config.py index 37aa834..9ee2514 100644 --- a/distutils2/tests/test_config.py +++ b/distutils2/tests/test_config.py @@ -73,10 +73,10 @@ sdist_extra = recursive-include examples *.txt *.py prune examples/sample?/build -[resources] -bm/ {b1,b2}.gif = {icon} -cfg/ data.cfg = {config} -init_script = {script} +resources= + bm/ {b1,b2}.gif = {icon} + Cf*/ *.CFG = {config}/baBar/ + init_script = {script}/JunGle/ [global] commands = @@ -196,8 +196,8 @@ class ConfigTestCase(support.TempdirManager, os.mkdir('bm') self.write_file(os.path.join('bm', 'b1.gif'), '') self.write_file(os.path.join('bm', 'b2.gif'), '') - os.mkdir('cfg') - self.write_file(os.path.join('cfg', 'data.cfg'), '') + os.mkdir('Cfg') + self.write_file(os.path.join('Cfg', 'data.CFG'), '') self.write_file('init_script', '') # try to load the metadata now @@ -243,11 +243,12 @@ 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(dist.data_files, + self.assertEqual( {'bm/b1.gif' : '{icon}/b1.gif', 'bm/b2.gif' : '{icon}/b2.gif', - 'cfg/data.cfg' : '{config}/data.cfg', - 'init_script' : '{script}/init_script'}) + 'Cfg/data.CFG' : '{config}/baBar/data.CFG', + 'init_script' : '{script}/JunGle/init_script'}, + dist.data_files) self.assertEqual(dist.package_dir, 'src') diff --git a/distutils2/tests/test_mkcfg.py b/distutils2/tests/test_mkcfg.py index 7e9da39..3caeca0 100644 --- a/distutils2/tests/test_mkcfg.py +++ b/distutils2/tests/test_mkcfg.py @@ -146,9 +146,9 @@ class MkcfgTestCase(support.TempdirManager, ' pyxfoil/fengine.so', 'scripts = my_script', ' bin/run', - '[resources]', - 'README.rst = {doc}', - 'pyxfoil.1 = {man}', + 'resources =', + ' README.rst = {doc}', + ' pyxfoil.1 = {man}', ])) def test_convert_setup_py_to_cfg_with_description_in_readme(self): @@ -166,7 +166,7 @@ class MkcfgTestCase(support.TempdirManager, url='http://www.python-science.org/project/pyxfoil', license='GPLv2', packages=['pyxfoil'], - package_data={'pyxfoil' : ['fengine.so']}, + package_data={'pyxfoil' : ['fengine.so', 'babar.so']}, data_files=[ ('share/doc/pyxfoil', ['README.rst']), ('share/man', ['pyxfoil.1']), @@ -184,7 +184,7 @@ ho, baby ! main() fp = open(os.path.join(self.wdir, 'setup.cfg')) try: - lines = set([line.strip() for line in fp]) + lines = set([line.rstrip() for line in fp]) finally: fp.close() self.assertEqual(lines, set(['', @@ -200,9 +200,10 @@ ho, baby ! '[files]', 'packages = pyxfoil', 'extra_files = pyxfoil/fengine.so', - '[resources]', - 'README.rst = {doc}', - 'pyxfoil.1 = {man}', + ' pyxfoil/babar.so', + 'resources =', + ' README.rst = {doc}', + ' pyxfoil.1 = {man}', ])) |
