From 4d35ad346cfc52c05f8a1a44c504d07597f8d452 Mon Sep 17 00:00:00 2001 From: Jannis Leidel Date: Fri, 13 Feb 2015 22:18:33 +0100 Subject: [PATCH] Call django.setup() for Sphinx, too. This also adds a configurations.setup() analogue to django.setup(). --- configurations/__init__.py | 23 ++++++++++++++--------- docs/cookbook.rst | 9 +++++---- 2 files changed, 19 insertions(+), 13 deletions(-) diff --git a/configurations/__init__.py b/configurations/__init__.py index 8299483..ee7aeeb 100644 --- a/configurations/__init__.py +++ b/configurations/__init__.py @@ -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() diff --git a/docs/cookbook.rst b/docs/cookbook.rst index 0cb5d54..02bef1e 100644 --- a/docs/cookbook.rst +++ b/docs/cookbook.rst @@ -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')