From a80e5063068ef92d7aea0f486bf53fcb8f28d546 Mon Sep 17 00:00:00 2001 From: Maxime Chéramy Date: Sun, 24 May 2015 15:17:57 +0200 Subject: [PATCH] Fix import for PyInstaller. Also remove a Non-ASCII character for Python2... --- simso/core/Scheduler.py | 43 +++++++++++++++++++++++++++++++++---------- simso/schedulers/BF.py | 2 +- 2 files changed, 34 insertions(+), 11 deletions(-) diff --git a/simso/core/Scheduler.py b/simso/core/Scheduler.py index 55e6840..b474732 100644 --- a/simso/core/Scheduler.py +++ b/simso/core/Scheduler.py @@ -241,14 +241,37 @@ class Scheduler(object): def get_schedulers(): - package = importlib.import_module('simso.schedulers') - for importer, modname, ispkg in pkgutil.walk_packages( - path=package.__path__, - prefix=package.__name__ + '.', - onerror=lambda x: None): - m = importlib.import_module(modname) - for name in dir(m): - c = m.__getattribute__(name) - if inspect.isclass(c) and issubclass(c, Scheduler): - yield modname + modules = [] + + # Special case when using PyInstaller: + if getattr(sys, 'frozen', False): + import pyi_importers + importer = None + for obj in sys.meta_path: + if isinstance(obj, pyi_importers.FrozenImporter): + importer = obj break + + for name in importer.toc: + if name.startswith('simso.schedulers.'): + modules.append(name) + + # Normal case: + else: + package = importlib.import_module('simso.schedulers') + for importer, modname, ispkg in pkgutil.walk_packages( + path=package.__path__, + prefix=package.__name__ + '.', + onerror=lambda x: None): + modules.append(modname) + + for modname in sorted(modules): + try: + m = importlib.import_module(modname) + for name in dir(m): + c = m.__getattribute__(name) + if inspect.isclass(c) and issubclass(c, Scheduler): + yield modname + break + except (ImportError, SyntaxError): + print("Import error: ", modname) diff --git a/simso/schedulers/BF.py b/simso/schedulers/BF.py index 666dbcc..a252692 100644 --- a/simso/schedulers/BF.py +++ b/simso/schedulers/BF.py @@ -1,7 +1,7 @@ """ Implementation of the BF algorithm. -Authors: Maxime Chéramy and Stefan Junker +Authors: Maxime Cheramy and Stefan Junker """ from simso.core import Scheduler, Timer from fractions import Fraction -- libgit2 0.26.0