[launcher] load hgviewlib manually if standalone (closes #117624) stable
authorAlain Leufroy <alain@leufroy.fr>
Mon, 15 Apr 2013 15:29:27 +0200
branchstable
changeset 942 cf93defad8a8
parent 927 30fdc10d8ebf
child 943 618c645aff6d
child 944 a802dac29c7e
[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>
bin/hgview
hgext/hgview.py
--- a/bin/hgview	Sat Dec 08 21:40:35 2012 +0100
+++ b/bin/hgview	Mon Apr 15 15:29:27 2013 +0200
@@ -13,20 +13,25 @@
 README file included.
 """
 
-import sys, os
-import os.path as pos
+import sys
+from os import readlink, lstat
+from os.path import join, dirname, abspath, pardir, exists
+from imp import load_package
+import stat
+
 
-try:
-    import hgviewlib
-except ImportError:
-    import stat
-    execpath = pos.abspath(__file__)
-    # resolve symbolic links
-    statinfo = os.lstat(execpath)
-    if stat.S_ISLNK(statinfo.st_mode):
-        execpath = pos.abspath(pos.join(pos.dirname(execpath),
-                                        os.readlink(execpath)))
-    sys.path.append(pos.abspath(pos.join(pos.dirname(execpath), "..")))
+execpath = abspath(__file__)
+#   resolve symbolic links
+statinfo = lstat(execpath)
+if stat.S_ISLNK(statinfo.st_mode):
+    execpath = join(dirname(execpath), readlink(execpath))
+    execpath = abspath(execpath)
+# if standalone, import manually
+setuppath = join(dirname(dirname(execpath)), 'setup.py')
+if exists(setuppath): # standalone if setup.py found in src dir
+    hgviewlibpath = join(dirname(dirname(execpath)), 'hgviewlib')
+    hgviewlibpath = abspath(hgviewlibpath)
+    load_package('hgviewlib', hgviewlibpath)
 
 from hgviewlib.application import main
 
--- a/hgext/hgview.py	Sat Dec 08 21:40:35 2012 +0100
+++ b/hgext/hgview.py	Mon Apr 15 15:29:27 2013 +0200
@@ -16,8 +16,24 @@
 buglink = 'https://www.logilab.org/project/hgview'
 
 import os
+import os.path as osp
+import stat
+import imp
 from optparse import Values
-from mercurial import error
+from mercurial import error, demandimport
+
+execpath = osp.abspath(__file__)
+#   resolve symbolic links
+statinfo = os.lstat(execpath)
+if stat.S_ISLNK(statinfo.st_mode):
+    execpath = join(osp.dirname(execpath), os.readlink(execpath))
+    execpath = osp.abspath(execpath)
+# if standalone, import manually
+setuppath = osp.join(osp.dirname(osp.dirname(execpath)), 'setup.py')
+if osp.exists(setuppath): # standalone if setup.py found in src dir
+    hgviewlibpath = osp.join(osp.dirname(osp.dirname(execpath)), 'hgviewlib')
+    hgviewlibpath = osp.abspath(hgviewlibpath)
+    imp.load_package('hgviewlib', hgviewlibpath)
 
 # every command must take a ui and and repo as arguments.
 # opts is a dict where you can find other command line flags
@@ -66,9 +82,12 @@
     options = Values(opts)
     start(repo, options, pats, fnerror)
 
-import hgviewlib.hgviewhelp as hghelp
+import hgviewlib
 
-start_hgview.__doc__ = hghelp.long_help_msg
+# note: ``import hgviewlib.hgviewhelp`` is incompatible with standalone
+#       because of the lazy import
+from hgviewlib.hgviewhelp import long_help_msg
+start_hgview.__doc__ = long_help_msg
 
 cmdtable = {
     "^hgview|hgv|qv": (start_hgview,