Skip to content

Commit

Permalink
Merge pull request #533 from yagebu/fix-pyinstaller
Browse files Browse the repository at this point in the history
* Revert "Also check for `sys._MEIPASS` before assuming PyInstallerness (#526)" (0b34807)
* Revert "Merge pull request #505 from wodo/pi_support" (commit 653e6d4, reversing
changes made to 5f3b008)
  • Loading branch information
akx authored Jan 15, 2018
2 parents 1539c8a + 29da2d2 commit 7f4a956
Show file tree
Hide file tree
Showing 3 changed files with 2 additions and 24 deletions.
2 changes: 1 addition & 1 deletion babel/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ def get_global(key):
"""
global _global_data
if _global_data is None:
dirname = localedata.get_base_dir()
dirname = os.path.join(os.path.dirname(__file__))
filename = os.path.join(dirname, 'global.dat')
if not os.path.isfile(filename):
_raise_no_data_error()
Expand Down
12 changes: 1 addition & 11 deletions babel/localedata.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,23 +16,13 @@
import threading
from collections import MutableMapping
from itertools import chain
import sys

from babel._compat import pickle, string_types


def get_base_dir():
if getattr(sys, 'frozen', False) and getattr(sys, '_MEIPASS', None):
# 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(get_base_dir(), 'locale-data')
_dirname = os.path.join(os.path.dirname(__file__), 'locale-data')


def normalize_locale(name):
Expand Down
12 changes: 0 additions & 12 deletions tests/test_localedata.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
import unittest
import random
from operator import methodcaller
import sys

from babel import localedata, numbers

Expand Down Expand Up @@ -94,17 +93,6 @@ def test_mixedcased_locale():
methodcaller(random.choice(['lower', 'upper']))(c) for c in l])
assert localedata.exists(locale_id)


def test_pi_support_frozen(monkeypatch):
monkeypatch.setattr(sys, '_MEIPASS', 'testdir', raising=False)
monkeypatch.setattr(sys, 'frozen', True, raising=False)
assert localedata.get_base_dir() == 'testdir'


def test_pi_support_not_frozen():
assert not getattr(sys, 'frozen', False)
assert localedata.get_base_dir().endswith('babel')

def test_locale_argument_acceptance():
# Testing None input.
normalized_locale = localedata.normalize_locale(None)
Expand Down

0 comments on commit 7f4a956

Please sign in to comment.