From 7d9d84662dc75b4458c8da61df50a3fed568d9c9 Mon Sep 17 00:00:00 2001 From: Malcolm Smith Date: Wed, 19 Oct 2022 13:34:15 +0100 Subject: [PATCH] Android: make Paths cache __main__ module location during startup --- src/android/toga_android/paths.py | 15 +++++---------- 1 file changed, 5 insertions(+), 10 deletions(-) diff --git a/src/android/toga_android/paths.py b/src/android/toga_android/paths.py index 37ad58d97b..653f0074bc 100644 --- a/src/android/toga_android/paths.py +++ b/src/android/toga_android/paths.py @@ -13,18 +13,13 @@ class Paths: def __context(self): return App.app._impl.native.getApplicationContext() + def __init__(self): + # On Android, __main__ only exists during app startup, so cache its location now. + self._app = Path(sys.modules["__main__"].__file__).parent + @property def app(self): - try: - return Path(sys.modules["__main__"].__file__).parent - except KeyError: - # If we're running in test conditions, - # there is no __main__ module. - return Path.cwd() - except AttributeError: - # If we're running at an interactive prompt, - # the __main__ module isn't file-based. - return Path.cwd() + return self._app @property def data(self):