Commit 6851d4e3 authored by Stefan H. Holek's avatar Stefan H. Holek

Make sure the manifest never contains decomposed UTF-8.

--HG--
branch : distribute
extra : rebase_source : 0e0fb3beac56f66f12670ec69ebfd3996d12d912
parent 077a69ae
......@@ -287,6 +287,19 @@ class FileList(FileList):
def compose(path):
# Apple's HFS Plus returns decomposed UTF-8. Since just about
# everyone else chokes on it, we must make sure to return fully
# composed UTF-8 only.
if sys.getfilesystemencoding().lower() == 'utf-8':
from unicodedata import normalize
if sys.version_info >= (3,):
path = normalize('NFC', path)
else:
path = normalize('NFC', path.decode('utf-8')).encode('utf-8')
return path
class manifest_maker(sdist):
template = "MANIFEST.in"
......@@ -311,6 +324,7 @@ class manifest_maker(sdist):
self.prune_file_list()
self.filelist.sort()
self.filelist.remove_duplicates()
self.filelist.files = [compose(path) for path in self.filelist.files]
self.write_manifest()
def write_manifest (self):
......
# -*- coding: utf-8 -*-
"""sdist tests"""
......@@ -74,6 +75,36 @@ class TestSdistTest(unittest.TestCase):
manifest = cmd.filelist.files
self.assert_(os.path.join('sdist_test', 'a.txt') in manifest)
self.assert_(os.path.join('sdist_test', 'b.txt') in manifest)
self.assert_(os.path.join('sdist_test', 'c.rst') not in manifest)
self.assertTrue(os.path.join('sdist_test', 'a.txt') in manifest)
self.assertTrue(os.path.join('sdist_test', 'b.txt') in manifest)
self.assertTrue(os.path.join('sdist_test', 'c.rst') not in manifest)
def test_filelist_is_fully_composed(self):
# Test for #303. Requires HFS Plus to fail.
# 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
self.assertTrue(filename in cmd.filelist.files)
def test_suite():
return unittest.defaultTestLoader.loadTestsFromName(__name__)
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment