Skip to content

Commit 8439331

Browse files
Merge pull request #6 from nbusseneau/pr/pyinstaller-macos-cwd
Kludge around MacOS current working directory when using PyInstaller executable
2 parents e970e11 + 0a79a58 commit 8439331

1 file changed

Lines changed: 15 additions & 0 deletions

File tree

modimporter.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
import argparse
44
import os
5+
import platform
6+
import sys
57
from collections import defaultdict
68
from collections import deque
79
from pathlib import Path
@@ -22,6 +24,19 @@
2224
print("SJSON python module not found! SJSON changes will be skipped!")
2325
print("SJSON module should be available in the same place as the importer\n")
2426

27+
28+
# if we are on MacOS and running PyInstaller executable, force working directory
29+
# to be the one containing the executable
30+
# this is a kludge around MacOS calling executables from the user home rather
31+
# than the current directory when double-clicked on from Finder
32+
# has to be done here due to the rest of the script mixing in `os.path` and
33+
# `pathlib` operations outside of the actual `__main__`
34+
if platform.system() == 'Darwin' and getattr(sys, 'frozen', False) and hasattr(sys, '_MEIPASS'):
35+
parent_dir = Path(sys.argv[0]).parent
36+
os.chdir(parent_dir)
37+
print(f"Running MacOS executable from Finder: forced working directory to {parent_dir}")
38+
39+
2540
## Global Settings
2641

2742
clean_only = False #uninstall option, ignores mod folder

0 commit comments

Comments
 (0)