PBR

setup.cfg shall be parsed as explicitly utf-8 encoded

Bug #1745396 reported by Jan Vlčinský
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
PBR
Fix Released
Medium
Stephen Finucane

Bug Description

Currently the `setup.cfg` is open using default console encoding what is definitely not deterministic and is likely to cause Windows/Linux incompatibilities.

On line http://git.openstack.org/cgit/openstack-dev/pbr/tree/pbr/util.py?h=3.1.1#n212 the `setup.cfg` is open as:

`parser.read(path)`

what shall be changed to:

`parser.read(path, encoding="utf-8")`

This assumes that the `setup.cfg` is UTF-8 encoded what sounds like good assumption (but would be nice to have it documented).

Note, that there is related issue in python distutils https://bugs.python.org/issue32223 which is likely to cause that distutils itself will fail on MS Windows if default encoding is not UTF-8. Anyway, we have tested, that above proposed fix togather with propopes in distutils issue is really fixing the problem, so there seems to be no problem to fix the pbr part without waiting for distuitls one.

Revision history for this message
Ben Nemec (bnemec) wrote :

Unfortunately parser.read() doesn't take an encoding kwarg on Python 2, which is something we still need to support. We should be able to add some logic to handle that though.

Changed in pbr:
status: New → Confirmed
importance: Undecided → Medium
Revision history for this message
OpenStack Infra (hudson-openstack) wrote : Fix proposed to pbr (master)

Fix proposed to branch: master
Review: https://review.openstack.org/555366

Changed in pbr:
assignee: nobody → Ben Nemec (bnemec)
status: Confirmed → In Progress
Changed in pbr:
assignee: Ben Nemec (bnemec) → Stephen Finucane (stephenfinucane)
Revision history for this message
OpenStack Infra (hudson-openstack) wrote : Fix merged to pbr (master)

Reviewed: https://review.openstack.org/555366
Committed: https://git.openstack.org/cgit/openstack-dev/pbr/commit/?id=10fce39a7b0c100d982d1d987eed57e31bfb9779
Submitter: Zuul
Branch: master

commit 10fce39a7b0c100d982d1d987eed57e31bfb9779
Author: Ben Nemec <email address hidden>
Date: Thu Mar 22 16:23:15 2018 +0000

    Explicitly read setup.cfg as utf-8 on Python 3

    Per the referenced bug, relying on the terminal encoding to read
    setup.cfg is not safe. Unfortunately, Python 2 doesn't accept an
    encoding when reading config files so we need a fallback path for
    that version.

    Change-Id: If49344db2f9139c0557f6acd17671163e02468a5
    Closes-Bug: 1745396

Changed in pbr:
status: In Progress → Fix Released
Revision history for this message
Jan Vlčinský (jan-vlcinsky) wrote :

Hi

Thanks for the fix, having it fixed in Python3 is a step forward.

Anyway, there seem to be working method to have it working in Python 2 too as described in https://pymotw.com/2/ConfigParser/#unicode-configuration-data

I have to admit, our originally proposed change was not aware of this python 2 related issue.

Revision history for this message
OpenStack Infra (hudson-openstack) wrote : Fix included in openstack-dev/pbr 4.0.1

This issue was fixed in the openstack-dev/pbr 4.0.1 release.

To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.