piccolo-orm/piccolo

Allow user-defined alternatives to piccolo_app and piccolo_conf files

aabmets opened this issue · 1 comments

I don't like how piccolo requires its files to have piccolo_app.py and piccolo_conf.py names.
I want to have a single file piccolo.py with the following contents:

from piccolo.conf.apps import table_finder, AppConfig
from piccolo.engine.postgres import PostgresEngine
from piccolo.conf.apps import AppRegistry
from pathlib import Path

PICCOLO_DIR = Path(__file__).parent.resolve()
MIGRATIONS_DIR = (PICCOLO_DIR / "migrations").as_posix()

APP_CONFIG = AppConfig(...)
APP_REGISTRY = AppRegistry(...)
DB = PostgresEngine(...)

Currently, this works for an ASGI app, but piccolo CLI is broken, because the required
file names are hardcoded into the piccolo CLI source code.

Instead, the user should be able to provide an --option to piccolo CLI with a path to the
file which contains the class instances that piccolo requires.

Also, the APP_CONFIG, APP_REGISTRY and DB variable names should also be parametrized,
because forcing heavy opinions on developers is impolite.

It's possible to change where Piccolo looks for the piccolo_conf.py file using an environment variable:

https://piccolo-orm.readthedocs.io/en/latest/piccolo/engines/index.html#piccolo-conf-environment-variable

Maybe we could also let the user specify it via the piccolo CLI command.