diff options
author | Victor Stinner <victor.stinner@haypocalc.com> | 2011-05-19 18:45:32 +0200 |
---|---|---|
committer | Victor Stinner <victor.stinner@haypocalc.com> | 2011-05-19 18:45:32 +0200 |
commit | dd13dd4bcc27fc77be7590ab0c9bf1c7c883201d (patch) | |
tree | 6214edb819cd9f5f47d5ff8142d151f5e6aa2438 | |
parent | 4c9706bd275134d513c61e07764215a7d0c2302c (diff) | |
download | cpython-git-dd13dd4bcc27fc77be7590ab0c9bf1c7c883201d.tar.gz |
Issue #12112: packaging reads and writes setup.cfg using UTF-8
-rw-r--r-- | Lib/packaging/config.py | 2 | ||||
-rw-r--r-- | Lib/packaging/create.py | 2 | ||||
-rw-r--r-- | Lib/packaging/tests/support.py | 4 | ||||
-rw-r--r-- | Lib/packaging/tests/test_config.py | 2 | ||||
-rw-r--r-- | Lib/packaging/tests/test_create.py | 12 |
5 files changed, 11 insertions, 11 deletions
diff --git a/Lib/packaging/config.py b/Lib/packaging/config.py index 9239f4a83b..9875f6881c 100644 --- a/Lib/packaging/config.py +++ b/Lib/packaging/config.py @@ -282,7 +282,7 @@ class Config: for filename in filenames: logger.debug(" reading %s", filename) - parser.read(filename) + parser.read(filename, encoding='utf-8') if os.path.split(filename)[-1] == 'setup.cfg': self._read_setup_cfg(parser, filename) diff --git a/Lib/packaging/create.py b/Lib/packaging/create.py index 0676cf188f..1df73da6f1 100644 --- a/Lib/packaging/create.py +++ b/Lib/packaging/create.py @@ -276,7 +276,7 @@ class MainProgram: return shutil.move(_FILENAME, '%s.old' % _FILENAME) - with open(_FILENAME, 'w') as fp: + with open(_FILENAME, 'w', encoding='utf-8') as fp: fp.write('[metadata]\n') # simple string entries for name in ('name', 'version', 'summary', 'download_url'): diff --git a/Lib/packaging/tests/support.py b/Lib/packaging/tests/support.py index dbd8683269..329b75504a 100644 --- a/Lib/packaging/tests/support.py +++ b/Lib/packaging/tests/support.py @@ -138,7 +138,7 @@ class TempdirManager: d = tempfile.mkdtemp(dir=self._basetempdir) return d - def write_file(self, path, content='xxx'): + def write_file(self, path, content='xxx', encoding=None): """Write a file at the given path. path can be a string, a tuple or a list; if it's a tuple or list, @@ -146,7 +146,7 @@ class TempdirManager: """ if isinstance(path, (list, tuple)): path = os.path.join(*path) - with open(path, 'w') as f: + with open(path, 'w', encoding=encoding) as f: f.write(content) def create_dist(self, **kw): diff --git a/Lib/packaging/tests/test_config.py b/Lib/packaging/tests/test_config.py index 8908c4fa4c..e6e558622a 100644 --- a/Lib/packaging/tests/test_config.py +++ b/Lib/packaging/tests/test_config.py @@ -183,7 +183,7 @@ class ConfigTestCase(support.TempdirManager, 'setup-hook': 'packaging.tests.test_config.hook'} if kwargs: opts.update(kwargs) - self.write_file('setup.cfg', SETUP_CFG % opts) + self.write_file('setup.cfg', SETUP_CFG % opts, encoding='utf-8') def get_dist(self): dist = Distribution() diff --git a/Lib/packaging/tests/test_create.py b/Lib/packaging/tests/test_create.py index 9c7a91220c..42cf34bdd1 100644 --- a/Lib/packaging/tests/test_create.py +++ b/Lib/packaging/tests/test_create.py @@ -91,7 +91,7 @@ class CreateTestCase(support.TempdirManager, def test_convert_setup_py_to_cfg(self): self.write_file((self.wdir, 'setup.py'), dedent(""" - # -*- coding: utf-8 -*- + # coding: utf-8 from distutils.core import setup long_description = '''My super Death-scription @@ -124,12 +124,12 @@ class CreateTestCase(support.TempdirManager, }, scripts=['my_script', 'bin/run'], ) - """)) + """), encoding='utf-8') sys.stdin.write('y\n') sys.stdin.seek(0) main() - with open(os.path.join(self.wdir, 'setup.cfg')) as fp: + with open(os.path.join(self.wdir, 'setup.cfg'), encoding='utf-8') as fp: lines = set(line.rstrip() for line in fp) # FIXME don't use sets @@ -171,7 +171,7 @@ class CreateTestCase(support.TempdirManager, def test_convert_setup_py_to_cfg_with_description_in_readme(self): self.write_file((self.wdir, 'setup.py'), dedent(""" - # -*- coding: utf-8 -*- + # coding: utf-8 from distutils.core import setup with open('README.txt') as fp: long_description = fp.read() @@ -191,7 +191,7 @@ class CreateTestCase(support.TempdirManager, ('share/man', ['pyxfoil.1']), ], ) - """)) + """), encoding='utf-8') self.write_file((self.wdir, 'README.txt'), dedent(''' My super Death-scription @@ -202,7 +202,7 @@ ho, baby! sys.stdin.seek(0) # FIXME Out of memory error. main() - with open(os.path.join(self.wdir, 'setup.cfg')) as fp: + with open(os.path.join(self.wdir, 'setup.cfg'), encoding='utf-8') as fp: lines = set(line.rstrip() for line in fp) self.assertEqual(lines, set(['', |