1
+ import itertools
1
2
import logging
2
3
import os
3
4
import sys
@@ -96,7 +97,7 @@ def configuration(self) -> DictConfig:
96
97
assert self .__config is not None
97
98
return self .__config
98
99
99
- def _get_possible_configuration_paths (self , additional_paths : List [ str ] = [] ) -> Iterable [str ]:
100
+ def _get_possible_configuration_paths (self ) -> Iterable [str ]:
100
101
"""List of paths where to find configuration files"""
101
102
name = self .name
102
103
is_windows = sys .platform .startswith ('win' )
@@ -111,7 +112,6 @@ def _get_possible_configuration_paths(self, additional_paths: List[str] = []) ->
111
112
if path and '$' not in path :
112
113
for ext in load_file .SUPPORTED_EXTENSIONS :
113
114
yield path .format (name + '.' + ext )
114
- yield from additional_paths
115
115
116
116
def _load_dotenv (self , load_dotenv : Optional [bool ] = None ):
117
117
"""Load dotenv variables (optionally)"""
@@ -163,6 +163,7 @@ def _get_configurations(
163
163
164
164
- All of the default configurations
165
165
- The app configuration
166
+ - Read file defined in PYTHON_ALPHACONF
166
167
- Reads existing files from possible configuration paths
167
168
- Reads environment variables based on given prefixes
168
169
@@ -176,8 +177,13 @@ def _get_configurations(
176
177
yield default_configuration
177
178
yield self ._app_configuration ()
178
179
# Read files
179
- for path in self ._get_possible_configuration_paths (configuration_paths ):
180
- if not (path in configuration_paths or os .path .isfile (path )):
180
+ env_configuration_path = os .environ .get ('PYTHON_ALPHACONF' ) or ''
181
+ for path in itertools .chain (
182
+ [env_configuration_path ],
183
+ self ._get_possible_configuration_paths (),
184
+ configuration_paths ,
185
+ ):
186
+ if not os .path .isfile (path ):
181
187
continue
182
188
application_log .debug ('Load configuration from %s' , path )
183
189
yield load_file .read_configuration_file (path )
0 commit comments