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.0.tar.gz (10.1 kB view details)

Uploaded Source

Built Distribution

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

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for config_mixin-1.0.0.tar.gz
Algorithm Hash digest
SHA256 3971b60a377c12ec3ed33e754f8448abd730bf9134238b026b210cc34a40bae7
MD5 c425047365ac2320a0ac9271ed6eee5b
BLAKE2b-256 b561eb127873a7160e375b1526e9c5926b8125bea0f3c875a54ccc6290d2f7d8

See more details on using hashes here.

Provenance

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

Publisher: publish.yml on stephanerobert/config-mixin

Attestations:

File details

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

File metadata

File hashes

Hashes for config_mixin-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 6c54a07de7c0e85640e1bf6010985c3a720e899281509a057f010fceb3e346bf
MD5 9aed63faad163c45eea44ec70ced2824
BLAKE2b-256 ff66be2918b3c1f575ea7b169ba8c7c2aab9320c40a598bc626ef829d8c4272b

See more details on using hashes here.

Provenance

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

Publisher: publish.yml on stephanerobert/config-mixin

Attestations:

Supported by

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