Commits

Stefan H. Holek committed a9bafd5

Read and write manifest in UTF-8 under Python 3. Fixes #303.

Comments (0)

Files changed (2)

setuptools/command/sdist.py

 
         self.get_finalized_command('egg_info').save_version_info(dest)
 
+    def _manifest_is_not_generated(self):
+        # check for special comment used in 2.7.1 and higher
+        if not os.path.isfile(self.manifest):
+            return False
 
+        fp = open(self.manifest, 'rbU')
+        try:
+            first_line = fp.readline()
+        finally:
+            fp.close()
+        return first_line != '# file GENERATED by distutils, do NOT edit\n'.encode()
+
+    def read_manifest(self):
+        """Read the manifest file (named by 'self.manifest') and use it to
+        fill in 'self.filelist', the list of files to include in the source
+        distribution.
+        """
+        log.info("reading manifest file '%s'", self.manifest)
+        manifest = open(self.manifest, 'rbU')
+        for line in manifest:
+            if sys.version_info >= (3,):
+                line = line.decode('UTF-8')
+            # ignore comments and blank lines
+            line = line.strip()
+            if line.startswith('#') or not line:
+                continue
+            self.filelist.append(line)
+        manifest.close()
 
 
 

setuptools/tests/test_sdist.py

 
         self.assertTrue(filename in cmd.filelist.files)
 
+    def test_manifest_is_written_in_utf8(self):
+        # Test for #303.
+
+        # Add file with non-ASCII filename
+        filename = os.path.join('sdist_test', 'smörbröd.py')
+        open(filename, 'w').close()
+
+        dist = Distribution(SETUP_ATTRS)
+        dist.script_name = 'setup.py'
+        cmd = sdist(dist)
+        cmd.ensure_finalized()
+
+        # squelch output
+        old_stdout = sys.stdout
+        old_stderr = sys.stderr
+        sys.stdout = StringIO()
+        sys.stderr = StringIO()
+        try:
+            cmd.run()
+        finally:
+            sys.stdout = old_stdout
+            sys.stderr = old_stderr
+
+        manifest = open(os.path.join('sdist_test.egg-info', 'SOURCES.txt'), 'rbU')
+        contents = manifest.read()
+        manifest.close()
+        self.assertTrue(len(contents))
+
+        # This must not fail:
+        contents.decode('UTF-8')
+
+    def test_manifest_is_read_in_utf8(self):
+        # Test for #303.
+
+        # Add file with non-ASCII filename
+        filename = os.path.join('sdist_test', 'smörbröd.py')
+        open(filename, 'w').close()
+
+        dist = Distribution(SETUP_ATTRS)
+        dist.script_name = 'setup.py'
+        cmd = sdist(dist)
+        cmd.ensure_finalized()
+
+        # squelch output
+        old_stdout = sys.stdout
+        old_stderr = sys.stderr
+        sys.stdout = StringIO()
+        sys.stderr = StringIO()
+        try:
+            cmd.run()
+        finally:
+            sys.stdout = old_stdout
+            sys.stderr = old_stderr
+
+        cmd.filelist.files = []
+        cmd.manifest = os.path.join('sdist_test.egg-info', 'SOURCES.txt')
+        cmd.read_manifest()
+
+        self.assertTrue(filename in cmd.filelist.files)
+
 
 def test_suite():
     return unittest.defaultTestLoader.loadTestsFromName(__name__)
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.