Browse Source

expose additional top-level API for easier packaging

pull/473/head
Kiehl 5 years ago
committed by Chris
parent
commit
fd962aa259
2 changed files with 21 additions and 1 deletions
  1. 2
      gooey/__init__.py
  2. 20
      gooey/gui/util/freeze.py

2
gooey/__init__.py

@ -1,5 +1,5 @@
import os
from gooey.python_bindings.gooey_decorator import Gooey
from gooey.python_bindings.gooey_parser import GooeyParser
from gooey.gui.util.freeze import localResourcePath as local_resource_path
__version__ = '1.0.3'

20
gooey/gui/util/freeze.py

@ -1,3 +1,9 @@
'''
Utils for retrieving resources when when in a frozen state.
MEIPASS explanation:
https://pythonhosted.org/PyInstaller/#run-time-operation
'''
import os
import sys
@ -26,3 +32,17 @@ def getResourcePath(*args):
resource_dir = os.path.normpath(
os.path.join(os.path.dirname(__file__), '..', '..'))
return os.path.join(resource_dir, *args)
def localResourcePath(path):
"""
A packaging aware util for getting the path to the local working directory.
When non-packaged, this is os.getcwd(), when packaged, it will be the local
(dynamic) directory where PyInstaller decompresses content.
"""
if is_frozen():
basedir = getattr(sys, '_MEIPASS', None)
return os.path.join(basedir or sys.executable, path)
else:
return os.path.join(os.getcwd(), path)
Loading…
Cancel
Save