Browse files

Try to load an app by name when mounts are empty

If a config file does not specify a mounts dictionary, greins will now
try to load the application by looking for a module whose name matches
the config file's name and looking for a symbol within called
'application' that is a callable WSGI handler.

This change means that developers can use this naming convention to
seamlessly import apps into greins without changing any files.
  • Loading branch information...
1 parent dbdbe01 commit 3d9dd6f78b37c429dcfc20d79c4f4a5bfad4f43f Randall Leeds committed Oct 11, 2011
Showing with 14 additions and 2 deletions.
  1. +8 −2 README.rst
  2. +6 −0 greins/
10 README.rst
@@ -54,9 +54,15 @@ are valid in these configuration files and work as in Gunicorn_. Other options,
such as logging and worker configuration, are ignored and should be configured
globally for the Greins application.
+As a convenience, a file name ``myapp`` which does not define any ``mounts``
+will try to import ``myapp:application`` and mount it underneath the path
It should be possible to write an application for Gunicorn_ and then place
-the application's configuration inside the configuration directory for Greins
-to begin using it within Greins immediately.
+a Gunicorn_ configuration file inside the configuration directory for Greins
+to begin using it within Greins immediately, provided that the config file name
+matches a module in the python path which exports ``application`` as a WSGI_
6 greins/
@@ -8,6 +8,7 @@
from import WSGIApplication
from gunicorn.config import make_settings
+from gunicorn.util import import_app
from greins.reloader import Reloader
from greins.router import Router
@@ -88,6 +89,11 @@ def load_file(self, cf):"Loading configuration for %s" % cf_name)
execfile(cf, cfg, cfg)
+ # By default, try to mount the application by name
+ if not cfg['mounts']:
+ app_name, ext = os.path.splitext(os.path.basename(cf))
+ cfg['mounts'][app_name] = import_app(app_name)
# Load all the mount points
for r, a in cfg['mounts'].iteritems():
# Capture the handler in a closure

0 comments on commit 3d9dd6f

Please sign in to comment.