-
Notifications
You must be signed in to change notification settings - Fork 7.3k
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
python3 default support & solving python3 buffer migration problems #1284
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for sending these changes.
One of the long term goals for IDF was to make it work with either Python 2 or 3. esptool.py & its related tools already work this way, and it looks like you've sorted out the remaining snags.
If this PR seems to have everything working OK with Python 3 then feel free to change the comment in the root level Kconfig file from "Python 2 interpreter" to "Python interpeter" and put a note in the help section there that either 2.7 or 3.x can be used.
Before we merge this I'm going to make some internal changes so we can run CI tests with both Python 2 and 3, which should help prevent any regressions.
@@ -7,7 +7,7 @@ | |||
# SDK tool configuration | |||
# | |||
CONFIG_TOOLPREFIX="xtensa-esp32-elf-" | |||
CONFIG_PYTHON="python" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd rather not change this default here. macOS, and some Linux distros, still ship with python
and no python3
.
Hi, Have you tried the patch with python 2? I see very strange output here:
I further noticed that the Last, but not least:
Cheers, |
Hi @supernlogn , Sorry, I missed that you'd pushed more commits to this branch. Unfortunately this PR branch doesn't work for me in either Python 2 or Python 3. (I get |
It works for me in python3, but I use python3.4.3 ▶ python
Python 2.7.6 (default, Nov 23 2017, 15:49:48)
[GCC 4.8.4] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> u"asdasdasd"
u'asdasdasd'
>>>
~
▶ python3
Python 3.4.3 (default, Nov 28 2017, 16:41:13)
[GCC 4.8.4] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> u"asdasdasd"
'asdasdasd'
>>>
~
▶ python --version
Python 2.7.6
~
▶ python3 --version
Python 3.4.3
Thank you very much! |
tools/idf_monitor.py
Outdated
@@ -288,8 +288,8 @@ def handle_key(self, key): | |||
self.serial_reader.stop() | |||
else: | |||
try: | |||
key = self.translate_eol(key) | |||
self.serial.write(codecs.encode(key)) | |||
key = self.translate_eol(bytes(u(""+key), 'utf-8')) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The problem isn't u"abc", this works fine the same as in your output.
The problem is that u("abc") is an error in Python 2 & 3, as this function doesn't exist.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So, for example, the way to write this is bytes(u"" + str(key))
or bytes(u"" + key)
if you know the type of key.
Code below fixes issues mentioned by projectgus above.
|
@projectgus I have successfully changed the code as you suggested and also tested it. Thanks to everyone for your suggestions! |
python3 support has problems to buffer migration issues.
By following this official guide: http://python3porting.com/problems.html#bytes-strings-and-unicode
problems with byte and str buffers like the example below are solved.
Before doing these changes the hello world example would have produced errors while monitoring like the one below:
Also, since all buffers are figured out for python3, I think python3 should be the default interpreter for monitoring.