Skip to content

Commit 7ac05f4

Browse files
committed
removing remaining direct piccolo_conf imports in favour of Finder
1 parent 8707c43 commit 7ac05f4

File tree

3 files changed

+8
-26
lines changed

3 files changed

+8
-26
lines changed

piccolo/apps/migrations/commands/new.py

Lines changed: 4 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111

1212
from .base import BaseMigrationManager
1313
from piccolo import __VERSION__
14-
from piccolo.conf.apps import AppConfig, AppRegistry
14+
from piccolo.conf.apps import AppConfig, Finder
1515
from piccolo.apps.migrations.auto import (
1616
AlterStatements,
1717
SchemaSnapshot,
@@ -149,26 +149,12 @@ def new(app_name: str, auto: bool = False):
149149
"""
150150
print("Creating new migration ...")
151151

152-
try:
153-
import piccolo_conf
154-
except ImportError:
155-
print("Can't find piccolo_conf")
156-
sys.exit(1)
157-
158-
if auto and isinstance(getattr(piccolo_conf, "DB"), SQLiteEngine):
152+
engine = Finder().get_engine()
153+
if auto and isinstance(engine, SQLiteEngine):
159154
print("Auto migrations aren't currently supported by SQLite.")
160155
sys.exit(1)
161156

162-
try:
163-
app_registry: AppRegistry = piccolo_conf.APP_REGISTRY
164-
except AttributeError:
165-
print("APP_REGISTRY isn't defined in piccolo_conf")
166-
sys.exit(1)
167-
168-
app_config = app_registry.get_app_config(app_name)
169-
170-
if not app_config:
171-
raise ValueError(f"Unrecognised app_name: {app_name}")
157+
app_config = Finder().get_app_config(app_name=app_name)
172158

173159
_create_migrations_folder(app_config.migrations_folder_path)
174160
_create_new_migration(app_config=app_config, auto=auto)

piccolo/apps/shell/commands/run.py

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -28,13 +28,7 @@ def run():
2828
Runs an iPython shell, and automatically imports all of the Table classes
2929
from your project.
3030
"""
31-
try:
32-
import piccolo_conf
33-
except ImportError:
34-
print("Can't find piccolo_conf")
35-
sys.exit(1)
36-
37-
app_registry: AppRegistry = piccolo_conf.APP_REGISTRY
31+
app_registry: AppRegistry = Finder().get_app_registry()
3832

3933
tables = {}
4034
spacer = "-------"

piccolo/conf/apps.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -295,7 +295,9 @@ def get_app_registry(self) -> AppRegistry:
295295
app_registry = getattr(piccolo_conf_module, "APP_REGISTRY")
296296
return app_registry
297297

298-
def get_engine(self, module_name: t.Optional[str]) -> t.Optional[Engine]:
298+
def get_engine(
299+
self, module_name: t.Optional[str] = None
300+
) -> t.Optional[Engine]:
299301
piccolo_conf = self.get_piccolo_conf_module(module_name=module_name)
300302
engine: t.Optional[Engine] = None
301303
engine = getattr(piccolo_conf, ENGINE_VAR, None)

0 commit comments

Comments
 (0)