Skip to content

Commit fd8e800

Browse files
committed
ref(conf): rename configs withot abbreviations
1 parent 84c2f9c commit fd8e800

File tree

8 files changed

+118
-112
lines changed

8 files changed

+118
-112
lines changed

src/tgdb/infrastructure/pyyaml/conf.py

Lines changed: 0 additions & 74 deletions
This file was deleted.
Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
from pathlib import Path
2+
3+
import yaml
4+
from pydantic import BaseModel, Field
5+
6+
7+
class UvicornConfig(BaseModel):
8+
host: str
9+
port: int
10+
11+
12+
class APIConfig(BaseModel):
13+
id: int
14+
hash: str
15+
16+
17+
class ClientsConfig(BaseModel):
18+
bots: Path
19+
userbots: Path
20+
21+
22+
class TransactionConfig(BaseModel):
23+
max_age_seconds: int = Field(..., alias="max_age_seconds")
24+
25+
26+
class HorizonConfig(BaseModel):
27+
max_len: int
28+
transaction: TransactionConfig
29+
30+
31+
class MessageCacheConfig(BaseModel):
32+
max_len: int
33+
34+
35+
class PageConfig(BaseModel):
36+
fullness: float
37+
38+
39+
class HeapConfig(BaseModel):
40+
chat: int
41+
page: PageConfig
42+
43+
44+
class RelationsConfig(BaseModel):
45+
chat: int
46+
47+
48+
class OverflowConfig(BaseModel):
49+
len: int
50+
timeout_seconds: int | float
51+
52+
53+
class BufferConfig(BaseModel):
54+
chat: int
55+
overflow: OverflowConfig
56+
57+
58+
class TgdbConfig(BaseModel):
59+
uvicorn: UvicornConfig
60+
api: APIConfig
61+
clients: ClientsConfig
62+
horizon: HorizonConfig
63+
message_cache: MessageCacheConfig
64+
heap: HeapConfig
65+
relations: RelationsConfig
66+
buffer: BufferConfig
67+
68+
@classmethod
69+
def load(cls, path: Path) -> "TgdbConfig":
70+
with path.open() as file:
71+
data = yaml.safe_load(file)
72+
73+
conf = data["conf"]
74+
return TgdbConfig(**conf)

src/tgdb/main/common/di.py

Lines changed: 32 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@
3838
from tgdb.infrastructure.adapters.uuids import UUIDs4
3939
from tgdb.infrastructure.async_map import AsyncMap
4040
from tgdb.infrastructure.async_queque import AsyncQueque
41-
from tgdb.infrastructure.pyyaml.conf import Conf
41+
from tgdb.infrastructure.pyyaml.config import TgdbConfig
4242
from tgdb.infrastructure.telethon.client_pool import (
4343
TelegramClientPool,
4444
loaded_client_pool_from_farm_file,
@@ -62,8 +62,8 @@ class MainIOProvider(Provider):
6262
provide_envs = provide(Envs.load, scope=Scope.APP)
6363

6464
@provide(scope=Scope.APP)
65-
def provide_conf(self, envs: Envs) -> Conf:
66-
return Conf.load(envs.conf_path)
65+
def provide_conf(self, envs: Envs) -> TgdbConfig:
66+
return TgdbConfig.load(envs.conf_path)
6767

6868

6969
class CommonProvider(Provider):
@@ -81,33 +81,35 @@ class CommonProvider(Provider):
8181
)
8282

8383
@provide(scope=Scope.APP)
84-
async def provide_bot_pool(self, conf: Conf) -> AsyncIterator[BotPool]:
84+
async def provide_bot_pool(
85+
self, config: TgdbConfig
86+
) -> AsyncIterator[BotPool]:
8587
pool = BotPool(loaded_client_pool_from_farm_file(
86-
conf.clients.bots,
87-
conf.api.id,
88-
conf.api.hash,
88+
config.clients.bots,
89+
config.api.id,
90+
config.api.hash,
8991
))
9092
async with pool:
9193
yield pool
9294

9395
@provide(scope=Scope.APP)
9496
async def provide_userbot_pool(
95-
self, conf: Conf
97+
self, config: TgdbConfig
9698
) -> AsyncIterator[UserBotPool]:
9799
pool = UserBotPool(loaded_client_pool_from_farm_file(
98-
conf.clients.userbots,
99-
conf.api.id,
100-
conf.api.hash,
100+
config.clients.userbots,
101+
config.api.id,
102+
config.api.hash,
101103
))
102104
async with pool:
103105
yield pool
104106

105107
@provide(scope=Scope.APP)
106-
def provide_horizon(self, conf: Conf) -> Horizon:
108+
def provide_horizon(self, config: TgdbConfig) -> Horizon:
107109
return horizon(
108110
0,
109-
conf.horizon.max_len,
110-
int(conf.horizon.transaction.max_age_seconds * 1_000_000_000),
111+
config.horizon.max_len,
112+
int(config.horizon.transaction.max_age_seconds * 1_000_000_000),
111113
)
112114

113115
@provide(scope=Scope.APP)
@@ -118,25 +120,27 @@ def provide_shared_horizon(self, horizon: Horizon) -> SharedHorizon:
118120
def provide_lazy_message_map(
119121
self,
120122
user_bot_pool: UserBotPool,
121-
conf: Conf,
123+
config: TgdbConfig,
122124
) -> MessageIndexLazyMap:
123-
return message_index_lazy_map(user_bot_pool, conf.message_cache.max_len)
125+
return message_index_lazy_map(
126+
user_bot_pool, config.message_cache.max_len
127+
)
124128

