Call django.setup() for Sphinx, too.

This also adds a configurations.setup() analogue to django.setup().
This commit is contained in:
Jannis Leidel 2015-02-13 22:18:33 +01:00
parent b91ebf083f
commit 4d35ad346c
2 changed files with 19 additions and 13 deletions

View file

@ -6,10 +6,7 @@ __version__ = '0.8'
__all__ = ['Configuration', 'pristinemethod', 'Settings']
def load_ipython_extension(ipython):
# The `ipython` argument is the currently active `InteractiveShell`
# instance, which can be used in any way. This allows you to register
# new magics or aliases, for example.
def _setup():
from . import importer
importer.install()
@ -22,12 +19,20 @@ def load_ipython_extension(ipython):
pass
def setup(app):
def load_ipython_extension(ipython):
"""
The `ipython` argument is the currently active `InteractiveShell`
instance, which can be used in any way. This allows you to register
new magics or aliases, for example.
"""
_setup()
def setup(app=None):
"""
The callback for Sphinx that acts as a Sphinx extension.
Add this to the ``extensions`` config variable in your ``conf.py``.
Add ``'configurations'`` to the ``extensions`` config variable
in your docs' ``conf.py``.
"""
from . import importer
importer.install()
_setup()

View file

@ -125,10 +125,11 @@ probably just add the following to the **beginning** of your settings module:
.. code-block:: python
from configurations import importer
importer.install()
import configurations
configurations.setup()
That has the same effect as using the ``manage.py`` or ``wsgi.py`` utilities.
This will also call ``django.setup()`` on Django >= 1.7.
>= 3.1
^^^^^^
@ -154,8 +155,8 @@ Celery's documentation`_:
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'mysite.settings')
os.environ.setdefault('DJANGO_CONFIGURATION', 'MySiteConfiguration')
from configurations import importer
importer.install()
import configurations
configurations.setup()
app = Celery('mysite')
app.config_from_object('django.conf:settings')