Differences between revisions 1 and 32 (spanning 31 versions)
Revision 1 as of 2014-02-03 21:26:12
Size: 948
Editor: AugieFackler
Comment:
Revision 32 as of 2019-02-26 03:18:39
Size: 4071
Editor: GregorySzorc
Comment: update test pass rate; add a couple of things to be investigated
Deletions are marked like this. Additions are marked like this.
Line 3: Line 3:
This is a status page for keeping track of what needs to be done to make progress on Mercurial on Python 3. Nobody is actively working on this - AugieFackler works on it sporadically, and would be happy to see patches on this topic flagged with Py3 on the mailing list. = Python 3 =
Line 5: Line 5:
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 6: Line 7:
The most significant problem at the moment is some lingering cyclic imports in the codebase: == What Works ==
Most of the basic and daily usage commands work with out of tree extensions being disabled. More than 98% of test suite works with Python 3. The lists of passing tests can be found at [[https://www.mercurial-scm.org/repo/hg-committed/file/tip/contrib/python3-whitelist|python3-whitelist]]
Line 8: Line 10:
==== cmdutil -> subrepo -> cmdutil ==== It is very likely that an alpha or beta Python 3 release will be there in first half of 2019.
Line 10: Line 12:
The easiest fix for this would be to move hgsubrepo to a new file, and then fix the registration mechanism to be dependency injected somehow. Out of tree hg-extensions still don't work. There would be several unicode issues.
Line 12: Line 14:
==== mercurial.repoview -> mercurial.revset -> mercurial.repoview ==== == Contributing ==
Line 14: Line 16:
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. Most of our efforts are to make sure have Python 2 compatibility intact while making Python 3 run.
Line 15: Line 18:
==== mercurial.fileset -> mercurial.merge -> mercurial.subrepo -> mercurial.match -> mercurial.fileset ====
If hgsubrepo moved out of subrepo, this would also be resolve.d
 * 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/295625f1296b/mercurial/__init__.py#l124|here]] and you can also use transformer on your .py files by adding them in the transformer.
Line 18: Line 26:
 * We deal with bytes internally, 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.
Line 19: Line 28:
==== mercurial.filemerge -> mercurial.match -> mercurial.fileset -> mercurial.merge -> mercurial.filemerge ====  * We also have `encoding.environ` which helps us using a bytes version of `os.environ` on both Python 2 and 3.

 * We are also adding `r''` at some places to make it a raw string.

 * Encoding issues are generally uncovered by our tests (as everything was byte string on Python 2.)

== How to contribute ==

 * Pick a failing tests, run `python3 ./run-tests.py <test-name>` and try to fix the exceptions raised.

Pure-python tests are sometimes easier to port, but often need to be ported to use unittest first instead of our legacy testing system. The first step in migrating such tests to Python 3 involves [[https://www.mercurial-scm.org/repo/hg-committed/rev/11d128a14ec0|porting to unittest]], followed by any necessary followups to fix issues on Python 3. A list of tests that probably still need this work done can be obtained by running `comm -23 <(hg files 'set:tests/test*py - grep(unittest)' | sed 's$tests/$$') contrib/python3-whitelist`.

The practice we follow now is run commands which are not yet fixed and try to fix the exceptions raised. So our current approach is exception based.

== Things need to be investigated ==

 * Windows encoding changes
 https://docs.python.org/3/whatsnew/3.6.html#pep-529-change-windows-filesystem-encoding-to-utf-8
 * Lazy importer performance overhead. Our custom importer on Python 2 always returns a stub module during ``import``. Python 3's does I/O to verify the module exists then returns a lazy module that is loaded when first accessed. In addition to behavior differences, the I/O may contribute sufficient performance overhead to constitute a problem.
 * A mechanism for extensions to advertise that they are Python 3 compatible. Nearly every extension will break in Python 3. We may want a mechanism that requires extensions to self-declare that they are Python 3 compatible - possibly via special syntax in their source code or the presence of a well-named variable. It might have to be at the source level because Python 3 would need to evaluate code in order to obtain the value of a module-level variable.

----
CategoryAudit

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

Most of the basic and daily usage commands work with out of tree extensions being disabled. More than 98% of test suite works with Python 3. The lists of passing tests can be found at python3-whitelist

It is very likely that an alpha or beta Python 3 release will be there in first half of 2019.

Out of tree hg-extensions still don't work. There would be several unicode issues.

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. Most of our efforts are to make sure have Python 2 compatibility intact while making Python 3 run.

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

  • We deal with bytes internally, 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.

  • We are also adding r'' at some places to make it a raw string.

  • Encoding issues are generally uncovered by our tests (as everything was byte string on Python 2.)

3. How to contribute

  • Pick a failing tests, run python3 ./run-tests.py <test-name> and try to fix the exceptions raised.

Pure-python tests are sometimes easier to port, but often need to be ported to use unittest first instead of our legacy testing system. The first step in migrating such tests to Python 3 involves porting to unittest, followed by any necessary followups to fix issues on Python 3. A list of tests that probably still need this work done can be obtained by running comm -23 <(hg files 'set:tests/test*py - grep(unittest)' | sed 's$tests/$$') contrib/python3-whitelist.

The practice we follow now is run commands which are not yet fixed and try to fix the exceptions raised. So our current approach is exception based.

4. Things need to be investigated

  • Windows encoding changes

    https://docs.python.org/3/whatsnew/3.6.html#pep-529-change-windows-filesystem-encoding-to-utf-8

  • Lazy importer performance overhead. Our custom importer on Python 2 always returns a stub module during import. Python 3's does I/O to verify the module exists then returns a lazy module that is loaded when first accessed. In addition to behavior differences, the I/O may contribute sufficient performance overhead to constitute a problem.

  • A mechanism for extensions to advertise that they are Python 3 compatible. Nearly every extension will break in Python 3. We may want a mechanism that requires extensions to self-declare that they are Python 3 compatible - possibly via special syntax in their source code or the presence of a well-named variable. It might have to be at the source level because Python 3 would need to evaluate code in order to obtain the value of a module-level variable.


CategoryAudit

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