pure module loading issues with stable tip

Martin Geisler martin at geisler.net
Fri Aug 24 10:01:10 CDT 2012


Adrian Buehlmann <adrian at cadifra.com> writes:

> On 2012-08-24 13:04, Martin Geisler wrote:
>> Steve Borho <steve at borho.org> writes:
>> 
>>> Hello,
>>>
>>> obsolete.py is importing the base85 module with a "from" statement:
>>> from mercurial import util, base85
>>>
>>> If one is using the pure Python extensions by adding mercurial/pure to
>>> sys.path, this import statement breaks.
>> 
>> As far as I know, this isn't how --pure works -- the files in
>> mercurial/pure are copied into mercurial/ and so sys.path is not
>> supposed to be modified.
>
> setup.py does it:
> http://selenic.com/repo/hg/file/a0cf8f4cd38b/setup.py#l159
>
> Steve's patch looks good to me.

Okay, I see now -- I knew that setup.py used the pure code to bootstrap
Mercurial, but I had not thought about how it would change things if a C
extension is imported with 'from mercurial import X'.

This suggests that we should use relative imports everywhere: instead of

  from mercurial import X

we use

  import X

when the importing module is already in mercurial. Older code already
does this, but I think there is a tendency for new code to use the
(IMHO) more logical and explicit 'from mercurial import X' style.

-- 
Martin Geisler
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 835 bytes
Desc: not available
URL: <http://selenic.com/pipermail/mercurial-devel/attachments/20120824/42aee02f/attachment.pgp>


More information about the Mercurial-devel mailing list