cht-core
cht-core copied to clipboard
Upgrade python dependency to latest
Describe the issue Python 2 hit end of life Jan 2020.
Describe the improvement you'd like We should move to python3 or possibly investigate other solutions if need be.
Running list of things that are affected.
- [ ] Medic-conf
npm test
fail because xml elements are in a different order than the stored files we have in test. - [ ] prepare.sh has some commands that won't run if you don't have python.
I think we should maintain compatibility with Python 2 while moving to Python 3 as "main" version. To do that, checking the code of our pyxform we can figure out why the XML are produced in that why and fix it, not because it is a bug but to maintain compatibility.
As far I could see today, the difference between the XML produced when used with Python 3 is that the attributes in the XML tags are sorted alphabetically, while in Python 2 may use another sorting. If that is not hard to fix, maybe the only important change to move smoothly to Python 3.
Python 2:
<bind nodeset="/data/contact/role_other" type="string" relevant="selected( /data/contact/role ,'other')" required="true()"/>
Python 3:
<bind nodeset="/data/contact/role_other" relevant="selected( /data/contact/role ,'other')" required="true()" type="string"/>
@mrsarm I think I have a solution that will work regardless. Using chai-xml
compares it and we don't have to worry about ordering. I'll have a pull request in for that tomorrow and get your feedback.
@newtewt yes but are we sure that generating the XML like that does not represent any issue in the CHT apps? It shouldn't, XML attributes' order should not be taken into account, just wanted to confirm.
As far I could see, using the medic-conf with Python 3 works well, I could use it to export the default configuration under this folder, but not sure if something was not exported well and I did not notice the error, although it is unlikely.
Currently running grunt dev-webapp
with python 3 throw errors. Probably after Enketo uplift but not sure what exactly cause it. The commands runs well with python V2.7
Additional context:
- The
build
workflow for cht-conf is pinned toubuntu-20.04
instead of being set to the latest version due to it being dependent on Python 2. This should be updated once we are no longer dependent on Python 2. https://github.com/medic/cht-conf/pull/503 - I think that updating our base Python version is also going to involve fixing this: https://github.com/medic/pyxform/issues/8
@jkuester should this issue be in cht-conf repo instead? 🤔
IIRC, https://github.com/medic/pyxform is actually the project that needs to be "upgraded" to support Python3 (probably as a part of https://github.com/medic/pyxform/issues/8).
Once Pyxform supports Python3, then I think there is nothing else in cht-conf or cht-core that is dependent on the old python version. :thinking: I have added a link to this issue from the Pyxform issue, but IMHO we can leave this issue here for now to capture this conversation and linkage....
@garethbowen I think we might actually be able to close this issue. cht-core is already building fine with Python3 (I cannot find any references/scripts/etc in the repo that reference Python 2.x....). Additionally, cht-conf seems to work fine with Python3 as well. TLDR is that there does not seem to be any compatibility issues with Python3 (in fact, our dev setup docs are already instructing folks to use Python3....).
Amazing! Thanks for seeing this through. Any idea what changed since this comment?
@garethbowen surprisingly, it was this change: https://github.com/medic/cht-core/commit/beadf34ecfa71f25efe7e7f29f927b0c21c6a2e6
I tested building cht-core at the commit directly before that one (without having Python2 installed) and it failed while trying to build libxslt
. The build works fine when I run it from that commit.
Ok. Closing this as already done. Please reopen if we've missed anything!