When you develop a web application it’s a good idae to use standard
Python project organization practices. Organizing your Project
describes some recommendations on how to do this with
Morepath. Relevant in particular is the contents of setup.py,
which depends on Morepath and also sets up an entry point to start the
web server.

Once you have a project you can use tools like pip or
buildout. We’ll briefly describe how to use both.

The develop line tells which directories to look in for Python
projects (with a setup.py). In this case only the local project
directory . is one. But if you also have the checkout of another
project that you depend on (maybe a development version of Morepath
itself), you can add that directory to the develop section.

mr.developer

If you are going to develop such a multi-project codebase you should
consider the buildout extension mr.developer which can help you
automate this.

parts tells buildout what to configure; they are described in
the [scripts] and [devpython] sections later.

The line versions=versions tells buildout to lock down version
numbers according to the [versions]
section.

show-picked-versions

You can add a line show-picked-versions=true to the
[buildout] section. When you now run bin/buildout this dumps
all versions of libraries you use directly or indirectly that you
haven’t locked down to an explicit version to the console. You can
then lock them down in the [versions] section.

Locking down versions is useful if you want to make sure everybody
has the same versions of the libraries in development.

The [scripts] section installs your web application as a script in
the bin subdirectory of your project, according to the
console_scripts entry point in your project’s setup.py. If
it’s called myproject-start, then you can start it like this:

bin/myproject-start

This will start a HTTP server for your project.

The buildout also has installed pytest so you can run your
project’s tests automatically:

bin/py.test myproject

(if your Python package is in myproject)

Test dependencies

If you want to add some extra dependencies just for testing, you can
do this in your project’s setup.py by adding:

extras_require=dict(test=['pytest >= 2.5','pytest-cov'],),

This makes sure we have a pytest version 2.5 or later, and we
install the pytest-cov code coverage extension.

You can then modify the [scripts] section in buildout.cfg to
use the extra test requirements:

Now as to some optional extras. The [devpython] section installs a
Python interpreter which can import exactly what your project can
import. It assumes your project is called myproject in its
setup.py; change the name to match your project. You can start it
using:

$ bin/devpython

You’ll get the usual Python console >>>. This is useful for
testing your project’s imports and API manually.

It also installs the flake8 tool which runs pep 8 checks and pyflakes
automatically. You can run it against your project by writing:

If you like being on the cutting edge and want to depend on the latest
Morepath and Reg development versions always, we recommend you use
buildout with the mr.developer extension for your project. You can see
how in this buildout.cfg.