ABirnberg
ABirnberg

Reputation: 129

Is is possible to run a pyramid application without installing it as an egg?

I am building an application using the Pyramid web framework and in all of the documentation it assumes that you will be installing your application as an egg using setup.py. While this makes sense for a distributable package, it adds a lot of overhead and unnecessary packaging code for an application that isn't meant to be shared as a library or extension.

Pyramid uses PasteDeploy to read application configuration files (.ini) and requires a section to define which application is to be run:

[app:blog]
use = egg:MyBlog#main
database = mysql://localhost/blogdb
blogname = This Is My Blog!

This tells the app loader to import a library called MyBlog found on the PYTHONPATH and use an entry point named main that has been defined in a setup.py configuration.

Is there any way to directly refer to the application by path and specify the WSGI entry point (similar to how you would run an application directly via:

cd /path/to/MyBlog
gunicorn --bind etc... app:main

There is an additional syntax starting with call: that allows you specify an entry point that hasn't been registered with setuptools:

[app:mythirdapp]
use = call:my.project:myapplication

However, it appears that the loader still expects a package installed on the python path rather than a bare python package/executable.

Upvotes: 2

Views: 601

Answers (2)

enkidulan
enkidulan

Reputation: 42

Is it possible to run a pyramid application without installing it as an egg?

Yes, it is, you can find a lot of examples on https://trypyramid.com/ site. You are not obliged to use ini-style declaration for runnig your WSGI application. For example you can create myapp_wsgi.py file:

from pyramid.paster import get_app, setup_logging
ini_path = 'production.ini'
setup_logging(ini_path)
application = get_app(ini_path, 'main')

And pass it to gunicorn:

gunicorn myapp_wsgi:application

You can find more information on modwsgi and gunicorn. pages.

Upvotes: 1

ABirnberg
ABirnberg

Reputation: 129

I actually think the call: method is able to find a package that hasn't been installed using setuptools. This is due to the fact that the python path starts in the current directory, so if you launch your app from the directory containing it, then everything should work as expected.

Problems arise when you want to compose apps using the [composite:] directive. It would be nice if [app:] sections could include a directory = ... parameter that would add that directory to the python path, but I guess this is more of a feature request to raise with the PasteDeploy developers...

Upvotes: 0

Related Questions