1616from ynamazon .amazon_transactions import AmazonConfig , get_amazon_transactions
1717from ynamazon .exceptions import YnabSetupError
1818from ynamazon .main import process_transactions
19- from ynamazon .settings import ConfigFile , SecretApiKey , SecretBudgetId , settings
19+ from ynamazon .settings import ConfigFile , SecretApiKey , SecretBudgetId , get_settings
2020from ynamazon .ynab_transactions import (
2121 TempYnabTransaction ,
2222 get_ynab_transactions ,
@@ -35,14 +35,14 @@ def print_ynab_transactions(
3535 str | None ,
3636 Argument (
3737 help = "YNAB API key" ,
38- default_factory = lambda : settings .ynab_api_key .get_secret_value (),
38+ default_factory = lambda : get_settings () .ynab_api_key .get_secret_value (),
3939 ),
4040 ],
4141 budget_id : Annotated [
4242 str | None ,
4343 Argument (
4444 help = "YNAB Budget ID" ,
45- default_factory = lambda : settings .ynab_budget_id .get_secret_value (),
45+ default_factory = lambda : get_settings () .ynab_budget_id .get_secret_value (),
4646 ),
4747 ],
4848) -> None :
@@ -83,13 +83,15 @@ def print_ynab_transactions(
8383def print_amazon_transactions (
8484 user_email : Annotated [
8585 str ,
86- Argument (help = "Amazon username" , default_factory = lambda : settings .amazon_user ),
86+ Argument (
87+ help = "Amazon username" , default_factory = lambda : get_settings ().amazon_user
88+ ),
8789 ],
8890 user_password : Annotated [
8991 str ,
9092 Argument (
9193 help = "Amazon password" ,
92- default_factory = lambda : settings .amazon_password .get_secret_value (),
94+ default_factory = lambda : get_settings () .amazon_password .get_secret_value (),
9395 ),
9496 ],
9597 order_years : Annotated [
@@ -148,28 +150,28 @@ def ynamazon(
148150 str | None ,
149151 Argument (
150152 help = "YNAB API key" ,
151- default_factory = lambda : settings .ynab_api_key .get_secret_value (),
153+ default_factory = lambda : get_settings () .ynab_api_key .get_secret_value (),
152154 ),
153155 ],
154156 ynab_budget_id : Annotated [
155157 str | None ,
156158 Argument (
157159 help = "YNAB Budget ID" ,
158- default_factory = lambda : settings .ynab_budget_id .get_secret_value (),
160+ default_factory = lambda : get_settings () .ynab_budget_id .get_secret_value (),
159161 ),
160162 ],
161163 amazon_user : Annotated [
162164 str ,
163165 Argument (
164166 help = "Amazon username" ,
165- default_factory = lambda : settings .amazon_user ,
167+ default_factory = lambda : get_settings () .amazon_user ,
166168 ),
167169 ],
168170 amazon_password : Annotated [
169171 str ,
170172 Argument (
171173 help = "Amazon password" ,
172- default_factory = lambda : settings .amazon_password .get_secret_value (),
174+ default_factory = lambda : get_settings () .amazon_password .get_secret_value (),
173175 ),
174176 ],
175177) -> None :
@@ -210,13 +212,13 @@ def new_ynamazon( # noqa: C901
210212 config .amazon_user = amazon_user
211213 if amazon_password is not None :
212214 config .amazon_password = SecretStr (amazon_password )
213- cli_settings = settings .model_copy (update = config .model_dump ())
215+ cli_settings = get_settings () .model_copy (update = config .model_dump ())
214216 else :
215217 assert ynab_api_key is not None , "YNAB API key is required"
216218 assert ynab_budget_id is not None , "YNAB Budget ID is required"
217219 assert amazon_user is not None , "Amazon username is required"
218220 assert amazon_password is not None , "Amazon password is required"
219- cli_settings = settings .model_copy (
221+ cli_settings = get_settings () .model_copy (
220222 update = {
221223 "ynab_api_key" : SecretApiKey (ynab_api_key ),
222224 "ynab_budget_id" : SecretBudgetId (ynab_budget_id ),
@@ -235,7 +237,7 @@ def new_ynamazon( # noqa: C901
235237 budget_id = cli_settings .ynab_budget_id .get_secret_value (),
236238 )
237239 except YnabSetupError as e :
238- console .print (f"[bold red]Settings error: { e } [/]" )
240+ console .print (f"[bold red]get_settings() error: { e } [/]" )
239241 console .print (
240242 "[bold red]Please check your .env file or use the --config option to specify a config file.[/]"
241243 )
@@ -248,7 +250,7 @@ def new_ynamazon( # noqa: C901
248250 debug = debug ,
249251 )
250252 except ValidationError as e :
251- console .print (f"[bold red]Settings error: { e } [/]" )
253+ console .print (f"[bold red]get_settings() error: { e } [/]" )
252254 console .print (
253255 "[bold red]Please check your .env file or use the --config option to specify a config file.[/]"
254256 )
0 commit comments