[launcher] load hgviewlib manually if standalone (closes #117624)

If use from source (setup.py found), load corresponding hgviewlib manually shadowing any system wide initialation.

This partially revert changes made in 32d191e8504d.

This changeset has been initiated by Arne Babenhauserheide <arne.babenhauserheide@fzk.de>

authorAlain Leufroy <alain@leufroy.fr>
changesetcf93defad8a8
branchstable
phasepublic
hiddenno
parent revision#30fdc10d8ebf qt: set window titles for file views
child revision#ee24a6abb01f [tui] fix source area stroke, #c006a7b9b6af [qt4] fix non displayed working directory on refreshing (closes #137714), #60cfa33f2548 [setup] use ``gmake`` instead of ``make`` on freebsd, #a802dac29c7e [qt] full support for unicode with utf-8 encoding (closes #142378), #afc2e9f1a776 [qt] full support for unicode with utf-8 encoding (closes #142378), #db743daa5937 [qt] fix unicode caracters in scintilla (closes #142378), #da173af8b1f5 [qt] fix unicode caracters in scintilla (closes #142378), #618c645aff6d merge stable into default
files modified by this revision
bin/hgview
hgext/hgview.py
# HG changeset patch
# User Alain Leufroy <alain@leufroy.fr>
# Date 1366032567 -7200
# Mon Apr 15 15:29:27 2013 +0200
# Branch stable
# Node ID cf93defad8a826e80ae683c84368cc3869731552
# Parent 30fdc10d8ebfcd0638fcab51813f6f06afaa5e7c
[launcher] load hgviewlib manually if standalone (closes #117624)

If use from source (``setup.py`` found), load corresponding ``hgviewlib`` manually
shadowing any system wide initialation.

This partially revert changes made in 32d191e8504d.

This changeset has been initiated by Arne Babenhauserheide <arne.babenhauserheide@fzk.de>

diff --git a/bin/hgview b/bin/hgview
@@ -11,23 +11,28 @@
1 
2  This may be used as a standalone application or as a hg extension. See
3  README file included.
4  """
5 
6 -import sys, os
7 -import os.path as pos
8 +import sys
9 +from os import readlink, lstat
10 +from os.path import join, dirname, abspath, pardir, exists
11 +from imp import load_package
12 +import stat
13 +
14 
15 -try:
16 -    import hgviewlib
17 -except ImportError:
18 -    import stat
19 -    execpath = pos.abspath(__file__)
20 -    # resolve symbolic links
21 -    statinfo = os.lstat(execpath)
22 -    if stat.S_ISLNK(statinfo.st_mode):
23 -        execpath = pos.abspath(pos.join(pos.dirname(execpath),
24 -                                        os.readlink(execpath)))
25 -    sys.path.append(pos.abspath(pos.join(pos.dirname(execpath), "..")))
26 +execpath = abspath(__file__)
27 +#   resolve symbolic links
28 +statinfo = lstat(execpath)
29 +if stat.S_ISLNK(statinfo.st_mode):
30 +    execpath = join(dirname(execpath), readlink(execpath))
31 +    execpath = abspath(execpath)
32 +# if standalone, import manually
33 +setuppath = join(dirname(dirname(execpath)), 'setup.py')
34 +if exists(setuppath): # standalone if setup.py found in src dir
35 +    hgviewlibpath = join(dirname(dirname(execpath)), 'hgviewlib')
36 +    hgviewlibpath = abspath(hgviewlibpath)
37 +    load_package('hgviewlib', hgviewlibpath)
38 
39  from hgviewlib.application import main
40 
41  main()
diff --git a/hgext/hgview.py b/hgext/hgview.py
@@ -14,12 +14,28 @@
42  testedwith = '2.4'
43 
44  buglink = 'https://www.logilab.org/project/hgview'
45 
46  import os
47 +import os.path as osp
48 +import stat
49 +import imp
50  from optparse import Values
51 -from mercurial import error
52 +from mercurial import error, demandimport
53 +
54 +execpath = osp.abspath(__file__)
55 +#   resolve symbolic links
56 +statinfo = os.lstat(execpath)
57 +if stat.S_ISLNK(statinfo.st_mode):
58 +    execpath = join(osp.dirname(execpath), os.readlink(execpath))
59 +    execpath = osp.abspath(execpath)
60 +# if standalone, import manually
61 +setuppath = osp.join(osp.dirname(osp.dirname(execpath)), 'setup.py')
62 +if osp.exists(setuppath): # standalone if setup.py found in src dir
63 +    hgviewlibpath = osp.join(osp.dirname(osp.dirname(execpath)), 'hgviewlib')
64 +    hgviewlibpath = osp.abspath(hgviewlibpath)
65 +    imp.load_package('hgviewlib', hgviewlibpath)
66 
67  # every command must take a ui and and repo as arguments.
68  # opts is a dict where you can find other command line flags
69  #
70  # Other parameters are taken in order from items on the command line that
@@ -64,13 +80,16 @@
71          """process errors"""
72          raise(error.Abort(text))
73      options = Values(opts)
74      start(repo, options, pats, fnerror)
75 
76 -import hgviewlib.hgviewhelp as hghelp
77 +import hgviewlib
78 
79 -start_hgview.__doc__ = hghelp.long_help_msg
80 +# note: ``import hgviewlib.hgviewhelp`` is incompatible with standalone
81 +#       because of the lazy import
82 +from hgviewlib.hgviewhelp import long_help_msg
83 +start_hgview.__doc__ = long_help_msg
84 
85  cmdtable = {
86      "^hgview|hgv|qv": (start_hgview,
87                         [('n', 'navigate', False, '(with filename) start in navigation mode'),
88                          ('r', 'rev', '', 'start in manifest navigation mode at rev R'),