Merge ~pieq/bugit/+git/qabro:fix-1806841-urwid-unicode into bugit:master

Proposed by Pierre Equoy
Status: Merged
Approved by: Pierre Equoy
Approved revision: c4804d95e73ad7189f33e0f5399e3976ad2a5891
Merged at revision: 3de35054961e7c63f6509fc4be6eed686eae9dd4
Proposed branch: ~pieq/bugit/+git/qabro:fix-1806841-urwid-unicode
Merge into: bugit:master
Diff against target: 52 lines (+23/-2)
2 files modified
qabro/__version__.py (+1/-1)
snap/snapcraft.yaml (+22/-1)
Reviewer Review Type Date Requested Status
Maciej Kisielewski (community) Approve
Review via email: mp+361827@code.launchpad.net
To post a comment you must log in.
Revision history for this message
Maciej Kisielewski (kissiel) wrote :

> By default, snap doesn't transmit locale information.
I don't think that's true. Or I'm misinterpreting your statement.

Apps in a snap are given the same locale as available in the calling environment.

Overriding locale is a very bad smell. I think your problem lies in how you use urwid. All strings inside your program should be strings. If you are forced to supply raw bytes to some function, make sure that function knows how to interpret those bytes. If it's poorly written and understands ascii only, then make sure you supply it with such (stripping, or replacing all erroneous chars).

review: Needs Fixing
Revision history for this message
Pierre Equoy (pieq) wrote :

Hi Maciek and thanks for your feedback!

> Apps in a snap are given the same locale as available in the calling environment.

~$ python3
Python 3.6.7 (default, Oct 22 2018, 11:32:17)
[GCC 8.2.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import locale
>>> locale.getlocale()
('en_US', 'UTF-8')
>>>
~$ sudo snap install qabro --devmode
[sudo] password for pierre:
qabro 0.8 from Pierre Equoy (pieq) installed
~$ snap run --shell qabro
To run a command as administrator (user "root"), use "sudo <command>".
See "man sudo_root" for details.

pierre@tmonk:/home/pierre$ /usr/bin/python3
Python 3.5.2 (default, Nov 12 2018, 13:43:14)
[GCC 5.4.0 20160609] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import locale
>>> locale.getlocale()
(None, None)

both environments inside and outside of the snap contain the same LANG and the same LC_* parameters, as I explained on the snapcraft forum. [1]

According to urwid's documentation [2], urwid guesses what encoding to use based on the locale available by Python. I've run a test outside and inside the snap, and I discovered that, when outside of the snap, everything was fine (urwid.get_encoding_mode() returns "utf-8" and I can paste whatever I want in the text fields), whereas inside the snap, urwid.get_encoding_mode() returns "narrow" (which means 8bit encoding) and pasting Unicode turns it into "???".

Does the above explanation light the problem under a different light for you? Do you think it's still a problem on my side? (I'm not good at localization and encodings shenanigans :))

Thanks!

[1] https://forum.snapcraft.io/t/python-cannot-determine-the-locale-used-when-inside-a-snap/9492
[2] http://urwid.org/manual/encodings.html

Revision history for this message
Maciej Kisielewski (kissiel) wrote :

I followed this rabbit hole a bit.

Snap doesn't hide or change locale information.
If you'd check 'locale.getdefaultlocale()' your envvars from the host would still be there. It's that python sets them to (None, None) when it cannot load them as in your case. And it cannot load them b/c they are not included in the snap, or to be precise in the environment visible from within snap.

Unfortunately it's not as simple as adding '- locales' to the staged parts. It would be necessary to generate those from within the snap.

To properly fix this you'd need to create a launcher that ensures locale data is there (or maybe an install hook would even suffice). I know that QABro doesn't use translations, so I guess it's not worth the work ATM, so +1 on landing this with overriding to C.UTF-8.

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1diff --git a/qabro/__version__.py b/qabro/__version__.py
2index 0dde18a..57cb785 100644
3--- a/qabro/__version__.py
4+++ b/qabro/__version__.py
5@@ -1,5 +1,5 @@
6 __title__ = 'qabro'
7-__version__ = '0.8'
8+__version__ = '0.9dev'
9 __description__ = 'Tool to generate a Launchpad bug report and attach useful logs (using sosreport and the like).'
10 __author__ = 'Pierre Equoy'
11 __author_email__ = 'pierre.equoy@canonical.com'
12diff --git a/snap/snapcraft.yaml b/snap/snapcraft.yaml
13index ecfa2e2..93d0d71 100644
14--- a/snap/snapcraft.yaml
15+++ b/snap/snapcraft.yaml
16@@ -10,6 +10,8 @@ apps:
17 command: qabro
18 environment:
19 LD_LIBRARY_PATH: $LD_LIBRARY_PATH:$SNAP/lib/fwts
20+ LANG: C.UTF-8
21+ LC_ALL: C.UTF-8
22
23 sosreport:
24 command: sosreport
25@@ -59,7 +61,26 @@ parts:
26 patch $SNAPCRAFT_PART_INSTALL/usr/share/sosreport/sos/policies/ubuntu.py $SNAPCRAFT_STAGE/patches/sosreport-env-path-snap.patch
27
28 fwts:
29- source-tag: V18.06.02
30+ plugin: autotools
31+ source: git://kernel.ubuntu.com/hwe/fwts
32+ source-tag: V19.01.00
33+ stage-packages:
34+ - libfdt1
35+ - libbsd0
36+ - libpci3
37+ build-packages:
38+ - gcc
39+ - make
40+ - autoconf
41+ - automake
42+ - libtool
43+ - libjson-c-dev
44+ - flex
45+ - bison
46+ - dh-autoreconf
47+ - libglib2.0-dev
48+ - libfdt-dev
49+ - libbsd-dev
50
51 lspci:
52 plugin: nil

Subscribers

People subscribed via source and target branches

to all changes: