Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix PyInstaller issues #927

Merged
merged 1 commit into from
Mar 19, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 17 additions & 5 deletions faker/utils/loading.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,15 @@
def get_path(module):
if getattr(sys, 'frozen', False):
# frozen
base_dir = os.path.dirname(sys.executable)
lib_dir = os.path.join(base_dir, "lib")

if getattr(sys, '_MEIPASS', False):
# PyInstaller
lib_dir = getattr(sys, '_MEIPASS')
else:
# others
base_dir = os.path.dirname(sys.executable)
lib_dir = os.path.join(base_dir, "lib")

module_to_rel_path = os.path.join(*module.__package__.split("."))
path = os.path.join(lib_dir, module_to_rel_path)
else:
Expand All @@ -19,9 +26,14 @@ def get_path(module):

def list_module(module):
path = get_path(module)
modules = [name for _, name,
is_pkg in pkgutil.iter_modules([path]) if is_pkg]
return modules

if getattr(sys, '_MEIPASS', False):
# PyInstaller
return [name for name in os.listdir(path)
if os.path.isdir(os.path.join(path, name)) and
"__init__.py" in os.listdir(os.path.join(path, name))]
else:
return [name for _, name, is_pkg in pkgutil.iter_modules([path]) if is_pkg]


def find_available_locales(providers):
Expand Down