Repository: klen/peewee_migrate

Issue:
peewee_migrate/router.py: module has no attribute '__path__'
File "/Users/anaconda3/lib/python3.6/site-packages/peewee_migrate/router.py", line 277, in _import_submodules
    if set(package.__path__) & passed:

AttributeError: module 'model' has no attribute '__path__'


Discussion:

Patch:
diff --git a/peewee_migrate/router.py b/peewee_migrate/router.py
index 77973a2..0abdac0 100644
--- a/peewee_migrate/router.py
+++ b/peewee_migrate/router.py
@@ -4,6 +4,8 @@ import sys
 from importlib import import_module
 
 import pkgutil
+from types import ModuleType
+
 import mock
 import peewee as pw
 from cached_property import cached_property
@@ -265,7 +267,11 @@ class ModuleRouter(BaseRouter):
 
 def load_models(module):
     """Load models from given module."""
-    modules = _import_submodules(module)
+    if isinstance(module, ModuleType):
+        # if itself is module already
+        modules = [module]
+    else:
+        modules = _import_submodules(module)
     return {m for module in modules for m in filter(
         _check_model, (getattr(module, name) for name in dir(module))
     )}


Test patch:
diff --git a/tests/test_router.py b/tests/test_router.py
index 960b9d5..e97a7b3 100644
--- a/tests/test_router.py
+++ b/tests/test_router.py
@@ -3,7 +3,7 @@ import os
 
 import mock
 import peewee as pw
-
+from tests.test_autodiscover.some_folder_one import one_models
 
 MIGRATIONS_DIR = os.path.join('tests', 'migrations')
 
@@ -61,6 +61,12 @@ def test_router():
 
     models = load_models('tests.test_autodiscover')
     assert models
+    from .test_autodiscover.some_folder_one import one_models
+    models = load_models(one_models)
+    assert models
+
+    models = load_models(one_models)
+    assert models
 
 
 def test_router_compile(tmpdir):