Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 3 additions & 8 deletions .github/workflows/pypi-publish.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,11 @@ jobs:
- name: Check out the repository
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2

- name: Set up Python
uses: actions/setup-python@a309ff8b426b58ec0e2a45f0f869d46889d02405 # v6.2.0
with:
python-version: "3.x"

- name: Install pypa/build
run: python3 -m pip install build --user
- name: Set up uv
uses: astral-sh/setup-uv@eb1897b8dc4b5d5bfe39a428a8f2304605e0983c # v7.0.0

- name: Build a binary wheel and a source tarball
run: python3 -m build --sdist --wheel --outdir dist/
run: uv build --sdist --wheel --out-dir dist/

- name: Publish to PyPI
uses: pypa/gh-action-pypi-publish@ed0c53931b1dc9bd32cbe73a98c7f6766f8a527e
3 changes: 1 addition & 2 deletions .github/workflows/test-pr.yaml
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
name: Test Pull Request

on:
# We use pull_request_target so that dependabot-created workflows can run
pull_request_target:
pull_request:
types:
- opened
- synchronize
Expand Down
22 changes: 7 additions & 15 deletions .github/workflows/tox.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,41 +8,33 @@ on:
description: The ref to build.
required: true

# Use the head ref for workflow concurrency, with cancellation
# This should mean that any previous workflows for a PR get cancelled when a new commit is pushed
concurrency:
group: ${{ github.workflow }}-${{ github.head_ref }}
cancel-in-progress: true
# Concurrency is handled by the calling workflow. Defining a group here would
# deadlock, as github.workflow resolves to the caller's name in a reusable workflow.

jobs:
build:
name: Tox unit tests and linting
runs-on: ubuntu-latest
strategy:
matrix:
python-version: ['3.10','3.12']
python-version: ['3.10', '3.14']

steps:
- name: Check out the repository
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
with:
ref: ${{ inputs.ref || github.ref }}

- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@a309ff8b426b58ec0e2a45f0f869d46889d02405 # v6.2.0
- name: Set up uv
uses: astral-sh/setup-uv@eb1897b8dc4b5d5bfe39a428a8f2304605e0983c # v7.0.0
with:
python-version: ${{ matrix.python-version }}

- name: Install dependencies
run: |
python -m pip install --upgrade pip
python -m pip install tox

- name: Test with tox
run: tox
run: uv run --locked tox

- name: Generate coverage reports
run: tox -e cover
run: uv run --locked tox -e cover

- name: Archive code coverage results
uses: actions/upload-artifact@bbbca2ddaa5d8feaa63e36b76fdaad77386f024f # v7.0.0
Expand Down
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,4 @@ cover/
.coverage*
!.coveragerc
.tox
.stestr
.venv
3 changes: 0 additions & 3 deletions .stestr.conf

This file was deleted.

18 changes: 9 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,18 +43,18 @@ class ChildConfig(Section):
class MainConfig(
Configuration,
# The default path for the configuration file
default_path = "/etc/mypackage/config.yaml",
default_path="/etc/mypackage/config.yaml",
# The environment variable that can be used to specify a different config file
path_env_var = "MYPACKAGE_CONFIG",
path_env_var="MYPACKAGE_CONFIG",
# The prefix that should be used for environment variable overrides
env_prefix = "MYPACKAGE"
env_prefix="MYPACKAGE",
):
child: ChildConfig
item4: str


# Initialise the configuration object
settings = MainConfig(item4 = "test1")
settings = MainConfig(item4="test1")


# Access nested settings
Expand Down Expand Up @@ -145,7 +145,7 @@ item2: notthedefault

### Environment variable overrides

Individial config items can be overridden using environment variables of the form
Individual config items can be overridden using environment variables of the form

```
{PREFIX}__{NAME}__{NESTEDNAME}=value
Expand Down Expand Up @@ -180,9 +180,9 @@ from configomatic import Configuration, LoggingConfiguration

class MyPackageConfig(
Configuration,
default_path = "/etc/mypackage/config.yaml",
path_env_var = "MYPACKAGE_CONFIG",
env_prefix = "MYPACKAGE"
default_path="/etc/mypackage/config.yaml",
path_env_var="MYPACKAGE_CONFIG",
env_prefix="MYPACKAGE",
):
# This will use the default logging configuration by default
logging: LoggingConfiguration = Field(default_factory=LoggingConfiguration)
Expand Down Expand Up @@ -228,7 +228,7 @@ to use the default logging configuration:
> applications where sending logs to stdout/stderr is encouraged so that log aggregation tools
> can collect them.

### Overridding logging configuration
### Overriding logging configuration

`LoggingConfiguration` will accept any full _or partial_ configuration that conforms to the
[logging configuration dictionary schema](https://docs.python.org/3/library/logging.config.html#logging-config-dictschema).
Expand Down
7 changes: 2 additions & 5 deletions configomatic/configuration.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,11 +68,7 @@ def __new__(cls, name, bases, attrs, /, **kwargs):
config_env.update(config_env_kwargs)

# Add the config env to the model attrs
# Add a classvar annotation so that Pydantic leaves it alone
attrs["config_env"] = config_env
attrs.setdefault("__annotations__", {})["config_env"] = t.ClassVar[
ConfigEnvironmentDict
]

return super().__new__(cls, name, bases, attrs, **pydantic_kwargs)

Expand All @@ -87,7 +83,8 @@ class Configuration(
Base class for a configuration.
"""

config_env = ConfigEnvironmentDict()
# A ClassVar so that Pydantic leaves it alone, which subclasses inherit
config_env: t.ClassVar[ConfigEnvironmentDict] = ConfigEnvironmentDict()

def __init__(self, _use_file=True, _path=None, _use_env=True, **init_kwargs):
# Work out which configs to use
Expand Down
Loading
Loading