Julien Jehannet avatar Julien Jehannet committed 409d512

Avoid double-declaration in double-declaration in description- and extra- files

Since changeset c8dfb3c63894, files in metadata must be declared in `extra_files`.
In order to simplify the declaration, include automatically these files when
under project directory.

The detection is really done by these two conditions:
- is not an absolute path
- not in one of parent directory

Note: the heuristic is quite fragile here (file could starts with ..)

Comments (0)

Files changed (2)


         reading the manifest, or just using the default file set -- it all
         depends on the user's options.
+        # Remark: external path files are allowed in setup.cfg
+        # This implies declarations in `extra_files` to include them in the
+        # source distribution but we want make them implicit when files are
+        # already under the project path (i.e. not absolute paths or not in
+        # parent directory)
+        for file in self.distribution.metadata.requires_files:
+            # XXX fragile heuristic: file cannot starts with '..'
+            if (not os.path.isabs(file) and
+                not os.path.normpath(file).startswith('..')):
+                 self.distribution.metadata.requires_files.remove(file)
+                 self.distribution.extra_files.append(file)
+                 self.filelist.append(file)
         template_exists = len(self.distribution.extra_files) > 0
         if not template_exists:
             self.warn('Using default file list')
         if self.use_defaults:
         if template_exists:
             template = '\n'.join(self.distribution.extra_files)


 import os
 import sys
 from StringIO import StringIO
+import tempfile
 from distutils2.tests import unittest, support, run_unittest
 from distutils2.command.sdist import sdist
         self.assertEqual(ext.extra_compile_args, ['-fPIC', '-O2'])
         self.assertEqual(ext.language, 'cxx')
+    def test_metadata_requires_external_description_files(self):
+        tmpdir = tempfile.mkdtemp()
+        readme = os.path.join(tmpdir, 'README')
+        self.write_setup({'description-file': readme + '\n'})
+        self.write_file(readme, 'yeah')
+        self.write_file('haven.py', '#')
+        self.write_file('script1.py', '#')
+        os.mkdir('scripts')
+        self.write_file(os.path.join('scripts', 'find-coconuts'), '#')
+        os.mkdir('bin')
+        self.write_file(os.path.join('bin', 'taunt'), '#')
+        os.mkdir('src')
+        for pkg in ('one', 'two', 'three'):
+            pkg = os.path.join('src', pkg)
+            os.mkdir(pkg)
+            self.write_file(os.path.join(pkg, '__init__.py'), '#')
+        dist = self.run_setup('--version')
+        cmd = sdist(dist)
+        cmd.finalize_options()
+        cmd.get_file_list()
+        self.assertRaises(DistutilsFileError, cmd.make_distribution)
     def test_metadata_requires_description_files_missing(self):
         self.write_setup({'description-file': 'README\n  README2'})
         cmd = sdist(dist)
-        self.assertRaises(DistutilsFileError, cmd.make_distribution)
+        cmd.make_distribution()
+        self.assertIn('README\nREADME2\n', open('MANIFEST').read())
+        # test if double-declaration in description- and extra- files
         self.write_setup({'description-file': 'README\n  README2',
                           'extra-files': '\n  README2\n    README'})
         dist = self.run_setup('--description')
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.