11import os
2+ from pathlib import Path
23import dotenv
34
45required = object ()
56
67
78def cast_bool (val ):
8- return (
9- val .lower () in {"1" , "yes" , "true" , "y" , "on" }
10- if isinstance (val , str )
11- else bool (val )
12- )
9+ return val .lower () in {"1" , "yes" , "true" , "y" , "on" } if isinstance (val , str ) else bool (val )
1310
1411
1512def cast_list (val ):
@@ -30,8 +27,11 @@ def cast_django_email(val):
3027
3128class Config :
3229 def __init__ (self , filename = ".env" , ** castings ):
33- self .filename = filename
34- self .found_path = None
30+ if isinstance (filename , (str , Path )):
31+ filename = [filename ]
32+
33+ self .filename = [str (f ) for f in filename ]
34+ self .found_path = []
3535
3636 self .castings = {
3737 bool : cast_bool ,
@@ -40,12 +40,15 @@ def __init__(self, filename=".env", **castings):
4040 "django_email" : cast_django_email ,
4141 }
4242 self .castings .update (** castings )
43-
44- if os .path .exists (self .filename ):
45- self .found_path = self .filename
46- else :
47- self .found_path = dotenv .find_dotenv (self .filename , usecwd = True )
48- self .values = dotenv .dotenv_values (self .found_path , verbose = True )
43+ self .values = {}
44+ for path in self .filename :
45+ if os .path .exists (path ):
46+ found = path
47+ else :
48+ found = dotenv .find_dotenv (path , usecwd = True )
49+
50+ self .found_path .append (found )
51+ self .values .update (** dotenv .dotenv_values (found , verbose = True ))
4952
5053 def add_castings (self , ** kwargs ):
5154 self .castings .update (kwargs )
0 commit comments