comparison hgsubversion/layouts/standard.py @ 1101:4a92eb1484ba

layouts: fix crash when importing hgsubversion itself (issue #402) Mercurial extensions are a bit weird: they aren't normally in sys.path, so you can't assume that "import hgsubversion" works. Luckily, Mercurial sneaks a little treat into sys.modules so that "import hgext_hgsubversion" does work. In fact, to get things working *as a Mercurial extension*, all that's needed is that trivial change to two import lines, in layouts/detect.py and layouts/standard.py. Unfortunately, hgsubversion is also imported as a Python module, in its own test suite. In that context, there is no "hgext_" trick -- unless we do it in ourselves, which I've done in TestBase.setUp(). That would work fine ... except that test_util imports from hgsubversion, which ends up importing hgsubversion.layouts.{detect,standard}, which want the "hgext_" trick to work. But it hasn't been done yet when we're still importing; it doesn't happen until setUp() runs. So make those two imports happen late, in the functions that need them. Incidentally, this is only necessary to support Mercurial <= 2.7. Mercurial got a bit smarter in 2.8: http://selenic.com/repo/hg/rev/621a26eb3a99
author Greg Ward <greg@gerg.ca>
date Thu, 02 Jan 2014 21:53:39 -0500
parents 9a7e3dbd0f6e
children 0f16e11b2c2b
comparison
equal deleted inserted replaced
1100:91cf81a36236 1101:4a92eb1484ba
1 import os.path 1 import os.path
2 import pickle 2 import pickle
3 3
4 import base 4 import base
5 import hgsubversion.util as util
6 5
7 class StandardLayout(base.BaseLayout): 6 class StandardLayout(base.BaseLayout):
8 """The standard trunk, branches, tags layout""" 7 """The standard trunk, branches, tags layout"""
9 8
10 def __init__(self, ui): 9 def __init__(self, ui):
55 branchpath = ''.join((self._branch_dir, branch, self._infix)) 54 branchpath = ''.join((self._branch_dir, branch, self._infix))
56 55
57 return '%s/%s' % (subdir or '', branchpath) 56 return '%s/%s' % (subdir or '', branchpath)
58 57
59 def taglocations(self, meta_data_dir): 58 def taglocations(self, meta_data_dir):
59 # import late to avoid trouble when running the test suite
60 from hgext_hgsubversion import util
61
60 if self._tag_locations is None: 62 if self._tag_locations is None:
61 63
62 tag_locations_file = os.path.join(meta_data_dir, 'tag_locations') 64 tag_locations_file = os.path.join(meta_data_dir, 'tag_locations')
63 65
64 if os.path.exists(tag_locations_file): 66 if os.path.exists(tag_locations_file):