55from types import ModuleType
66import typing as t
77
8+ from piccolo .conf .apps import AppConfig , AppRegistry
89from piccolo .migrations .tables import Migration
910
1011
@@ -18,9 +19,8 @@ async def backwards() -> None:
1819 pass
1920
2021
21- class ConfigModule (ModuleType ):
22- NAME : str
23- DEPENDENCIES : t .List [str ]
22+ class PiccoloAppModule (ModuleType ):
23+ APP_CONFIG : AppConfig
2424
2525
2626class BaseMigrationManager :
@@ -35,52 +35,53 @@ def create_migration_table(self) -> bool:
3535 return False
3636
3737 def _deduplicate (
38- self , config_modules : t .List [ConfigModule ]
39- ) -> t .List [ConfigModule ]:
38+ self , config_modules : t .List [PiccoloAppModule ]
39+ ) -> t .List [PiccoloAppModule ]:
4040 """
4141 Remove all duplicates - just leaving the first instance.
4242 """
4343 # Deduplicate, but preserve order - which is why set() isn't used.
4444 return list (dict ([(c , None ) for c in config_modules ]).keys ())
4545
46- def import_config_modules (
47- self , migrations : t .List [str ]
48- ) -> t .List [ConfigModule ]:
46+ def _import_app_modules (
47+ self , config_module_paths : t .List [str ]
48+ ) -> t .List [PiccoloAppModule ]:
4949 """
50- Import all config modules, and all dependencies.
50+ Import all piccolo_app.py modules, and all dependencies.
5151 """
5252 config_modules = []
5353
54- for config_module_path in migrations :
54+ for config_module_path in config_module_paths :
5555 try :
5656 config_module = t .cast (
57- ConfigModule , importlib .import_module (config_module_path )
57+ PiccoloAppModule ,
58+ importlib .import_module (config_module_path ),
5859 )
5960 except ImportError :
6061 raise Exception (f"Unable to import { config_module_path } " )
61- DEPENDENCIES = getattr (config_module , "DEPENDENCIES" , [] )
62- dependency_config_modules = self .import_config_modules (
63- DEPENDENCIES
62+ app_config : AppConfig = getattr (config_module , "APP_CONFIG" )
63+ dependency_config_modules = self ._import_app_modules (
64+ app_config . migration_dependencies
6465 )
6566 config_modules .extend (dependency_config_modules + [config_module ])
6667
6768 return config_modules
6869
69- def get_config_modules (self ) -> t .List [ConfigModule ]:
70+ def get_app_modules (self ) -> t .List [PiccoloAppModule ]:
7071 try :
71- from piccolo_conf import MIGRATIONS
72+ from piccolo_conf import APP_REGISTRY
7273 except ImportError :
7374 raise Exception (
74- "Unable to import MIGRATIONS from piccolo_conf - make sure "
75+ "Unable to import APP_REGISTRY from piccolo_conf - make sure "
7576 "it's in your path."
7677 )
7778
78- config_modules = self .import_config_modules ( MIGRATIONS )
79+ app_modules = self ._import_app_modules ( APP_REGISTRY . apps )
7980
8081 # Now deduplicate any dependencies
81- config_modules = self ._deduplicate (config_modules )
82+ app_modules = self ._deduplicate (app_modules )
8283
83- return config_modules
84+ return app_modules
8485
8586 def get_migration_modules (
8687 self , folder_path : str
@@ -93,7 +94,7 @@ def get_migration_modules(
9394 sys .path .insert (0 , folder_path )
9495
9596 folder_contents = os .listdir (folder_path )
96- excluded = ("__init__.py" , "__pycache__" , "config.py" )
97+ excluded = ("__init__.py" , "__pycache__" )
9798 migration_names = [
9899 i .split (".py" )[0 ]
99100 for i in folder_contents
@@ -116,7 +117,7 @@ def get_migration_ids(
116117 ) -> t .List [str ]:
117118 return sorted (list (migration_module_dict .keys ()))
118119
119- def get_app_name (self , config_module : ConfigModule ) -> str :
120+ def get_app_name (self , config_module : PiccoloAppModule ) -> str :
120121 # TODO - default to package name instead.
121122 app_name = getattr (config_module , "NAME" , "" ).strip ()
122123 return app_name
0 commit comments