Skip to content

Commit

Permalink
New API and pydantic (#21)
Browse files Browse the repository at this point in the history
  • Loading branch information
kmagusiak authored Nov 26, 2023
1 parent 04f6aa7 commit d898112
Show file tree
Hide file tree
Showing 30 changed files with 1,160 additions and 897 deletions.
12 changes: 6 additions & 6 deletions .github/workflows/lint-test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,12 @@ jobs:
lint:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v3
- name: Set up Python
uses: actions/setup-python@v2
uses: actions/setup-python@v4
with:
# use minimum version here from setup.py
python-version: "3.8"
python-version: "3.9"
- name: Install dependencies
run: |
python -m pip install --upgrade pip
Expand All @@ -28,11 +28,11 @@ jobs:
strategy:
matrix:
# lowest, common (defaut ubuntu LTS), newest
python-version: ["3.8", "3.10", "3.11"]
python-version: ["3.9", "3.10", "3.11"]
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v3
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v2
uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python-version }}
- name: Install dependencies
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/python-publish.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,12 @@ jobs:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v3
with:
# don't use shallow checkout to determine an intermediary version correctly
fetch-depth: 0
- name: Set up Python
uses: actions/setup-python@v2
uses: actions/setup-python@v4
with:
python-version: '3.11'
- name: Install dependencies
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ __pycache__
# Local env
.env
.venv
/local*

# Other tools
dist
Expand Down
30 changes: 17 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
A small library to ease writing parameterized scripts.
The goal is to execute a single script and be able to overwrite the parameters
easily.
The configuration is based on [OmegaConf](https://omegaconf.readthedocs.io/).
Optionally, loading from toml is possible.
The configuration is based on [OmegaConf].
Optionally, loading from toml or using [pydantic] is possible.

To run multiple related tasks, there is an integration with
[invoke](https://www.pyinvoke.org).
Expand All @@ -23,10 +23,9 @@ To run an application, you need...
import alphaconf
import logging
# define the default values and helpers
alphaconf.setup_configuration("""
server:
url: http://default
""", {
alphaconf.setup_configuration({
"server.url": "http://default",
}, {
"server.url": "The URL to show here",
})

Expand All @@ -36,15 +35,15 @@ def main():
log.info('has server.user:', alphaconf.get('server.user', bool))

if __name__ == '__main__':
alphaconf.run(main)
alphaconf.cli.run(main)
```

Invoking:
```bash
python myapp.py server.url=http://github.com
```

During an interactive session, you can set the application in the current
During an *interactive session*, you can set the application in the current
context.
```python
# import other modules
Expand All @@ -64,7 +63,7 @@ Then configuration is built from:

- default configurations defined using (`alphaconf.setup_configuration`)
- `application` key is generated
- PYTHON_ALPHACONF may contain a path to a configuration file
- `PYTHON_ALPHACONF` environment variable may contain a path to load
- configuration files from configuration directories (using application name)
- environment variables based on key prefixes,
except "BASE" and "PYTHON";
Expand All @@ -77,13 +76,14 @@ Finally, the configuration is fully resolved and logging is configured.

## Configuration templates and resolvers

Omegaconf's resolvers may be used as configuration values.
[OmegaConf]'s resolvers may be used as configuration values.
For example, `${oc.env:USER,me}` would resolve to the environment variable
USER with a default value "me".
Similarly, `${oc.select:path}` will resolve to another configuration value.

Additional resolvers are added to read file contents.
These are the same as type casts: read_text, read_strip, read_bytes.
-- TODO use secrets for v1

The select is used to build multiple templates for configurations by providing
base configurations.
Expand All @@ -96,6 +96,7 @@ dict defined in base.logging.default and you can select it using
## Configuration values and integrations

### Typed-configuration
-- TODO update to pydantic

You can use *omegaconf* with *dataclasses* to specify which values are
enforced in the configuration.
Expand Down Expand Up @@ -123,7 +124,10 @@ alphaconf.setup_configuration({'backup': 'all'})
alphaconf.invoke.run(__name__, ns)
```

### Interactive and manual usage
## Way to 1.0
- Secret management
- Install completions for bash
- Run a function after importing the module

Use `alphaconf.interactive.mount()` or load manually create an
`alphaconf.Application`, configure it and set it.
[OmegaConf]: https://omegaconf.readthedocs.io/
[pydantic]: https://docs.pydantic.dev/latest/
Loading

0 comments on commit d898112

Please sign in to comment.