cht-core icon indicating copy to clipboard operation
cht-core copied to clipboard

Upgrade python dependency to latest

Open newtewt opened this issue 4 years ago • 5 comments

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.

newtewt avatar Jul 14 '20 19:07 newtewt

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 avatar Jul 14 '20 21:07 mrsarm

@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 avatar Jul 14 '20 22:07 newtewt

@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.

mrsarm avatar Jul 14 '20 22:07 mrsarm

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

latin-panda avatar Aug 26 '22 00:08 latin-panda

Additional context:

  • The build workflow for cht-conf is pinned to ubuntu-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 avatar Aug 26 '22 22:08 jkuester

@jkuester should this issue be in cht-conf repo instead? 🤔

latin-panda avatar Dec 20 '22 05:12 latin-panda

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....

jkuester avatar Dec 20 '22 14:12 jkuester

@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....).

jkuester avatar Jun 21 '23 15:06 jkuester

Amazing! Thanks for seeing this through. Any idea what changed since this comment?

garethbowen avatar Jun 21 '23 21:06 garethbowen

@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.

jkuester avatar Jun 22 '23 14:06 jkuester

Ok. Closing this as already done. Please reopen if we've missed anything!

garethbowen avatar Jun 22 '23 20:06 garethbowen