montague - media.readthedocs.org · extension; montague uses that to dispatch to config loaders....
TRANSCRIPT
MontagueRelease 0.2.1
June 17, 2015
Contents
1 Overview 31.1 Montague . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3
2 Installation 5
3 Usage 7
4 Writing your own config loader 94.1 Montague Standard Format . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9
5 Reference 115.1 montague . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 115.2 montague.ini . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 115.3 montague.interfaces . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 125.4 montague.loadwsgi . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12
6 Contributing 156.1 Bug reports . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 156.2 Documentation improvements . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 156.3 Feature requests and feedback . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 156.4 Development . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15
7 Authors 17
8 Changelog 198.1 0.2.1 (2015-06-17) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 198.2 0.2.0 (2015-06-14) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 198.3 0.1.5 (2015-05-12) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 198.4 0.1.0 (2014-11-12) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 20
9 Indices and tables 21
Python Module Index 23
i
ii
Montague, Release 0.2.1
Contents:
Contents 1
Montague, Release 0.2.1
2 Contents
CHAPTER 1
Overview
1.1 Montague
Montague provides functions to load WSGI apps and servers based on configuration files.
• Free software: MIT license
1.1.1 Status
Montague is a pre-1.0 project using Semantic Versioning.
1.1.2 Installation
pip install montague
1.1.3 Documentation
https://montague.readthedocs.org/
1.1.4 Development
To run the all tests run:
tox
3
Montague, Release 0.2.1
4 Chapter 1. Overview
CHAPTER 2
Installation
At the command line:
pip install montague
5
Montague, Release 0.2.1
6 Chapter 2. Installation
CHAPTER 3
Usage
To use Montague in a project:
import montague
7
Montague, Release 0.2.1
8 Chapter 3. Usage
CHAPTER 4
Writing your own config loader
Do you want to store your WSGI app config in Redis? In a TOML file? In ZooKeeper? You can do that.
You will need to decide two things:
1. A filename extension for your configuration format: for actual files, that’s easy. A JSON loader should work withfoo.json files. However, if you are loading your configuration from a service, you still need to pick a filenameextension; Montague uses that to dispatch to config loaders. Perhaps you will store the Redis connection info inmyfile.redis, or perhaps the file doesn’t even exist and you extract the connection info from the path name.
2. Whether you need to support individual app_config, server_config, etc methods: the default INI loadersupports these because the PasteDeploy INI format allows individual app configs to override global variablesfor that specific app.
Config loaders must provide the methods listed in the montague.interfaces.IConfigLoader interface; it’srecommended, though not required, that they actually implement the interface using zope.interface.
4.1 Montague Standard Format
The actual layout of your configuration information will obviously vary from format to for-mat. Because of this, Montague has a standard layout you should use when implementing themontague.interfaces.IConfigLoader.config() method. You should return a dict that looks likethis:
{"globals": {},"application": {},"composite": {},"filter": {},"server": {},"logging": {},
}
Of course, the dict can contain other keys as well, but those are the ones Montague cares about.
9
Montague, Release 0.2.1
10 Chapter 4. Writing your own config loader
CHAPTER 5
Reference
5.1 montague
5.2 montague.ini
class montague.ini.IniConfigLoader(path)This config loader transforms a traditional INI file into a Montague Standard Format dictionary. It is compatiblewith most but not all PasteDeploy files.
__eq__(other)Automatically created by characteristic.
__ge__(other)Automatically created by characteristic.
__gt__(other)Automatically created by characteristic.
__hash__()Automatically created by characteristic.
__le__(other)Automatically created by characteristic.
__lt__(other)Automatically created by characteristic.
__ne__(other)Automatically created by characteristic.
__repr__()Automatically created by characteristic.
__setattr__(attr, value)Immutability sentry automatically created by characteristic.
If an attribute is attempted to be set from any other place than an initializer, a TypeError is raised. Else theoriginal __setattr__ is called.
app_config(name)
characteristic_attributes = [<Attribute(name=’path’, exclude_from_cmp=False, exclude_from_init=False, exclude_from_repr=False, exclude_from_immutable=False, default_value=NOTHING, default_factory=None, instance_of=None, init_aliaser=None)>]
config()
filter_config(name)
11
Montague, Release 0.2.1
logging_config(name)
server_config(name)
5.3 montague.interfaces
interface montague.interfaces.IConfigLoaderA config loader for a given config format. You do not have to implement app_config/server_config/filter_config.They must still be present, but can simply return NotImplementedError. In that case, Montague will extract theconfig from the config().
logging_config(name)Provides a dict suitable for passing to logging.config.dictConfig. It’s possible a config loader may onlysupport a single logging config, which would be available under DEFAULT.
filter_config(name)Return the config for the specified filter. If name is montague.structs.DEFAULT, use the default name forthe config format (such as ‘main’).
server_config(name)Return the config for the specified server. If name is montague.structs.DEFAULT, use the default name forthe config format (such as ‘main’).
app_config(name)Return the config for the specified app. If name is montague.structs.DEFAULT, use the default name forthe config format (such as ‘main’).
pathLocation of config data. Usually will be a filesystem path, but may be a URL, redis connection string, etc.
config()Returns the entire config as a dict in Montague standard format. Montague standard format has the follow-ing keys (all optional): global, application, composite, filter, server. Other than global, these keys shouldthen contain name, config value pairs. Use DEFAULT for the default app/filter/server.
5.4 montague.loadwsgi
class montague.loadwsgi.CompositeHelper(loader)
get_app(name=’main’, global_conf=None)
class montague.loadwsgi.Loader(path)
__eq__(other)Automatically created by characteristic.
__ge__(other)Automatically created by characteristic.
__gt__(other)Automatically created by characteristic.
__hash__()Automatically created by characteristic.
12 Chapter 5. Reference
Montague, Release 0.2.1
__le__(other)Automatically created by characteristic.
__lt__(other)Automatically created by characteristic.
__ne__(other)Automatically created by characteristic.
__repr__()Automatically created by characteristic.
__setattr__(attr, value)Immutability sentry automatically created by characteristic.
If an attribute is attempted to be set from any other place than an initializer, a TypeError is raised. Else theoriginal __setattr__ is called.
app_config(name=None)
characteristic_attributes = [<Attribute(name=’path’, exclude_from_cmp=False, exclude_from_init=False, exclude_from_repr=False, exclude_from_immutable=False, default_value=NOTHING, default_factory=None, instance_of=None, init_aliaser=None)>]
config
filter_config(name=None)
load_app(name=None)
load_filter(name=None)
load_server(name=None)
logging_config(name=None)
server_config(name=None)
montague.loadwsgi.lookup_object(spec)Looks up a module or object from a some.module:func_name specification. To just look up a module, omit thecolon and everything after it.
5.4. montague.loadwsgi 13
Montague, Release 0.2.1
14 Chapter 5. Reference
CHAPTER 6
Contributing
Contributions are welcome, and they are greatly appreciated! Every little bit helps, and credit will always be given.
6.1 Bug reports
When reporting a bug please include:
• Your operating system name and version.
• Any details about your local setup that might be helpful in troubleshooting.
• Detailed steps to reproduce the bug.
6.2 Documentation improvements
Montague could always use more documentation, whether as part of the official Montague docs, in docstrings, or evenon the web in blog posts, articles, and such.
6.3 Feature requests and feedback
The best way to send feedback is to file an issue at https://github.com/inklesspen/montague/issues.
If you are proposing a feature:
• Explain in detail how it would work.
• Keep the scope as narrow as possible, to make it easier to implement.
• Remember that this is a volunteer-driven project, and that contributions are welcome :)
6.4 Development
To set up montague for local development:
1. Fork montague on GitHub.
2. Clone your fork locally:
15
Montague, Release 0.2.1
git clone [email protected]:your_name_here/montague.git
3. Create a branch for local development:
git checkout -b name-of-your-bugfix-or-feature
Now you can make your changes locally.
4. When you’re done making changes, run all the checks, doc builder and spell checker with tox one command:
tox
5. Commit your changes and push your branch to GitHub:
git add .git commit -m "Your detailed description of your changes."git push origin name-of-your-bugfix-or-feature
6. Submit a pull request through the GitHub website.
6.4.1 Pull Request Guidelines
If you need some code review or feedback while you’re developing the code just make the pull request.
For merging, you should:
1. Include passing tests (run tox) 1.
2. Update documentation when there’s new API, functionality etc.
3. Add a note to CHANGELOG.rst about the changes.
4. Add yourself to AUTHORS.rst.
6.4.2 Tips
To run a subset of tests:
tox -e envname -- py.test -k test_myfeature
To run all the test environments in parallel (you need to pip install detox):
detox
1 If you don’t have all the necessary python versions available locally you can rely on Travis - it will run the tests for each change you add in thepull request.
It will be slower though ...
16 Chapter 6. Contributing
CHAPTER 7
Authors
• Jon Rosebaugh - http://inklesspen.com
Based upon PasteDeploy 1.5.2 by Ian Bicking.
17
Montague, Release 0.2.1
18 Chapter 7. Authors
CHAPTER 8
Changelog
8.1 0.2.1 (2015-06-17)
• Removed zope.interface requirement, since the interfaces themselves were removed in 0.2.0.
• Removed useless console_script entry point.
• Changed loader detection to only consider the final extension in a filename.
• Support and test egg specifications with no named entry point (because it’s ‘main’).
• Support basic interpolation (here and __file__) in the built-in INI loader.
8.2 0.2.0 (2015-06-14)
• Remove the PasteDeploy FakeApp package in favor of montague_testapps.
• Enable a looponfail tox environment.
• Add logging ini conversion
• Reincorporate the test JSON config loader, active only during tests.
• Remove the DEFAULT sentinal value; we’ll use ‘main’ as the default loadable name, just like grandpa used todo. This is a breaking change.
• Add logging config to the Montague Standard Format.
• Allow config loaders to skip implementing app_config() and the like, instead of raisingNotImplementedError
• Add validation functions to let config loaders test their compliance. These functions use assert statements,making them ideal for py.test, but they should work under unittest as well.
8.3 0.1.5 (2015-05-12)
• The legacy PasteDeploy support was spun off into a separate package (montague_pastedeploy), enablingsimplicity.
19
Montague, Release 0.2.1
8.4 0.1.0 (2014-11-12)
• First release on PyPI, corresponding to PasteDeploy 1.5.2.
• Backwards incompatibility: ConfigMiddleware stores the config under montague.config in the environ-ment instead of paste.config and no longer offers a threadlocal CONFIG importable. (This removes thedependency on Paste.)
20 Chapter 8. Changelog
CHAPTER 9
Indices and tables
• genindex
• modindex
• search
21
Montague, Release 0.2.1
22 Chapter 9. Indices and tables
Python Module Index
mmontague, 11montague.ini, 11montague.interfaces, 12montague.loadwsgi, 12
23
Montague, Release 0.2.1
24 Python Module Index
Index
Symbols__eq__() (montague.ini.IniConfigLoader method), 11__eq__() (montague.loadwsgi.Loader method), 12__ge__() (montague.ini.IniConfigLoader method), 11__ge__() (montague.loadwsgi.Loader method), 12__gt__() (montague.ini.IniConfigLoader method), 11__gt__() (montague.loadwsgi.Loader method), 12__hash__() (montague.ini.IniConfigLoader method), 11__hash__() (montague.loadwsgi.Loader method), 12__le__() (montague.ini.IniConfigLoader method), 11__le__() (montague.loadwsgi.Loader method), 12__lt__() (montague.ini.IniConfigLoader method), 11__lt__() (montague.loadwsgi.Loader method), 13__ne__() (montague.ini.IniConfigLoader method), 11__ne__() (montague.loadwsgi.Loader method), 13__repr__() (montague.ini.IniConfigLoader method), 11__repr__() (montague.loadwsgi.Loader method), 13__setattr__() (montague.ini.IniConfigLoader method), 11__setattr__() (montague.loadwsgi.Loader method), 13
Aapp_config() (montague.ini.IniConfigLoader method), 11app_config() (montague.interfaces.IConfigLoader
method), 12app_config() (montague.loadwsgi.Loader method), 13
Ccharacteristic_attributes (montague.ini.IniConfigLoader
attribute), 11characteristic_attributes (montague.loadwsgi.Loader at-
tribute), 13CompositeHelper (class in montague.loadwsgi), 12config (montague.loadwsgi.Loader attribute), 13config() (montague.ini.IniConfigLoader method), 11config() (montague.interfaces.IConfigLoader method), 12
Ffilter_config() (montague.ini.IniConfigLoader method),
11
filter_config() (montague.interfaces.IConfigLoadermethod), 12
filter_config() (montague.loadwsgi.Loader method), 13
Gget_app() (montague.loadwsgi.CompositeHelper
method), 12
IIConfigLoader (interface in montague.interfaces), 12IniConfigLoader (class in montague.ini), 11
Lload_app() (montague.loadwsgi.Loader method), 13load_filter() (montague.loadwsgi.Loader method), 13load_server() (montague.loadwsgi.Loader method), 13Loader (class in montague.loadwsgi), 12logging_config() (montague.ini.IniConfigLoader
method), 12logging_config() (montague.interfaces.IConfigLoader
method), 12logging_config() (montague.loadwsgi.Loader method),
13lookup_object() (in module montague.loadwsgi), 13
Mmontague (module), 11montague.ini (module), 11montague.interfaces (module), 12montague.loadwsgi (module), 12
Ppath (montague.interfaces.IConfigLoader attribute), 12
Sserver_config() (montague.ini.IniConfigLoader method),
12server_config() (montague.interfaces.IConfigLoader
method), 12server_config() (montague.loadwsgi.Loader method), 13
25