-
Project description
miniconfig
making configuration phase, in your application. (Tiny version of almost pyramid's configurator object)
# yourapp/__init__.py
from miniconfig import ConfiguratorCore
class Configurator(ConfiguratorCore):
def make_app(self):
self.commit()
return App(self.settings)
class App:
def __init__(self, settings):
self.settings = settings
yourapp/pluginA.py
class A:
pass
def includeme(config):
config.settings["A"] = A()
yourapp/pluginB.py
class B:
pass
def includeme(config):
config.include(".pluginA")
config.settings["B"] = B()
application user
from yourapp import Configurator
config = Configurator()
config.include("yourapp.pluginB")
app = config.make_app()
print(app.settings.keys()) # dict_keys(['A', 'B'])
Adding directives
directive means that action of configurator.
how to define and use directive
def hello(config, name):
def register():
assert config.settings["foo"] == "foo"
print("hello: {}".format(name))
discriminator = (hello, name)
config.action(discriminator, register)
config = Configurator(settings={"foo": "foo"})
config.add_directive("hello", hello)
config.hello("foo")
it is also supported that to define directives by dotted name
foo/bar.py
def hello(config):
def register():
print("hai")
discriminator = id(object()) # xxx
config.action(discriminator, register)
yourapp
config = Configurator()
config.add_directive("hello", "foo.bar:hello")
config.hello()
config.commit() # hai
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distributions
No source distribution files available for this release.See tutorial on generating distribution archives.
Built Distribution
File details
Details for the file miniconfig-0.6.0-py3-none-any.whl
.
File metadata
- Download URL: miniconfig-0.6.0-py3-none-any.whl
- Upload date:
- Size: 6.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/45.0.0 requests-toolbelt/0.9.1 tqdm/4.41.1 CPython/3.8.2
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 036577ff1d4693fefb28d132b2c2c8aedc5bdc93e3068d28ad3bfbda7f523a14 |
|
MD5 | 518bf8e8935b9ceef4b1a7a4845f6a9d |
|
BLAKE2b-256 | 2e47d274e81e2382db1aa574835b14a8d88b607821b8981bd2ade7e934ec33bb |