[PATCH 1 of 2] thg: centralize the computation of the directory containing the thg main script

4 views
Skip to first unread message

Antonio Muci

unread,
Jan 31, 2025, 6:08:43 PMJan 31
to thg...@googlegroups.com, a....@inwind.it
# 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__)

Yuya Nishihara

unread,
Jan 31, 2025, 9:50:06 PMJan 31
to 'Antonio Muci' via TortoiseHg Developers, a....@inwind.it
On Sat, 01 Feb 2025 00:08:39 +0100, 'Antonio Muci' via TortoiseHg Developers wrote:
> # 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

Queued, thanks.
Reply all
Reply to author
Forward
0 new messages