Mercurial on Py3k (GSoC 2009)

Antoine Pitrou solipsis at pitrou.net
Thu Apr 2 05:41:11 CDT 2009


Hello,

My 2 cents:

> Some design choices come to my mind:
> 
> a) Create some compatibility layer to make Hg work on Py3k (or Py2.x)?

This approach would only be workable for small scripts. For a full-blown
project such as Mercurial, it would probably make writing code very un-natural
and tedious.

(not to mention that 3.x mandates some synctatical constructs
("except Exception as e") that are not available before 2.6)

> c) Follow Python's PEP 3000 recommenden model for simultaneous support
> of Py2.x and Py3k?

Strangely enough, I recommend following the recommended model :-)

Note that Mercurial must first be runnable under Python 2.6 with the "-3" flag
without any warnings being spout. If Mercurial wants to remain 2.4-compatible
this might be a difficult task in itself...

> The main problem would be to correctly handle the repository binary
> data at a Byte level, keeping compatibility of the data files using
> either Python >= 3.0 or Python 2.x.

I don't think that would be the main problem. Handling binary data hasn't
changed much between 2.x and 3.x. The main difference being that you have
to use the bytes type throughout the code rather than the str type. A more
annoying problem, as Matt Mackall suggested, may be that py3k tries to convert a
lot of things as unicode strings - notably file names and environment variables.

If you want more information about porting to 3.x, a dedicated mailing-list
exists: http://mail.python.org/mailman/listinfo/python-porting

If more bytes-friendly (rather than unicode-) methods are needed on the
IO side, specific questions may be raised on the python-ideas mailing-list, or
directly in the bug tracker.

(also, now that Mercurial has been officially chosen as the future DVCS for
development of Python, people will probably be more open to any API suggestion
the Mercurial project may submit)

> 4. What intermediate milestones can be defined?
> 
> 1st, Choose between the design choices, and write the propper documentation.
> 2nd, Run the 2to3 tool on Hg source and check if the source is
> correctly converted (on a source-code syntax level)

An intermediate milestone between 1 and 2 would be to make sure that either
Mercurial, or a slightly modified branch of Mercurial, runs under Python 2.6
with the "-3" flag and without warnings.

At least, that's if you choose the recommended method for porting, which is
recommended :-)

Regards

Antoine.




More information about the Mercurial-devel mailing list