Skip to content

Commit a4fc820

Browse files
committed
Fix paths when using Nuitka. Closes #357.
1 parent 622f098 commit a4fc820

1 file changed

Lines changed: 7 additions & 6 deletions

File tree

emailproxy.py

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
__author__ = 'Simon Robinson'
77
__copyright__ = 'Copyright (c) 2024 Simon Robinson'
88
__license__ = 'Apache 2.0'
9-
__package_version__ = '2025.4.27' # for pyproject.toml usage only - needs to be ast.literal_eval() compatible
9+
__package_version__ = '2025.5.30' # for pyproject.toml usage only - needs to be ast.literal_eval() compatible
1010
__version__ = '-'.join('%02d' % int(part) for part in __package_version__.split('.')) # ISO 8601 (YYYY-MM-DD)
1111

1212
import abc
@@ -172,7 +172,8 @@ class NSObject:
172172
CENSOR_CREDENTIALS = True
173173
CENSOR_MESSAGE = b'[[ Credentials removed from proxy log ]]' # replaces actual credentials; must be a byte-type string
174174

175-
script_path = sys.executable if getattr(sys, 'frozen', False) else os.path.realpath(__file__) # for pyinstaller etc
175+
FROZEN_PACKAGE = getattr(sys, 'frozen', False) or '__compiled__' in globals() # for pyinstaller/nuitka etc
176+
script_path = sys.executable if FROZEN_PACKAGE else os.path.realpath(__file__)
176177
if sys.platform == 'darwin' and '.app/Contents/MacOS/' in script_path: # pyinstaller .app binary is within the bundle
177178
if float('.'.join(platform.mac_ver()[0].split('.')[:2])) >= 10.12: # need a known path (due to App Translocation)
178179
script_path = pathlib.Path('~/.%s/%s' % (APP_SHORT_NAME, APP_SHORT_NAME)).expanduser()
@@ -275,7 +276,7 @@ def initialise(log_file=None):
275276
if log_file or sys.platform == 'win32':
276277
handler = logging.handlers.RotatingFileHandler(
277278
log_file or os.path.join(os.getcwd() if __package__ is not None else
278-
os.path.dirname(sys.executable if getattr(sys, 'frozen', False) else
279+
os.path.dirname(sys.executable if FROZEN_PACKAGE else
279280
os.path.realpath(__file__)), '%s.log' % APP_SHORT_NAME),
280281
maxBytes=LOG_FILE_MAX_SIZE, backupCount=LOG_FILE_MAX_BACKUPS)
281282
handler.setFormatter(logging.Formatter('%(asctime)s: %(message)s'))
@@ -2800,8 +2801,8 @@ def init_platforms(self):
28002801
# proxy's handling of this signal may change in future if other actions are seen as more suitable
28012802
signal.signal(signal.SIGUSR1, lambda _signum, _fr: self.toggle_debug(Log.get_level() == logging.INFO))
28022803

2803-
# certificates are not imported automatically when packaged using pyinstaller - we need certifi
2804-
if getattr(sys, 'frozen', False):
2804+
# certificates are not imported automatically when packaged using pyinstaller/nuitka - we need certifi
2805+
if FROZEN_PACKAGE:
28052806
if ssl.get_default_verify_paths().cafile is None and 'SSL_CERT_FILE' not in os.environ:
28062807
try:
28072808
import certifi
@@ -3210,7 +3211,7 @@ def get_script_start_command(self, quote_args=True):
32103211
python_command = 'pythonw.exe'.join(python_command.rsplit('python.exe', 1))
32113212

32123213
script_command = [python_command]
3213-
if not getattr(sys, 'frozen', False): # no need for the script path if using pyinstaller
3214+
if not FROZEN_PACKAGE: # no need for the script path if using pyinstaller/nuitka
32143215
if __package__ is not None:
32153216
script_command.extend(['-m', APP_SHORT_NAME])
32163217
else:

0 commit comments

Comments
 (0)