11import logging
22import os
3- import pathlib
43
5- from dependency_injector .wiring import inject
4+ from dependency_injector .wiring import Provide , inject
65
76from mpt_api_client import AsyncMPTClient
87from mpt_api_client .resources .accounts .buyers import Buyer
8+ from seed .container import Container
99from seed .context import Context
10- from seed .defaults import DEFAULT_CONTEXT , DEFAULT_MPT_OPERATIONS
10+ from seed .static . static import ICON
1111
1212logger = logging .getLogger (__name__ )
1313
14- icon = pathlib .Path ("seed/data/logo.png" ).resolve ()
15-
1614
1715@inject
1816async def get_buyer (
19- context : Context = DEFAULT_CONTEXT ,
20- mpt_operations : AsyncMPTClient = DEFAULT_MPT_OPERATIONS ,
17+ context : Context = Provide [ Container . context ] ,
18+ mpt_operations : AsyncMPTClient = Provide [ Container . mpt_operations ] ,
2119) -> Buyer | None :
2220 """Get buyer from context or fetch from API."""
2321 buyer_id = context .get_string ("accounts.buyer.id" )
@@ -36,7 +34,7 @@ async def get_buyer(
3634
3735
3836@inject
39- def build_buyer_data (context : Context = DEFAULT_CONTEXT ) -> dict [str , object ]:
37+ def build_buyer_data (context : Context = Provide [ Container . context ] ) -> dict [str , object ]:
4038 """Build buyer data dictionary for creation."""
4139 buyer_account_id = os .getenv ("CLIENT_ACCOUNT_ID" )
4240 if not buyer_account_id :
@@ -65,16 +63,16 @@ def build_buyer_data(context: Context = DEFAULT_CONTEXT) -> dict[str, object]:
6563
6664@inject
6765async def init_buyer (
68- context : Context = DEFAULT_CONTEXT ,
69- mpt_operations : AsyncMPTClient = DEFAULT_MPT_OPERATIONS ,
66+ context : Context = Provide [ Container . context ] ,
67+ mpt_operations : AsyncMPTClient = Provide [ Container . mpt_operations ] ,
7068) -> Buyer :
7169 """Get or create buyer."""
7270 buyer = await get_buyer (context = context , mpt_operations = mpt_operations )
7371 if buyer is None :
7472 buyer_data = build_buyer_data (context = context )
7573 logger .debug ("Creating buyer ..." )
76- with open (str ( icon ), "rb" ) as icon_file : # noqa: PTH123
77- created = await mpt_operations .accounts .buyers .create (buyer_data , file = icon_file )
74+ with ICON . open ("rb" ) as icon_fd :
75+ created = await mpt_operations .accounts .buyers .create (buyer_data , file = icon_fd )
7876 if isinstance (created , Buyer ):
7977 context .set_resource ("accounts.buyer" , created )
8078 context ["accounts.buyer.id" ] = created .id
0 commit comments