-
Notifications
You must be signed in to change notification settings - Fork 39
[scons] Python 3 support for SConscripts and related tools #297
[scons] Python 3 support for SConscripts and related tools #297
Conversation
scons 3 should also be provided by Fedora 27: https://bodhi.fedoraproject.org/updates/FEDORA-2017-0c9b229e88 |
I already stumbled upon these problems. Could you please verify that all commands from the TravisCI ( Yes, the weather already felt like November++ today ... |
Update: The examples start compiling now with SCons 3.0.0/Python 3.6, but there seem to be some more problems, including some Python errors, other build system problems:
(and similar) and some C++ errors, I don't understand yet:
I'll do more investigations in the next days. |
Thanks for fixing this!
This just says that even though the device file specifies the atmega328p to have a timer, no such implementation was found. It was supposed to be a reminder to add that. However, the model has changed completely in MODM, so can just ignore (or remove) this warning. |
Related upstream issue for the SCons tools we use for MODM. |
On my machine all the xpcc examples and unittests are building now with SCons 2.5 and 3.0 without errors, except for the above mentioned warnings and c++ errors. However, the latter seems to be a problem of compiling with GCC 7.2 for AVR, which is unrelated to SCons. |
I also tested it on my (Fedora 27) machine with scons 3. One of the tricky things is that you need jinja2 installed for python2 as well as python3 because the communication code is still running under python2. |
With CircleCI the job
Can anyone reproduce this? |
Can you try running |
At least, SCons now finds something to compile. I am not sure if the UnicodeDecodeError is related to CircleCI/Ubuntu/SCons or to the changes introduced here (
|
I would bet, this error is related to my changes. (Though, I'm wondering, why it doesn't print a complete stacktrace of the Python Exception in the CircleCI output.) I thought, it was a nice idea to update the scripts to use unicode strings instead of bytearrays, which is the native string representation in Python 3 but a bit hacky in Python 2. Later, I discovered that the |
I just rebased and gave it another try on CircleCI but it failed :-( |
What is the locale in your CircleCI environment? Precisely, what is the value of the I can reproduce the error when setting |
I'll add an |
Seems to me that |
Sadly, setting the |
Just tested a bit on my machine (where I have generated en_US.utf8 but not en_GB.utf8):
Presumably the locale must be actually available for Python to detect the correct encoding. |
Trying to add locale and locale-gen to Docker container. |
If this turns out to be too instable or too much overhead, we can still step back to hard-coding UTF-8 decoding or even handling raw bytearrays (and not doing any decoding in python at all). |
Status reporting of CircleCI workflow does not yet work, so it will be enabled later. Great work! |
@mhthies Could you please rebase onto the latest develop branch and maybe cherry-pick cd8c851 to enable CircleCI for this PR? @salkinium CircleCI then should run without a problem. @salkinium Do you suggest any rework of these commits? |
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 believe #68 needs to be reverted too.
@@ -1,4 +1,4 @@ | |||
# path to the xpcc root directory | |||
xpccpath = '../../../..' | |||
# execute the common SConstruct file | |||
execfile(xpccpath + '/scons/SConstruct') | |||
exec(compile(open(xpccpath + '/scons/SConstruct', "rb").read(), xpccpath + '/scons/SConstruct', 'exec')) |
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.
This is kinda ugly. Is there no execfile in Python 3?
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.
Nope, no execfile
in Python 3. This is the official workaround, see https://docs.python.org/3.0/whatsnew/3.0.html#builtins
One thing left to do would be changing the Python interpreter in the shebang lines of all scripts and some documentation strings from 'python2' to 'python', so each system's default Python interpreter is used and we do not depend on python2 being installed anymore. Before doing this: Could anyone test all the utility scripts (that are not included or called in the build process) for Python 3 compatibility? |
Can't we just change them to use Not having to maintain backwards compatibility to Within a year or two, once |
I'm working on it here. I added the scripts to the I opt for deleting I'll try to get in running in CircleCI as well. |
Isn't that used to convert bitmap formats?
Removed in modm too. Kill it. |
I can't see when and where it might be called. I only found |
Any update on this? |
cd4ff32
to
07ef403
Compare
Sorry, I've been into other projects for the last few weeks. Now, this branch is rebased to the current develop and supplemented with the two comments by @strongly-typed. I already fixed the missing LANG environment of the python script tests. As soon as all the ci tests are running successfully, I would change all the Shebangs and readme files from 'python2' to 'python3', so we can drop support for Python2 when necessary and not required by scons 2, as discussed by @ekiwi. |
35c72dd
to
c69e47d
Compare
There are in general two classes of python files in
The first category needs to work with python 2+3 and thus should probably be marked Sorry for the build system being so confusing @mhthies. |
I considered differentiating between those two groups of scripts, but decided to change all of them to The Shebang is only useful for scripts that may be called directly from the commandline and has no effect when the file is included from another python script, e.g. a With this in mind, I decided for |
I can't really judge the state of this feature, is it finished? If not, what's missing? |
From my side, it's finished. We should probably squash the commits and separate pure compatibility fixes, breaking changes and CI config things. Breaking changes are (as far as I'm aware):
Maybe @ekiwi wants to comment on my thoughts about the Shebang above? |
Ok, then I'll merge this latest in the first week of January for the Q4 release, until then feel free to rebase your changes as you like. And poke whoever you need to review this. |
In Python 2 envrionments, we depend on the 'future' and 'configparser' packages now, that provide compatibility for Python 3 solutions. Strings (e.g. output of subprocesses) is now decoded to Unicode strings using the system locale's default encoding. This can crash in some environments without a proper locale setting.
This commit introduces some changes that rely on the Python 2 'future' package. It also brings decoding of input strings according to the system locale's default encoding, which requires a proper system locale to be defined.
… Python 3 compatibility
This breaks the build on systems without Python 3 or the required Python 3 packages.
94fe8bf
to
d3f969b
Compare
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 doing this work!
- "python2 tools/authors.py --handles --count --shoutout --since 2017-01-01" | ||
- "python3 tools/authors.py --handles --count --shoutout --since 2017-01-01" | ||
- "python2 tools/system_design/builder/system_layout.py examples/communication/xml/communication.xml -o /tmp" | ||
- "python3 tools/system_design/builder/system_layout.py examples/communication/xml/communication.xml -o /tmp" |
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.
Is this supposed to be duplicated?
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.
Yep, as the commit message says, we want to test all scripts with Python 2 and Python 3.
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.
Ah, I didn’t see the difference there 🤦♂️
SCons 3.0.0 has been released a few days ago and it features support for Python 3.5+, without dropping Python 2.7 support. [1] Since the update, some Linux distributions (such as Arch Linux) default to the Python 3 interpreter to run scons. This breaks the xpcc build process, as the SConscript files and some other Python files, which are imported by them, are written in old Python 2 syntax. (See #293)
I tried to fix the scripts using current Python syntax and compatibility packages, that should be compatible with at least Python 2.7 and Python 3.6. Depending on the system environment, it might be necessary to install the
configparser
package for Python 2 andfuture
package for the Python interpreter in use. The only minor drawback for Python 2-users might be a slightly poorer performance of some scripts, due the the use ofdict.items()
instead ofdict.iteritems()
.Though I also updated some seperate scripts, not required by the SConscripts, I didn't test them with both Python interpreters yet. Indeed, I did only test building the RCA's robot software; so there still might be problems with some scripts.
[1] http://scons.org/scons-300-is-available.html