125129
@provide(scope=Scope.APP)
126130
def provide_in_telegram_heap(
127131
self,
128132
bot_pool: BotPool,
129133
user_bot_pool: UserBotPool,
130-
conf: Conf,
134+
config: TgdbConfig,
131135
message_index_lazy_map: MessageIndexLazyMap,
132136
) -> InTelegramHeap:
133137
return InTelegramHeap(
134138
bot_pool,
135139
user_bot_pool,
136140
bot_pool,
137141
bot_pool,
138-
conf.heap.chat,
139-
InTelegramHeap.encoded_tuple_max_len(conf.heap.page.fullness),
142+
config.heap.chat,
143+
InTelegramHeap.encoded_tuple_max_len(config.heap.page.fullness),
140144
message_index_lazy_map,
141145
)
142146

@@ -149,23 +153,25 @@ def provide_in_telegram_heap(
149153
@provide(scope=Scope.APP)
150154
def provide_in_memory_buffer[ValueT](
151155
self,
152-
conf: Conf,
156+
config: TgdbConfig,
153157
) -> InMemoryBuffer[ValueT]:
154158
return InMemoryBuffer(
155-
conf.buffer.overflow.len,
156-
conf.buffer.overflow.timeout_seconds,
159+
config.buffer.overflow.len,
160+
config.buffer.overflow.timeout_seconds,
157161
deque(),
158162
)
159163

160164
@provide(scope=Scope.APP)
161165
async def provide_buffer(
162166
self,
163-
conf: Conf,
167+
config: TgdbConfig,
164168
bot_pool: BotPool,
165169
user_bot_pool: UserBotPool,
166170
buffer: InMemoryBuffer[Commit | PreparedCommit]
167171
) -> AsyncIterator[Buffer[Commit | PreparedCommit]]:
168-
in_tg_bytes = InTelegramBytes(bot_pool, user_bot_pool, conf.buffer.chat)
172+
in_tg_bytes = InTelegramBytes(
173+
bot_pool, user_bot_pool, config.buffer.chat
174+
)
169175

170176
biffer = InTelegramReplicablePreparedCommitBuffer(buffer, in_tg_bytes)
171177

@@ -179,13 +185,13 @@ def provide_relation_cache(self) -> RelationCache:
179185
@provide(scope=Scope.APP)
180186
async def provide_relations(
181187
self,
182-
conf: Conf,
188+
config: TgdbConfig,
183189
bot_pool: BotPool,
184190
user_bot_pool: UserBotPool,
185191
relation_cache: RelationCache,
186192
) -> AsyncIterator[Relations]:
187193
in_tg_bytes = InTelegramBytes(
188-
bot_pool, user_bot_pool, conf.relations.chat
194+
bot_pool, user_bot_pool, config.relations.chat
189195
)
190196
relations = InTelegramReplicableRelations(in_tg_bytes, relation_cache)
191197

src/tgdb/main/dev_server/__main__.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
import uvicorn
22

3-
from tgdb.infrastructure.pyyaml.conf import Conf
3+
from tgdb.infrastructure.pyyaml.config import TgdbConfig
44
from tgdb.main.common.di import main_io_container
55

66

77
def main() -> None:
8-
tgdb_config = main_io_container.get(Conf)
8+
tgdb_config = main_io_container.get(TgdbConfig)
99

1010
uvicorn.run(
1111
"tgdb.main.dev_server.asgi:app",

src/tgdb/main/prod_server/__main__.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,14 @@
22

33
import uvicorn
44

5-
from tgdb.infrastructure.pyyaml.conf import Conf
5+
from tgdb.infrastructure.pyyaml.config import TgdbConfig
66
from tgdb.main.server.di import server_container
77
from tgdb.presentation.fastapi.common.app import app_from
88

99

1010
async def amain() -> None:
1111
app = await app_from(server_container)
12-
tgdb_config = await server_container.get(Conf)
12+
tgdb_config = await server_container.get(TgdbConfig)
1313

1414
uvicorn_config = uvicorn.Config(
1515
app,

src/tgdb/presentation/fastapi/relation/routes/view_tuples.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,12 @@
1010
from tgdb.entities.numeration.number import Number
1111
from tgdb.entities.relation.scalar import Scalar
1212
from tgdb.entities.relation.tuple import Tuple
13-
from tgdb.presentation.fastapi.relation.schemas.error import NoRelationSchema
1413
from tgdb.presentation.fastapi.common.tags import Tag
1514
from tgdb.presentation.fastapi.horizon.schemas.error import (
1615
NoTransactionSchema,
1716
TransactionCommittingSchema,
1817
)
18+
from tgdb.presentation.fastapi.relation.schemas.error import NoRelationSchema
1919
from tgdb.presentation.fastapi.relation.schemas.tuple import TupleSchema
2020

2121

tests/test_tgdb/test_infrastructure/test_pyyaml/test_conf.py

Lines changed: 0 additions & 7 deletions
This file was deleted.
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
from pathlib import Path
2+
3+
from tgdb.infrastructure.pyyaml.config import TgdbConfig
4+
5+
6+
def test_no_errors() -> None:
7+
TgdbConfig.load(Path("deploy/dev/tgdb/conf.yaml"))

0 commit comments

Comments
 (0)