Add uvicorn server; make in-memory DB default

This commit is contained in:
Daniil Fajnberg 2022-06-29 13:04:36 +02:00
parent 27696ad57c
commit 8ec4e8885a
5 changed files with 37 additions and 2 deletions

View File

@ -1,4 +1,4 @@
-r common.txt
-r srv.txt
coverage
sqlalchemy-stubs
aiosqlite

2
requirements/srv.txt Normal file
View File

@ -0,0 +1,2 @@
-r common.txt
Uvicorn[standard]

View File

@ -29,7 +29,10 @@ install_requires =
Alembic
[options.extras_require]
srv =
Uvicorn[standard]
dev =
Uvicorn[standard]
coverage
sqlalchemy-stubs
aiosqlite

30
src/compub/__main__.py Normal file
View File

@ -0,0 +1,30 @@
from argparse import ArgumentParser, SUPPRESS
from pathlib import Path
from typing import Any, Sequence
import uvicorn
from .settings import PROGRAM_NAME, CONFIG_FILE_PATH_PARAM, DEFAULT_CONFIG_FILE_PATHS, init, settings
def parse_cli(args: Sequence[str] = None) -> dict[str, Any]:
parser = ArgumentParser(PROGRAM_NAME)
parser.add_argument(
'-c', f'--{CONFIG_FILE_PATH_PARAM}',
type=Path,
metavar='PATH',
default=SUPPRESS,
help=f"Paths to config file that will take precedence over all others; "
f"the following {len(DEFAULT_CONFIG_FILE_PATHS)} paths are always checked first (in that order):"
f" {','.join(str(p) for p in DEFAULT_CONFIG_FILE_PATHS)}"
)
return vars(parser.parse_args(args))
def main():
init(**parse_cli())
uvicorn.run(f'{PROGRAM_NAME}.routes:app', **settings.server.dict())
if __name__ == '__main__':
main()

View File

@ -81,7 +81,7 @@ class ServerSettings(BaseModel):
class Settings(AbstractBaseSettings):
db_uri: DBUri | None = None
db_uri: DBUri = 'sqlite+aiosqlite:///:memory:'
server: ServerSettings = ServerSettings()
log_config: dict | Path | None = None