configurator
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()
def includeme(config):
config.settings["A"] = PluginA()
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))
config.action(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")
config.action(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 Distribution
miniconfig-0.2.0.tar.gz
(3.4 kB
view hashes)
Built Distribution
Close
Hashes for miniconfig-0.2.0-py2.py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 45a0b89243c26f867fd608db3be7cbce99e9ed4dee6d0a856f71ce4b1e6f4831 |
|
MD5 | 70689fe0052ec65d3b16d11c72a72e8b |
|
BLAKE2b-256 | c234da65eca28f6cfb2f74e4d33fba751317ed5f4a82f72b98848f1a961c1b85 |