tower icon indicating copy to clipboard operation
tower copied to clipboard

Python 3 compatibility

Open thijstriemstra opened this issue 9 years ago • 11 comments

I tried porting my own library to Python 3(.4), that depends on tower, and fixed some Python 3 errors in tower along the way. Unfortunately it's not yet possible to run the test suite under Python 3 because the translate-toolkit library is not compatible with Python 3 yet it seems, and tower depends on it.

Also updated some of the dependencies in requirements.txt and added six (comes with Django 1.6 and later).

run_tests.py now also works with Django 1.7.

thijstriemstra avatar Mar 10 '15 23:03 thijstriemstra

Thanks - this looks great. And thanks for adding the tests. Can you rebase this into one commit?

clouserw avatar Mar 23 '15 20:03 clouserw

Squashed the commits into one, never did that before, git's cool.

thijstriemstra avatar Mar 25 '15 16:03 thijstriemstra

I wonder if our testing is set up correctly. On the Travis page, if you click through to the python2.7 tests it says it's using 2.6: https://travis-ci.org/clouserw/tower/builds/55825211

@magopian - what do you think?

clouserw avatar Mar 25 '15 17:03 clouserw

I ran into that issue before and solved it with $TRAVIS_PYTHON_VERSION, for example:

language: python
python:
  - "2.7"
  - "3.4"
install:
  - "pip install -r requirements/production.txt"
  - "pip install -r requirements/testing.txt"
  - "pip install ."
script:
  - if [[ $TRAVIS_PYTHON_VERSION == '2.7' ]]; then tox -e py27,coverage; fi
  - if [[ $TRAVIS_PYTHON_VERSION == '3.4' ]]; then tox -e py34; fi

thijstriemstra avatar Mar 25 '15 18:03 thijstriemstra

The interpreter version that's displayed in travis is the one used by the travis.yml file. But this file is only used to "proxy" to tox: https://github.com/clouserw/tower/pull/32/files#diff-354f30a63fb0907d4ad57269548329e3L13

What you want, though, is at least a target (an environment) for python3, if you're porting to py3, just to make sure that it does run correctly on py3.

I therefore believe that it's missing:

  • something like - TOX_ENV=py34-1.7 here: https://github.com/clouserw/tower/pull/32/files#diff-354f30a63fb0907d4ad57269548329e3R10
  • a target in tox.ini py34-1.7: https://github.com/clouserw/tower/pull/32/files#diff-b91f3d5bd63fcd17221b267e851608e8R2
  • an env in tox.ini https://github.com/clouserw/tower/pull/32/files#diff-b91f3d5bd63fcd17221b267e851608e8R55
[testenv:py27-1.7]
basepython = python2.7
deps =
    Django==1.7.7
    {[testenv]deps}
{[testenv]deps}

magopian avatar Mar 25 '15 18:03 magopian

The python 3 builder will fail until the tower dependencies like translate-toolkit are ported. Making sure that tower is ready for it is what this PR is about.

thijstriemstra avatar Mar 25 '15 18:03 thijstriemstra

Ah, that's a hard problem to solve then, chicken and egg of some sorts. How did you make sure the code was compatible (and ran correctly) under py3 if the dependencies aren't ported yet?

If you did it by also porting the other dependencies, it means you have a fork or something? If so, maybe you can (temporarily, for the sake or running the tests) change the requirements to point to your py3 ported fork?

I personally don't usually port the code from a lib before its dependencies are already ported, to avoid this kind of issue ;)

magopian avatar Mar 25 '15 18:03 magopian

I ran 2to3 on the codebase, fixed the django 1.7 build/test runner and tried to fix the failing tests for python 3.4 but realized it the dependencies that caused the failures. So now we have something that has improved but can't be measured, so should we throw this PR away? :)

There is some flag in travis that allows you to have failing builds. Maybe setting up a 3.4 builder with that enabled helps us see when dependencies start supporting python 3?

thijstriemstra avatar Mar 25 '15 18:03 thijstriemstra

Thanks for all the info. Yeah, we should probably not land this until we can make sure it works. I've been pretty removed from the toolkit. It looks like Dwayne had a py3 branch a year ago at https://github.com/translate/translate/tree/feature/py3 . Maybe you could try to sync up with him if you're still in the py3 mood :)

clouserw avatar Mar 27 '15 17:03 clouserw

I see.

thijstriemstra avatar Mar 27 '15 17:03 thijstriemstra

I've always been baffled how this project not only has one, but two PRs, trying to add Python 3 support and it's just crickets... Sad!

thijstriemstra avatar Jan 24 '22 01:01 thijstriemstra