summaryrefslogtreecommitdiff
path: root/babel
diff options
context:
space:
mode:
authorWolfgang Doll <wolfgang.doll@web.de>2017-06-23 12:03:23 +0200
committerWolfgang Doll <wolfgang.doll@web.de>2017-06-24 10:25:19 +0200
commitc3422e8103cb662015e84f5a5ffc29b4333aa062 (patch)
tree966dcec2bc58078e9d4ee1edea0cdca50f8d72d1 /babel
parent0c75f291ebf79558b9a6b118dcf4bbb3098bd144 (diff)
downloadbabel-c3422e8103cb662015e84f5a5ffc29b4333aa062.tar.gz
Introduce PyInstaller support. Fixes #500
Add a get_base_dir function that works in the context of PyInstaller, where the __file__ system variable is not available.
Diffstat (limited to 'babel')
-rw-r--r--babel/core.py2
-rw-r--r--babel/localedata.py12
2 files changed, 12 insertions, 2 deletions
diff --git a/babel/core.py b/babel/core.py
index 5140f49..df03b24 100644
--- a/babel/core.py
+++ b/babel/core.py
@@ -68,7 +68,7 @@ def get_global(key):
"""
global _global_data
if _global_data is None:
- dirname = os.path.join(os.path.dirname(__file__))
+ dirname = localedata.get_base_dir()
filename = os.path.join(dirname, 'global.dat')
if not os.path.isfile(filename):
_raise_no_data_error()
diff --git a/babel/localedata.py b/babel/localedata.py
index 9e272a2..4658221 100644
--- a/babel/localedata.py
+++ b/babel/localedata.py
@@ -16,13 +16,23 @@ import os
import threading
from collections import MutableMapping
from itertools import chain
+import sys
from babel._compat import pickle
+def get_base_dir():
+ if getattr(sys, 'frozen', False):
+ # we are running in a |PyInstaller| bundle
+ basedir = sys._MEIPASS
+ else:
+ # we are running in a normal Python environment
+ basedir = os.path.dirname(__file__)
+ return basedir
+
_cache = {}
_cache_lock = threading.RLock()
-_dirname = os.path.join(os.path.dirname(__file__), 'locale-data')
+_dirname = os.path.join(get_base_dir(), 'locale-data')
def normalize_locale(name):