Skip to content

Commit

Permalink
Merge pull request #1626 from mhsmith/android-paths
Browse files Browse the repository at this point in the history
Android: make Paths cache __main__ module location during startup
  • Loading branch information
freakboy3742 authored Oct 19, 2022
2 parents 975b2a1 + 7d9d846 commit d3bfed9
Showing 1 changed file with 5 additions and 10 deletions.
15 changes: 5 additions & 10 deletions src/android/toga_android/paths.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down

0 comments on commit d3bfed9

Please sign in to comment.