[Python-checkins] distutils2: Change resource files declaration in setup.cfg

tarek.ziade python-checkins at python.org
Wed Feb 16 22:23:59 CET 2011


tarek.ziade pushed 3841fa64b64c to distutils2:

http://hg.python.org/distutils2/rev/3841fa64b64c
changeset:   1089:3841fa64b64c
user:        Pierre-Yves David <pierre-yves.david at ens-lyon.org>
date:        Sun Feb 06 18:23:06 2011 +0100
summary:
  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.

files:
  distutils2/config.py
  distutils2/mkcfg.py
  distutils2/tests/test_config.py
  distutils2/tests/test_mkcfg.py

diff --git a/distutils2/config.py b/distutils2/config.py
--- a/distutils2/config.py
+++ b/distutils2/config.py
@@ -106,6 +106,7 @@
         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 @@
             # 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:
+            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:
+                    assert len(rich_glob) == 1
                     prefix = ''
-                    suffix = splitted_glob[0]
-                else:
-                    prefix = splitted_glob[0]
-                    suffix = splitted_glob[1]
+                    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
--- a/distutils2/mkcfg.py
+++ b/distutils2/mkcfg.py
@@ -629,9 +629,11 @@
                     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
--- a/distutils2/tests/test_config.py
+++ b/distutils2/tests/test_config.py
@@ -73,10 +73,10 @@
   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 @@
         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 @@
         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
--- a/distutils2/tests/test_mkcfg.py
+++ b/distutils2/tests/test_mkcfg.py
@@ -146,9 +146,9 @@
             '    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 @@
               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 @@
         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 @@
             '[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}',
         ]))
 
 

--
Repository URL: http://hg.python.org/distutils2


More information about the Python-checkins mailing list