# HG changeset patch
# User Antonio Muci <
a....@inwind.it>
# Date 1737850614 -3600
# Sun Jan 26 01:16:54 2025 +0100
# Branch stable
# Node ID 326e8dde97a9440bd82e4e40a40671df04a893b9
# Parent a1332fdbe48329928867db8dab6dab4e63431f2f
thg: centralize the computation of the directory containing the thg main script
The invocation of os.path.dirname(os.path.realpath(__file__)) was made in two
places. We can centralize it to a single place on top of the file. In the
process, the variable can be renamed to thg_base_path.
No functional changes.
diff --git a/thg b/thg
--- a/thg
+++ b/thg
@@ -13,11 +13,12 @@ from __future__ import annotations
import os
import sys
+thg_base_path = os.path.dirname(os.path.realpath(__file__))
+
if 'THG_OSX_APP' in os.environ:
# sys.path as created by py2app doesn't work quite right with demandimport
# Add the explicit path where PyQt4 and other libs are
- bundlepath = os.path.dirname(os.path.realpath(__file__))
- sys.path.insert(0, os.path.join(bundlepath, 'lib/python2.6/lib-dynload'))
+ sys.path.insert(0, os.path.join(thg_base_path, 'lib/python2.6/lib-dynload'))
if hasattr(sys, "frozen"):
if sys.frozen == 'windows_exe':
@@ -104,10 +105,9 @@ if hasattr(sys, "frozen"):
'system32', 'cmd.exe')
os.environ['COMSPEC'] = comspec
else:
- thgpath = os.path.dirname(os.path.realpath(__file__))
- testpath = os.path.join(thgpath, 'tortoisehg')
- if os.path.isdir(testpath) and thgpath not in sys.path:
- sys.path.insert(0, thgpath)
+ testpath = os.path.join(thg_base_path, 'tortoisehg')
+ if os.path.isdir(testpath) and thg_base_path not in sys.path:
+ sys.path.insert(0, thg_base_path)
# compile .ui and .qrc for in-place use
fpath = os.path.realpath(__file__)