diff --git a/doc/source/user/using.rst b/doc/source/user/using.rst index d0ff3bd5..f8da6def 100644 --- a/doc/source/user/using.rst +++ b/doc/source/user/using.rst @@ -119,6 +119,11 @@ such as the ``extract_mesages`` section provided by Babel__. # A comment on a dedicated line value3 +.. note:: + + On Python 3 ``setup.cfg`` is explicitly read as UTF-8. On Python 2 the + encoding is dependent on the terminal encoding. + __ http://setuptools.readthedocs.io/en/latest/setuptools.html#configuring-setup-using-setup-cfg-files __ http://babel.pocoo.org/en/latest/setup.html diff --git a/pbr/util.py b/pbr/util.py index 163feb83..31a2a262 100644 --- a/pbr/util.py +++ b/pbr/util.py @@ -214,7 +214,11 @@ def cfg_to_args(path='setup.cfg', script_args=()): if not os.path.exists(path): raise errors.DistutilsFileError("file '%s' does not exist" % os.path.abspath(path)) - parser.read(path) + try: + parser.read(path, encoding='utf-8') + except TypeError: + # Python 2 doesn't accept the encoding kwarg + parser.read(path) config = {} for section in parser.sections(): config[section] = dict()