[skeleton] Add an entry point and configuration for running a Pyramid application
We add a `pyramid_main` function in __init__.py that instantiate the WSGI
application using "cubicweb.pyramid"; this is defined as an entry point (in
setup.py) so that pserve_ can find it.
Alongside comes a development.ini file which includes basic settings so that
running a Pyramid+CubicWeb application works (only the "instance=<appid>" may
be passed as a command-line argument). Logging is also configured there, but
only includes the cube at stake and cubicweb (others could be added if
needed).
.. _perse: \
http://docs.pylonsproject.org/projects/pyramid/en/1.8-branch/pscripts/pserve.html
--- a/cubicweb/devtools/test/unittest_devctl.py Fri Jan 27 09:58:30 2017 +0100
+++ b/cubicweb/devtools/test/unittest_devctl.py Fri Jan 27 11:05:07 2017 +0100
@@ -47,7 +47,7 @@
expected_project_content = ['setup.py', 'test', 'MANIFEST.in',
'cubicweb_foo',
'cubicweb-foo.spec', 'debian', 'README',
- 'tox.ini']
+ 'tox.ini', 'development.ini']
expected_package_content = ['i18n', 'hooks.py', 'views.py',
'migration', 'entities.py', 'schema.py',
'__init__.py', 'data', '__pkginfo__.py']
--- a/cubicweb/skeleton/MANIFEST.in.tmpl Fri Jan 27 09:58:30 2017 +0100
+++ b/cubicweb/skeleton/MANIFEST.in.tmpl Fri Jan 27 11:05:07 2017 +0100
@@ -5,6 +5,6 @@
recursive-include cubicweb_%(cubename)s/i18n *.po
recursive-include cubicweb_%(cubename)s/wdoc *
recursive-include test/data bootstrap_cubes *.py
-include tox.ini
+include *.ini
recursive-include debian changelog compat control copyright rules
include cubicweb-%(cubename)s.spec
--- a/cubicweb/skeleton/cubicweb_CUBENAME/__init__.py.tmpl Fri Jan 27 09:58:30 2017 +0100
+++ b/cubicweb/skeleton/cubicweb_CUBENAME/__init__.py.tmpl Fri Jan 27 11:05:07 2017 +0100
@@ -2,3 +2,12 @@
%(longdesc)s
"""
+
+
+def pyramid_main(global_config, **settings):
+ """Return a Pyramid WSGI application bound to a CubicWeb repository."""
+ from pyramid.config import Configurator
+ config = Configurator(settings=settings)
+ config.include('cubicweb.pyramid')
+ config.scan()
+ return config.make_wsgi_app()
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/cubicweb/skeleton/development.ini.tmpl Fri Jan 27 11:05:07 2017 +0100
@@ -0,0 +1,76 @@
+###
+# app configuration
+# http://docs.pylonsproject.org/projects/pyramid/en/latest/narr/environment.html
+###
+
+[app:main]
+use = egg:%(distname)s
+
+pyramid.reload_templates = true
+pyramid.debug_authorization = false
+pyramid.debug_notfound = false
+pyramid.debug_routematch = false
+pyramid.default_locale_name = en
+pyramid.includes =
+ pyramid_debugtoolbar
+
+# By default, the toolbar only appears for clients from IP addresses
+# '127.0.0.1' and '::1'.
+# debugtoolbar.hosts = 127.0.0.1 ::1
+
+##
+# CubicWeb instance settings
+# http://cubicweb.readthedocs.io/en/latest/book/pyramid/settings/
+##
+cubicweb.instance = %%(instance)s
+cubicweb.bwcompat = True
+cubicweb.debug = True
+# cubicweb.auth.authtkt.persistent.secret =
+cubicweb.auth.authtkt.persistent.secure = False
+# cubicweb.auth.authtkt.session.secret =
+cubicweb.auth.authtkt.session.secure = False
+
+###
+# wsgi server configuration
+###
+
+[server:main]
+use = egg:waitress#main
+listen = 127.0.0.1:6543 [::1]:6543
+
+###
+# logging configuration
+# http://docs.pylonsproject.org/projects/pyramid/en/latest/narr/logging.html
+###
+
+[loggers]
+keys = root, cubicweb_%(cubename)s, cubicweb
+
+[handlers]
+keys = console
+
+[formatters]
+keys = generic
+
+[logger_root]
+level = INFO
+handlers = console
+
+[logger_cubicweb]
+level = INFO
+handlers = console
+qualname = cubicweb
+
+[logger_cubicweb_%(cubename)s]
+level = DEBUG
+handlers = console
+qualname = cubicweb_%(cubename)s
+
+[handler_console]
+class = StreamHandler
+args = (sys.stderr,)
+level = NOTSET
+formatter = generic
+
+[formatter_generic]
+format = %%(asctime)s %%(levelname)-5.5s [%%(name)s:%%(lineno)s][%%(threadName)s] %%(message)s
--- a/cubicweb/skeleton/setup.py.tmpl Fri Jan 27 09:58:30 2017 +0100
+++ b/cubicweb/skeleton/setup.py.tmpl Fri Jan 27 11:05:07 2017 +0100
@@ -77,6 +77,9 @@
'cubicweb.cubes': [
'%(cubename)s=cubicweb_%(cubename)s',
],
+ 'paste.app_factory': [
+ 'main=cubicweb_%(cubename)s:pyramid_main',
+ ],
},
zip_safe=False,
)
--- a/doc/book/pyramid/quickstart.rst Fri Jan 27 09:58:30 2017 +0100
+++ b/doc/book/pyramid/quickstart.rst Fri Jan 27 11:05:07 2017 +0100
@@ -57,3 +57,17 @@
- Configure the base-url and https-url in all-in-one.conf to match the ones
of the pyramid configuration (this is a temporary limitation).
+
+
+Usage with pserve
+-----------------
+
+To run a Pyramid application using pserve_:
+
+::
+
+ pserve /path/to/development.ini instance=<appid>
+
+
+.. _pserve: \
+ http://docs.pylonsproject.org/projects/pyramid/en/latest/pscripts/pserve.html