New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

tools: Let unicode error messages through #6154

Merged
merged 1 commit into from Feb 22, 2018

Conversation

Projects
None yet
6 participants
@geky
Member

geky commented Feb 21, 2018

Some toolchains (GCC) may emit error messages with unicode symbols based on the your localization settings. Instead of being passed to the user as is, the unicode causes an exception.

I'm not sure exactly what the correct fix is regarding python2+3 compat, but changing str to unicode seems to work on my setup (x86_64-linux-gnu-gcc 5.4.0 + python 2.7.12 + mbed-os-5c7cd1f + LANG=en_US.UTF-8)

cc @theotherjimmy

@theotherjimmy

unicode does not exist in Python 3. Please import it from six or do a try: ... except ImportError: like utils.py

@geky

This comment has been minimized.

Member

geky commented Feb 21, 2018

Ah, it looks like from builtins import str gets you a unicode compatible str function. @theotherjimmy does this work for you?

@theotherjimmy

This comment has been minimized.

Contributor

theotherjimmy commented Feb 21, 2018

@geky Nope. That returns a str on both python 2 and 3. str is bytes for 2 and unicode for 3. They are not compatible. Turns out that the Python documentation indicates that this is the same as str and IS WRONG.

@geky

This comment has been minimized.

Member

geky commented Feb 21, 2018

It seems to behave as unicode, even in python2:

$ python2 -c 'from builtins import str; print(str(u"\U0001f60b"))'
$ python3 -c 'from builtins import str; print(str(u"\U0001f60b"))'

This module contains backports the data types that were significantly changed in the transition from Python 2 to Python 3. [Including] an implementation of Python 3’s str object (pure Python subclass of Python 2’s builtin unicode type)

http://python-future.org/reference.html#module-future.builtins

@theotherjimmy

This comment has been minimized.

Contributor

theotherjimmy commented Feb 21, 2018

@geky That website is quite confusing: it seems to indicate that it's describing the python-future package. Are they talking about a competitor to six? or is this builtin?

@theotherjimmy

This comment has been minimized.

Contributor

theotherjimmy commented Feb 21, 2018

Either way, Sure you can use that import. It seems to work. Just take a look at the rest of the file to verify that you're not breaking any other str invocations (I don't think that will)

tools: Let unicode error messages through
Some toolchains (GCC) may emit error messages with unicode symbols based on
the your localization settings. Instead of being passed to the user as is,
the unicode causes an exception.

@geky geky force-pushed the g-fix-unicode-errors branch from 4c1634b to 0bc386a Feb 21, 2018

@geky

This comment has been minimized.

Member

geky commented Feb 21, 2018

I don't know why it is and it is confusing, but the builtins module (not __builtins__) seems to have all of the python3 builtins for python2.

I tested most of the other str invocations they all should probably have been unicode strings anyways.

@theotherjimmy

Nice 👍

@theotherjimmy

This comment has been minimized.

Contributor

theotherjimmy commented Feb 21, 2018

/morph build

@mbed-ci

This comment has been minimized.

mbed-ci commented Feb 21, 2018

Build : SUCCESS

Build number : 1207
Build artifacts/logs : http://mbed-os.s3-website-eu-west-1.amazonaws.com/?prefix=builds/6154/

Triggering tests

/morph test
/morph uvisor-test
/morph export-build
/morph mbed2-build

@mbed-ci

This comment has been minimized.

@mbed-ci

This comment has been minimized.

@0xc0170 0xc0170 added ready for merge and removed needs: CI labels Feb 22, 2018

@cmonr cmonr merged commit 6c4654a into master Feb 22, 2018

19 checks passed

AWS-CI uVisor Build & Test Success
Details
ci-morph-build build completed
Details
ci-morph-exporter build completed
Details
ci-morph-mbed2-build build completed
Details
ci-morph-test test completed
Details
continuous-integration/jenkins/pr-head This commit looks good
Details
continuous-integration/travis-ci/pr The Travis CI build passed
Details
continuous-integration/travis-ci/push The Travis CI build passed
Details
mbed-ci-generic Build finished.
Details
travis-ci/docs/ Local docs testing has passed
Details
travis-ci/events/ Local events testing has passed
Details
travis-ci/littlefs/ Local littlefs testing has passed
Details
travis-ci/mbed2-ATMEL/ Local mbed2-ATMEL testing has passed
Details
travis-ci/mbed2-MAXIM/ Local mbed2-MAXIM testing has passed
Details
travis-ci/mbed2-NORDIC/ Local mbed2-NORDIC testing has passed
Details
travis-ci/mbed2-NUVOTON/ Local mbed2-NUVOTON testing has passed
Details
travis-ci/mbed2-NXP/ Local mbed2-NXP testing has passed
Details
travis-ci/mbed2-SILICON_LABS/ Local mbed2-SILICON_LABS testing has passed
Details
travis-ci/mbed2-STM/ Local mbed2-STM testing has passed
Details

@cmonr cmonr removed the ready for merge label Feb 22, 2018

@adbridge

This comment has been minimized.

Contributor

adbridge commented Feb 23, 2018

Also reliant on #5848 for 5.8

@geky geky deleted the g-fix-unicode-errors branch Feb 23, 2018

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment