summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorZuul <zuul@review.opendev.org>2019-06-10 22:55:38 +0000
committerGerrit Code Review <review@openstack.org>2019-06-10 22:55:38 +0000
commit17f9439e9f9026dd3e8cae1e917a78e80195152c (patch)
tree513bcc7b613db12ca65b9d5be5b2ca127bcdeb6c
parente5c6099e1dc4071259e7e4c5aef80b641ff45366 (diff)
parent3b102a551bb2518682a0da4e6065feeb7f20807a (diff)
downloadpbr-17f9439e9f9026dd3e8cae1e917a78e80195152c.tar.gz
Merge "Read description file as utf-8"5.3.0
-rw-r--r--pbr/tests/test_util.py20
-rw-r--r--pbr/util.py3
2 files changed, 22 insertions, 1 deletions
diff --git a/pbr/tests/test_util.py b/pbr/tests/test_util.py
index 393bc5c..1cbb2d2 100644
--- a/pbr/tests/test_util.py
+++ b/pbr/tests/test_util.py
@@ -1,3 +1,4 @@
+# -*- coding: utf-8 -*-
# Copyright (c) 2015 Hewlett-Packard Development Company, L.P. (HP)
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may
@@ -13,6 +14,7 @@
# under the License.
import io
+import tempfile
import textwrap
import six
@@ -197,3 +199,21 @@ class TestDataFilesParsing(base.BaseTestCase):
self.assertEqual(self.data_files,
list(kwargs['data_files']))
+
+
+class TestUTF8DescriptionFile(base.BaseTestCase):
+ def test_utf8_description_file(self):
+ _, path = tempfile.mkstemp()
+ ini_template = """
+ [metadata]
+ description_file = %s
+ """
+ # Two \n's because pbr strips the file content and adds \n\n
+ # This way we can use it directly as the assert comparison
+ unicode_description = u'UTF8 description: é"…-ʃŋ\'\n\n'
+ ini = ini_template % path
+ with io.open(path, 'w', encoding='utf8') as f:
+ f.write(unicode_description)
+ config = config_from_ini(ini)
+ kwargs = util.setup_cfg_to_setup_kwargs(config)
+ self.assertEqual(unicode_description, kwargs['long_description'])
diff --git a/pbr/util.py b/pbr/util.py
index e931b5f..323747e 100644
--- a/pbr/util.py
+++ b/pbr/util.py
@@ -62,6 +62,7 @@ except ImportError:
import logging # noqa
from collections import defaultdict
+import io
import os
import re
import shlex
@@ -320,7 +321,7 @@ def setup_cfg_to_setup_kwargs(config, script_args=()):
in_cfg_value = split_multiline(in_cfg_value)
value = ''
for filename in in_cfg_value:
- description_file = open(filename)
+ description_file = io.open(filename, encoding='utf-8')
try:
value += description_file.read().strip() + '\n\n'
finally: