From 5c0f123aa0d62fe050ee3edfa67d0d300c9a20d8 Mon Sep 17 00:00:00 2001 From: Kai Willadsen Date: Mon, 20 Jan 2025 07:11:22 +1000 Subject: [PATCH] Move macOS bundle setup logic to conf.py --- bin/meld | 20 ++------------------ meld/conf.py.in | 12 ++++++++++++ 2 files changed, 14 insertions(+), 18 deletions(-) diff --git a/bin/meld b/bin/meld index 0319e6c4..588e3c07 100755 --- a/bin/meld +++ b/bin/meld @@ -105,6 +105,8 @@ if uninstalled: meld.conf.uninstalled() elif frozen: meld.conf.frozen() +elif "Contents/MacOS" in sys.executable: + meld.conf.setup_macos_application_bundle() # TODO: Possibly move to elib.intl import gettext # noqa: E402, I100 @@ -410,23 +412,6 @@ def setup_glib_logging(): pass -def setup_macos_application_bundle(): - # When running from inside an application bundle, adjust paths relative - # to the location of the main binary. - if "Contents/MacOS" in sys.executable: - meld.conf.DATADIR = os.path.abspath( - os.path.join( - os.path.dirname(os.path.realpath(sys.executable)), - "../Resources/share/meld" - ) - ) - meld.conf.LOCALEDIR = os.path.abspath( - os.path.join( - os.path.dirname(meld.conf.DATADIR), "locale" - ) - ) - - def environment_hacks(): # MSYSTEM is set by git, and confuses our # msys-packaged version's library search path - @@ -466,7 +451,6 @@ def run_application(): def main(): - setup_macos_application_bundle() environment_hacks() setup_logging() disable_stdout_buffering() diff --git a/meld/conf.py.in b/meld/conf.py.in index 0e09043e..014a7f5c 100644 --- a/meld/conf.py.in +++ b/meld/conf.py.in @@ -62,3 +62,15 @@ def uninstalled(): resource_path = melddir / "meld" / "resources" os.environ['G_RESOURCE_OVERLAYS'] = f'{RESOURCE_BASE}={resource_path}' + + +def setup_macos_application_bundle(): + global DATADIR, LOCALEDIR, DATADIR_IS_UNINSTALLED + + # When running from inside an application bundle, adjust paths relative + # to the location of the main binary. + base_dir = Path(sys.executable).resolve().parent.parent + share_dir = base_dir / "Resources" / "share" + DATADIR = share_dir / "meld" + LOCALEDIR = share_dir / "locale" + DATADIR_IS_UNINSTALLED = True