[PATCH 1 of 4] revlog: use absolute_import

Gregory Szorc gregory.szorc at gmail.com
Sat Jul 18 15:25:28 CDT 2015


On Sat, Jul 18, 2015 at 1:13 PM, Gregory Szorc <gregory.szorc at gmail.com>
wrote:

> On Sat, Jul 18, 2015 at 1:07 PM, Gregory Szorc <gregory.szorc at gmail.com>
> wrote:
>
>> On Thu, Jul 16, 2015 at 10:28 AM, Matt Mackall <mpm at selenic.com> wrote:
>>
>>> On Tue, 2015-07-14 at 13:51 -0700, Gregory Szorc wrote:
>>> > # HG changeset patch
>>> > # User Gregory Szorc <gregory.szorc at gmail.com>
>>>
>>> > # Date 1436894831 25200
>>> > #      Tue Jul 14 10:27:11 2015 -0700
>>> > # Node ID 5154b8421ebd670d6155659c5811f193f5fe1555
>>> > # Parent  35fa7c77c754aa4d156c42abfdb61ca178468872
>>> > revlog: use absolute_import
>>> >
>>> > This is needed for Python 3 compatibility. We have static analysis
>>> > checks in place to ensure files using absolute_import conform to the
>>> > style adopted by this patch.
>>>
>>> More weird test failures on 2.6:
>>>
>> ........
>>> --- /home/mpm/hg-test-/tests/test-help.t
>>> +++ /home/mpm/hg-test-/tests/test-help.t.err
>>> @@ -1244,6 +1244,15 @@
>>>
>>>    $ cd "$TESTDIR"/../doc
>>>    $ python check-seclevel.py
>>> +  Traceback (most recent call last):
>>> +    File "check-seclevel.py", line 168, in <module>
>>> +      if checkhghelps():
>>> +    File "check-seclevel.py", line 99, in checkhghelps
>>> +      mod = extensions.load(None, name, None)
>>> +    File "../mercurial/extensions.py", line 86, in load
>>> +      ui.debug('could not import hgext.%s (%s): trying %s\n'
>>> +  AttributeError: 'NoneType' object has no attribute 'debug'
>>> +  [1]
>>>    $ cd $TESTTMP
>>>
>>>  #if serve
>>>
>>> ERROR: test-help.t output changed
>>> !......
>>> --- /home/mpm/hg-test-/tests/test-extension.t
>>> +++ /home/mpm/hg-test-/tests/test-extension.t.err
>>> @@ -949,12 +949,15 @@
>>>    $ if [ -z "$hgver" ]; then
>>>    >   echo "unable to fetch a mercurial version. Make sure __version__
>>> is correct";
>>>    > fi
>>> +  unable to fetch a mercurial version. Make sure __version__ is correct
>>>    $ rm -f throw.pyc throw.pyo
>>>    $ hg --config extensions.throw=throw.py throw 2>&1 | egrep '^\*\*'
>>> -  ** unknown exception encountered, please report by visiting
>>> -  ** http://mercurial.selenic.com/wiki/BugTracker
>>> -  ** Python * (glob)
>>> -  ** Mercurial Distributed SCM (*) (glob)
>>> +  ** Unknown exception encountered with possibly-broken third-party
>>> extension throw
>>> +  ** which supports versions unknown of Mercurial.
>>> +  ** Please disable throw and try your action again.
>>> +  ** If that fixes the bug please report it to http://example.com/bts
>>> +  ** Python 2.6.6 (r266:84292, Jan 22 2014, 09:42:36) [GCC 4.4.7
>>> 20120313 (Red Hat 4.4.7-4)]
>>> +  ** Mercurial Distributed SCM (version +0-)
>>>    ** Extensions loaded: throw
>>>
>>>  Patch version is ignored during compatibility check
>>>
>>>
>> I'm able to reproduce these on Linux with Python 2.6.9. However, the
>> problem goes away if `make local` is executed (both run-tests.py and
>> run-tests.py -l work with a local build in place). However, the failure
>> persists if the local install was built against Python 2.7. It certainly
>> appears like the local install is leaking into the test environment
>> somehow, at least for these tests.
>>
>
> doc/check-seclevels.py is doing weirdness with sys.path foo. The error
> message about ui not having a "debug" attribute is a red herring because
> demandimport is mucking about with things. This is the actual error:
>
> $ HGDEMANDIMPORT=disable ~/.pyenv/versions/2.6.9/bin/python
> check-seclevel.py
> Traceback (most recent call last):
>   File "check-seclevel.py", line 13, in <module>
>     from mercurial.commands import table
>   File "../mercurial/commands.py", line 13, in <module>
>     import hg, scmutil, util, revlog, copies, error, bookmarks
>   File "../mercurial/hg.py", line 13, in <module>
>     import localrepo, bundlerepo, unionrepo, httppeer, sshpeer,
> statichttprepo
>   File "../mercurial/localrepo.py", line 10, in <module>
>     import peer, changegroup, subrepo, pushkey, obsolete, repoview
>   File "../mercurial/subrepo.py", line 13, in <module>
>     import config, util, node, error, cmdutil, scmutil, match as matchmod
>   File "../mercurial/cmdutil.py", line 11, in <module>
>     import util, scmutil, templater, patch, error, templatekw, revlog,
> copies
>   File "../mercurial/revlog.py", line 29, in <module>
>     from . import (
> ImportError: cannot import name parsers
>
> This is probably a result of the 'sys.path.insert(0, "..")' line in
> check-seclevel.py. That will almost certainly throw off relative imports.
>

The rabbit hole says this is a problem with mercurial/pure being in
sys.path. Before "import parsers" would pick up the C extension from
mercurial/ (if available) and fall back to mercurial/pure/parsers.py if
there was no C extension. With absolute imports, we need to explicitly
qualify imports.

The obvious solution is to catch ImportError when native extensions can't
be imported:

try:
    from . import parsers
except ImportError:
    from .pure import parsers
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://selenic.com/pipermail/mercurial-devel/attachments/20150718/15c4c83a/attachment.html>


More information about the Mercurial-devel mailing list