Hi,

Le 09/10/2015 12:12, vishal yadav a écrit :
However I was just checking if you considered using 2to3. I can
understand that translation using this tool might not cover every area
in the code more specifically custom/3rd party libraries (non-standard
python libraries) but IMO it can do fixer translations to much extent.

I tried 2to3, modernize and 2to6 tools in the past, but they produce a single giant patch with unwanted changes. These tools are written to add compatibility for all Python versions including Python 2.6 and Python 3.0. In OpenStack, we only care of Python 2.7 and 3.4, so the code can be simpler. For example, we can simply write u"unicode" instead of six.b("unicode").

I wrote the sixer tool for OpenStack. Basically, it's the same than 2to6, except that:

- sixer respects OpenStack Coding Style on imports: it groups and sorts imports. It avoids to have to manually fix individual modified import which takes a lot of time

- sixer can produce a patch for a single pattern. For example, replace all unicode with six.text_type but nothing else. Since all changes are reviewed carefully in OpenStack, it's important to produce "reviewable" (small) changes.

See also my blog article which explains the full rationale:
http://haypo.github.io/python3-sixer.html

My patch serie of 6 changes to fix most Python 3 issues was almost fully generated by sixer. Sometimes, I had to manually fix a few lines because no tool is perfect ;-) The patch serie:

* "py3: Replace unicode with six.text_type"
  https://review.openstack.org/#/c/232476/

* "py3: Replace urllib imports with six.moves.urllib"
  https://review.openstack.org/#/c/232536/

* "py3: Use six.reraise() to reraise an exception"
  https://review.openstack.org/#/c/232537/

* "py3: Replace gen.next() with next(gen)"
  https://review.openstack.org/#/c/232538/

* "Replace itertools.ifilter with six.moves.filter"
  https://review.openstack.org/#/c/232539/

* "py3: Replace basestring with six.string_types"
  https://review.openstack.org/#/c/232540/

Then I will then use sixer on individual files to fix all Python 3 at once.

Victor

__________________________________________________________________________
OpenStack Development Mailing List (not for usage questions)
Unsubscribe: [email protected]?subject:unsubscribe
http://lists.openstack.org/cgi-bin/mailman/listinfo/openstack-dev

Reply via email to