Skip to content

Commit 1f1c5f2

Browse files
committed
Fix and refactor CLI code
1 parent d68be59 commit 1f1c5f2

File tree

2 files changed

+23
-20
lines changed

2 files changed

+23
-20
lines changed

Tekst-API/tekst/__main__.py

Lines changed: 21 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -25,41 +25,40 @@
2525
"""
2626

2727

28-
async def _init_odm() -> None:
29-
from tekst import db
30-
31-
await db.init_odm()
32-
33-
3428
async def _create_indices() -> None:
35-
await _init_odm()
36-
from tekst import search
29+
from tekst import db, search
3730

31+
await db.init_odm()
3832
await search.create_indices_task()
3933
await search.close()
34+
await db.close()
4035

4136

4237
async def _refresh_precomputed_cache(force: bool) -> None:
43-
await _init_odm()
44-
from tekst import resources
38+
from tekst import db, resources
4539

40+
await db.init_odm()
4641
await resources.call_resource_precompute_hooks(force=force)
42+
await db.close()
4743

4844

4945
async def _cleanup() -> None:
50-
await _init_odm()
51-
from tekst import platform
46+
from tekst import db, platform
5247

48+
await db.init_odm()
5349
await platform.cleanup_task()
50+
await db.close()
5451

5552

5653
async def _maintenance() -> None:
57-
await _init_odm()
58-
from tekst import platform, resources, search
54+
from tekst import db, platform, resources, search
5955

56+
await db.init_odm()
6057
await search.create_indices_task()
6158
await resources.call_resource_precompute_hooks()
6259
await platform.cleanup_task()
60+
await search.close()
61+
await db.close()
6362

6463

6564
async def _export(
@@ -77,6 +76,12 @@ async def _export(
7776
click.echo(f"Output directory {output_dir_path} is not a directory", err=True)
7877
exit(1)
7978

79+
# prepare system
80+
from tekst import db, resources
81+
from tekst.routers import resources as resources_router
82+
83+
await db.init_odm()
84+
8085
# delete all existing files in output directory
8186
if delete:
8287
if not quiet:
@@ -85,11 +90,6 @@ async def _export(
8590
if child.is_file():
8691
child.unlink()
8792

88-
# prepare system
89-
await _init_odm()
90-
from tekst import resources
91-
from tekst.routers import resources as resources_router
92-
9393
# call precompute hooks
9494
await resources.call_resource_precompute_hooks()
9595

@@ -141,6 +141,8 @@ async def _export(
141141
if not quiet:
142142
click.echo(f"Exported resource {res_id_str} as {str(target_path)}.")
143143

144+
await db.close()
145+
144146

145147
@click.command()
146148
def bootstrap():

Tekst-API/tekst/auth.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import contextlib
22
import re
33

4+
from collections.abc import Callable
45
from typing import Annotated, Any
56

67
import fastapi_users.models as fapi_users_models
@@ -388,7 +389,7 @@ def setup_auth_routes(app: FastAPI) -> list[APIRouter]:
388389
)
389390

390391

391-
def _current_user(**kwargs) -> callable:
392+
def _current_user(**kwargs) -> Callable:
392393
"""Returns auth dependencies for API routes (optional auth in dev mode)"""
393394
return _fastapi_users.current_user(
394395
get_enabled_backends=_get_enabled_backends,

0 commit comments

Comments
 (0)