Skip to content

Commit

Permalink
API review (#2)
Browse files Browse the repository at this point in the history
* Restructure the API
* Refactor getting and setting the configuration
* Copy context in run()
  • Loading branch information
kmagusiak authored Oct 6, 2022
1 parent 927524c commit 604756c
Show file tree
Hide file tree
Showing 9 changed files with 488 additions and 480 deletions.
3 changes: 2 additions & 1 deletion .github/workflows/lint.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ jobs:
- name: Set up Python
uses: actions/setup-python@v2
with:
python-version: "3.10"
# use minimum version here from setup.py
python-version: "3.8"
- name: Install dependencies
run: |
python -m pip install --upgrade pip
Expand Down
15 changes: 7 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,17 +31,18 @@ To run an application, you need...
def main():
log = logging.getLogger()
# get the DictConfig from the current application
log.info('app name:', alphaconf.configuration().application.name)
log.info('app name:', alphaconf.configuration.get().application.name)
# shortcut to get an option as a dict, str, etc.
log.info('server.user:', alphaconf.get('server.user'))
log.info('has server.user:', alphaconf.get('server.user', bool))

if __name__ == '__main__':
# run the application
alphaconf.Application(
alphaconf.run(
main,
name='example',
version='0.1',
).run(main)
)

## Secrets

Expand All @@ -59,8 +60,7 @@ when the script is directly called.
ns = Collection() # define the invoke configuration
import alphaconf.invoke
alphaconf.setup_configuration({'backup': 'all'})
alphaconf.invoke.invoke_application(__name__, ns)

alphaconf.invoke.run(__name__, ns)

## How the configuration is loaded

Expand All @@ -71,16 +71,15 @@ Then configuration is built from:

- default configurations defined using (`alphaconf.setup_configuration`)
- `application` key is generated
- configuration files from the system (from your HOME and configuration
directories)
- configuration files from configuration directories (base on application name)
- environment variables based on key prefixes,
except "BASE" and "PYTHON";
if you have a configuration key "abc", all environment variables starting
with "ABC_" will be loaded where keys are converted to lower case and "_"
to ".": "ABC_HELLO=a" would set "abc.hello=a"
- key-values from the program arguments

Finally, the configuration is fully resolved once and logging is configured.
Finally, the configuration is fully resolved and logging is configured.

## Configuration templates and resolvers

Expand Down
Loading

0 comments on commit 604756c

Please sign in to comment.