From 9fb0d9669c3a66857ee09c9dbe82607295009ad7 Mon Sep 17 00:00:00 2001 From: benoitc Date: Wed, 7 Nov 2012 09:52:49 +0100 Subject: [PATCH] expose --pythonpath command to all modes . fix #433 --pythonpath may also be useful in other commands, so expose it to all. --- docs/source/settings.rst | 3 +++ gunicorn/app/base.py | 8 ++++++++ gunicorn/app/djangoapp.py | 8 +++++--- gunicorn/config.py | 4 ++-- 4 files changed, 18 insertions(+), 5 deletions(-) diff --git a/docs/source/settings.rst b/docs/source/settings.rst index e0b16424..66dfebd6 100644 --- a/docs/source/settings.rst +++ b/docs/source/settings.rst @@ -482,6 +482,9 @@ The Python path to a Django settings module. e.g. 'myproject.settings.main'. If this isn't provided, the DJANGO_SETTINGS_MODULE environment variable will be used. +Server Mechanics +---------------- + pythonpath ~~~~~~~~~~ diff --git a/gunicorn/app/base.py b/gunicorn/app/base.py index e5d4c996..b980daf5 100644 --- a/gunicorn/app/base.py +++ b/gunicorn/app/base.py @@ -115,6 +115,14 @@ class Application(object): if self.cfg.daemon: util.daemonize() + # set python paths + if self.cfg.pythonpath and self.cfg.pythonpath is not None: + paths = self.cfg.pythonpath.split(",") + for path in paths: + pythonpath = os.path.abspath(self.cfg.pythonpath) + if pythonpath not in sys.path: + sys.path.insert(0, pythonpath) + try: Arbiter(self).run() except RuntimeError as e: diff --git a/gunicorn/app/djangoapp.py b/gunicorn/app/djangoapp.py index 7fe44cff..de403578 100644 --- a/gunicorn/app/djangoapp.py +++ b/gunicorn/app/djangoapp.py @@ -44,9 +44,11 @@ def make_default_env(cfg): os.environ['DJANGO_SETTINGS_MODULE'] = cfg.django_settings if cfg.pythonpath and cfg.pythonpath is not None: - pythonpath = os.path.abspath(cfg.pythonpath) - if pythonpath not in sys.path: - sys.path.insert(0, pythonpath) + paths = cfg.pythonpath.split(",") + for path in paths: + pythonpath = os.path.abspath(cfg.pythonpath) + if pythonpath not in sys.path: + sys.path.insert(0, pythonpath) try: os.environ['DJANGO_SETTINGS_MODULE'] diff --git a/gunicorn/config.py b/gunicorn/config.py index 41f176b0..1901d492 100644 --- a/gunicorn/config.py +++ b/gunicorn/config.py @@ -867,9 +867,9 @@ class DjangoSettings(Setting): DJANGO_SETTINGS_MODULE environment variable will be used. """ -class DjangoPythonPath(Setting): +class PythonPath(Setting): name = "pythonpath" - section = "Django" + section = "Server Mechanics" cli = ["--pythonpath"] meta = "STRING" validator = validate_string