Skip to content

Commit 57186f6

Browse files
committed
Load configuration from PYTHON_ALPHACONF
1 parent 39e3451 commit 57186f6

File tree

3 files changed

+14
-7
lines changed

3 files changed

+14
-7
lines changed

README.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,8 @@ Then configuration is built from:
6464

6565
- default configurations defined using (`alphaconf.setup_configuration`)
6666
- `application` key is generated
67-
- configuration files from configuration directories (base on application name)
67+
- PYTHON_ALPHACONF may contain a path to a configuration file
68+
- configuration files from configuration directories (using application name)
6869
- environment variables based on key prefixes,
6970
except "BASE" and "PYTHON";
7071
if you have a configuration key "abc", all environment variables starting
@@ -92,7 +93,7 @@ So, `logging: ${oc.select:base.logging.default}` resolves to the configuration
9293
dict defined in base.logging.default and you can select it using
9394
`--select logging=default`.
9495

95-
## Configuration values and intergations
96+
## Configuration values and integrations
9697

9798
### Typed-configuration
9899

alphaconf/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,7 @@ def run(
203203
arguments: Union[bool, List[str]] = True,
204204
*,
205205
should_exit: bool = True,
206-
app: Application = None,
206+
app: Optional[Application] = None,
207207
**config,
208208
) -> Optional[T]:
209209
"""Run this application

alphaconf/internal/__init__.py

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import itertools
12
import logging
23
import os
34
import sys
@@ -96,7 +97,7 @@ def configuration(self) -> DictConfig:
9697
assert self.__config is not None
9798
return self.__config
9899

99-
def _get_possible_configuration_paths(self, additional_paths: List[str] = []) -> Iterable[str]:
100+
def _get_possible_configuration_paths(self) -> Iterable[str]:
100101
"""List of paths where to find configuration files"""
101102
name = self.name
102103
is_windows = sys.platform.startswith('win')
@@ -111,7 +112,6 @@ def _get_possible_configuration_paths(self, additional_paths: List[str] = []) ->
111112
if path and '$' not in path:
112113
for ext in load_file.SUPPORTED_EXTENSIONS:
113114
yield path.format(name + '.' + ext)
114-
yield from additional_paths
115115

116116
def _load_dotenv(self, load_dotenv: Optional[bool] = None):
117117
"""Load dotenv variables (optionally)"""
@@ -163,6 +163,7 @@ def _get_configurations(
163163
164164
- All of the default configurations
165165
- The app configuration
166+
- Read file defined in PYTHON_ALPHACONF
166167
- Reads existing files from possible configuration paths
167168
- Reads environment variables based on given prefixes
168169
@@ -176,8 +177,13 @@ def _get_configurations(
176177
yield default_configuration
177178
yield self._app_configuration()
178179
# 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):
181187
continue
182188
application_log.debug('Load configuration from %s', path)
183189
yield load_file.read_configuration_file(path)

0 commit comments

Comments
 (0)