Differences between revisions 13 and 14
Revision 13 as of 2016-08-21 12:15:53
Size: 1653
Editor: PulkitGoyal
Comment:
Revision 14 as of 2017-03-11 20:57:40
Size: 2421
Editor: PulkitGoyal
Comment:
Deletions are marked like this. Additions are marked like this.
Line 4: Line 4:
To see a summary of our current position on Python 3 support, see SupportedPythonVersions#Python_3.x_support.
Line 6: Line 5:
This is a status page for keeping track of what needs to be done to make progress on Mercurial on Python 3.

GregorySzorc,
AugieFackler, YuyaNishihara and PulkitGoyal are some of those who are responsible for the work done until now. PulkitGoyal was selected as GSoC student to do the porting work with MartijnPieters as his mentor.
This is a status page for keeping track of what needs to be done to make progress on Mercurial on Python 3. Our current aim is to support Python 3.5.
Line 11: Line 8:
run-tests.py can pass its own tests (test-run-tests.py and test-run-tests.t) under 2.6, 2.7 and 3.5. `hg version` works on Python 3 without using any out of core extensions. `hg debuginstall` is our next goal and it's nearly complete. These won't work for you if you have out of core extensions enabled.
Line 13: Line 10:
== Next Steps ==
 * Eliminate all Python 3 compatibility warnings from [[https://selenic.com/repo/hg/file/default/tests/test-check-py3-compat.t|test-check-py3-compat.t]]
 * Get the entire codebase working with 'from future import absolute_import' (Exceptions Left)
  * This requires fixing some cyclic imports. See [[https://selenic.com/repo/hg/file/default/tests/test-check-module-imports.t|test-check-module-imports.t]] for currently whitelisted cyclic imports. (./)
 * Make existing modules at least parse with Python 3 (still some Python 2.x syntax)
 * Remove 2to3 and have the source be 2.6/2.7/3.5 compatible (./)
 * Conditionalize imports for renamed modules (./)
 * Get the C extensions compiling correctly in Python 3
 * The codebase uses a source transformer which converts every string to bytes and few other hacks which are required to port. There are places where unicode is required in both Python 2 and 3, there are places where unicode is required in Python 3, and bytes in Python 2. So these things are to be fixed.
== Contributing ==

We will be happy to review patches and speed up the work related to Python 3. Before you start there are few things related to current porting and how things work currently.

 * We have a source transformer which does following things on Python 3.
    1. It adds b'' in front of string starting with "'" or '"' and not having any u'', r'' or b'' in front.
    2. Adds this line `from mercurial.pycompat import delattr, getattr, hasattr, setattr, xrange, open` on every python file.
    3. Converts every occurrence of `iteritems` to `items` on Python 3.
    4. Converts argument of *attr and encode, decode to unicodes by adding u''.
    5. The transformer currently works on `mercurial/, hgext/ and hgext3rd/`.
    6. The transformer code lies [[https://www.mercurial-scm.org/repo/hg/file/tip/mercurial/__init__.py#l124|here]] and you can also use transformer on your .py files by adding them in the transformer.

  * Due to everything is unicodes by default in Python 3, and we need to rely on bytes, we have [[https://www.mercurial-scm.org/repo/hg/file/tip/mercurial/pycompat.py|pycompat.py]] which contains hacks related to various functions of `os` module on Python.

  * We also have encoding.environ which helps us using a bytes version of os.environ on both Python 2 and 3.

  * There are currently two tests which are based on Python 3 compatibility and few checks in our linter [[https://www.mercurial-scm.org/repo/hg/file/tip/tests/test-check-code.t|test-check-code.t]] to make sure new patches include things from `pycompat.py`.

    1. [[https://www.mercurial-scm.org/repo/hg/file/tip/tests/test-check-py3-compat.t|test-check-py3-compat.t]] : This test was used initially to fix a lot of things, not very much helpful now.
    2. [[https://www.mercurial-scm.org/repo/hg/file/tip/tests/test-check-py3-commands.t|test-check-py3-commands.t]]: This test which things actually works on Python 3. You can see in the test that `hg version` runs on vanilla hg.

Note:

This page is primarily intended for developers of Mercurial.

Python 3

This is a status page for keeping track of what needs to be done to make progress on Mercurial on Python 3. Our current aim is to support Python 3.5.

1. What Works

hg version works on Python 3 without using any out of core extensions. hg debuginstall is our next goal and it's nearly complete. These won't work for you if you have out of core extensions enabled.

2. Contributing

We will be happy to review patches and speed up the work related to Python 3. Before you start there are few things related to current porting and how things work currently.

  • We have a source transformer which does following things on Python 3.
    1. It adds b in front of string starting with "'" or '"' and not having any u, r or b in front.

    2. Adds this line from mercurial.pycompat import delattr, getattr, hasattr, setattr, xrange, open on every python file.

    3. Converts every occurrence of iteritems to items on Python 3.

    4. Converts argument of *attr and encode, decode to unicodes by adding u.

    5. The transformer currently works on mercurial/, hgext/ and hgext3rd/.

    6. The transformer code lies here and you can also use transformer on your .py files by adding them in the transformer.

    • Due to everything is unicodes by default in Python 3, and we need to rely on bytes, we have pycompat.py which contains hacks related to various functions of os module on Python.

    • We also have encoding.environ which helps us using a bytes version of os.environ on both Python 2 and 3.
    • There are currently two tests which are based on Python 3 compatibility and few checks in our linter test-check-code.t to make sure new patches include things from pycompat.py.

      1. test-check-py3-compat.t : This test was used initially to fix a lot of things, not very much helpful now.

      2. test-check-py3-commands.t: This test which things actually works on Python 3. You can see in the test that hg version runs on vanilla hg.

Python3 (last edited 2023-02-19 16:08:38 by AntonShestakov)