Skip to main content

Provide an auto-discovery process for configurations

Project description

Build Status PyPI version

Mission

Provide an auto-discovery process of configurations for simple code use. Given a path and a list of pattern, the result config will be a shortcut to any config.

Usage

Setup:

config = mixin(
    path="path/to/my/files",
    patterns=["path/(*)/file.yaml"]
)

Use it:

print config.mynamespace.key

Parameters

  • path

    Initial path to configs. Patterns will be tested against the file structure underneath the path, and it will be ignored in determining the namespacing.

  • patterns

    A list of file paths containing (or not) placeholders "(*)" o find where the configuration files are located. The patterns definition order defines which keys has the priority, the last one being the most relevant.

    Each placeholder in the path will result in a namespace in the resulting config. So let's say you have a pattern

      dir1/(*)/dir2/(*).yaml
    

    If this pattern finds the file : "dir1/ns1/dir2/file.yaml" that contains "key: 'value'", the resulting config will be

      config.ns1.file.key == "value"
    

    now if the pattern was

      dir1/ns1/dir2/file.yaml
    

    for the same file, the resulting config would simply be

      config.key == "value"
    

    so you can use placeholders "(*)" to namespace the resulting config and use "*" without the parenthesis to have a variable path without the namespacing

      dir1/(*)/dir2/*.yaml
      config.ns1.key == "value"
    

Mocking the probing

Your unit test can have your code use fake_probe instead to which to give a dict, and it will appear as if it was just mixed-in. Example:

config = fake_probe({
    "ns1": {
        "file": {
            "key": "value"
        }
    }
})
# then
config.ns1.file.key == "value"

Contributing

Feel free to raise issues and send some pull request, we'll be happy to look at them!

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

config_mixin-1.0.1.tar.gz (10.1 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

config_mixin-1.0.1-py3-none-any.whl (7.3 kB view details)

Uploaded Python 3

File details

Details for the file config_mixin-1.0.1.tar.gz.

File metadata

  • Download URL: config_mixin-1.0.1.tar.gz
  • Upload date:
  • Size: 10.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for config_mixin-1.0.1.tar.gz
Algorithm Hash digest
SHA256 b1c028c74041350b783b2ddaa41c2d11e352ffd91c50fea700d6eb776c0a29ff
MD5 1eeee02036e895baf4e4d888bf0f1938
BLAKE2b-256 b71020a8a2180bb862d24f5f9de2957b144702a5770a33e1253838202be800ea

See more details on using hashes here.

Provenance

The following attestation bundles were made for config_mixin-1.0.1.tar.gz:

Publisher: publish.yml on stephanerobert/config-mixin

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file config_mixin-1.0.1-py3-none-any.whl.

File metadata

  • Download URL: config_mixin-1.0.1-py3-none-any.whl
  • Upload date:
  • Size: 7.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for config_mixin-1.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 5c4b0b4950768764e1e147dbca2b688994f097ad74b76471db3ab88ae2365fac
MD5 1a981b55a06a7c5555f42f539f10155d
BLAKE2b-256 da913b7dd642bd83dbf7b56fa261ffee9c69eb22f8b6ef86ae0508a44ce9377e

See more details on using hashes here.

Provenance

The following attestation bundles were made for config_mixin-1.0.1-py3-none-any.whl:

Publisher: publish.yml on stephanerobert/config-mixin

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page