Skip to content

Commit

Permalink
Call django.setup() for Sphinx, too.
Browse files Browse the repository at this point in the history
This also adds a configurations.setup() analogue to django.setup().
  • Loading branch information
jezdez committed Feb 13, 2015
1 parent b91ebf0 commit 4d35ad3
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 13 deletions.
23 changes: 14 additions & 9 deletions configurations/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,7 @@
__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()
Expand All @@ -22,12 +19,20 @@ def load_ipython_extension(ipython):
pass


def setup(app):
def load_ipython_extension(ipython):
"""
The callback for Sphinx that acts as a Sphinx extension.
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()


Add this to the ``extensions`` config variable in your ``conf.py``.
def setup(app=None):
"""
from . import importer
The callback for Sphinx that acts as a Sphinx extension.
importer.install()
Add ``'configurations'`` to the ``extensions`` config variable
in your docs' ``conf.py``.
"""
_setup()
9 changes: 5 additions & 4 deletions docs/cookbook.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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
^^^^^^
Expand All @@ -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')
Expand Down

0 comments on commit 4d35ad3

Please sign in to comment.