Here is a general overview of what I do. This is by no means a prescription for success, but merely a slightly more generic way of how we lay out CP projects at my job that I have used on personal projects as well.
I should start by saying that we distribute our apps for deployment as eggs. If you're unfamiliar with eggs, then I'd take a look at setuptools, pip and virtualenv (google!) to see what that is about.
For example's sake, we'll call this project "Jack". Here is how I typically layout my package:
# $home/projects/Jack
setup.py
jack/
control/
view/
static/
static/css/
static/js/
etc/
lib/
testing/
tests/unit
tests/func
scripts/
bin/
The control dir is for my main CP handler classes. I typically will create base classes in control/__init__.py that set up things like templating and returning common formats such as JSON (there is a tool for this as well). The control dir typically also has a "root.py" which is where the actual cherrypy configuration ends up. This is where we would include the configuration details like the host, port, setup static resources, etc. Often times I fit most my controller objects in one file called main.py in control dir, but sometimes I use different files for things like API handlers vs. traditional web pages.
The view directory is where I put template files. Personally, I use Mako, but use whatever works for you (if you even need it). I usually try to organize it similarly to the structure of the app. For example, if I had a URL like foo/bar/, there might be a foo and bar directory in the view directory for those templates.
The static directory is for static resources. I typically have a js and css directory to keep things separated.
The etc directory is for configuration details. As a package I like to have a base configuration that is helpful for development that gets overridden in production. There is usually a "startup.py" file as well that helps to set up things like database connection pools. Basically it acts as a place to put bootstrapping needs.
The lib directory is where I keep most of the actual application classes. Usually I'll create a store.py file that has general database connection details. Sometimes that will involve a "model" directory with specific models defined as .py files. Typically if there is specific functionality the application can implement as a library of sorts it will get its own directory under lib but at the very least it has its own file. For example if "Jack" project does some audio processing, you might have a lib/audio/downsample.py.
The testing directory is for helpers used in testing. These could mocks, test runners, stubs, base classes used in testing, etc.
The test directory is where I keep the tests. Some people like to have a test directory for each directory in the package such that things are mirrored directly (ie lib/foo/bar.py and lib/foo/test/test_bar.py). Personally, I like having all the tests in one place, but that is just me. For running tests, I use py.test (http://pytest.org) but others might have other suggestions such as nose or unittest2.
The scripts directory is for project specific scripts. These could be shell scripts for running tests or python scripts for loading test data or helpers for building a release. Anything really.
The bin directory is for putting scripts that will end up in the python bin directory. Again, this is a setuptools feature where in your setup.py you can define console scripts that can be called from the command line. A simple example would be if you had a simple script that started up your server.
All of this is considered part of the "package" that in our case is an setuptools package. This lets us build eggs for deployment. If you do something similar be sure to consider things like package data and console scripts when writing your setup.py otherwise you might find that certain files are not present when you run the application.
Again, this is just an example of what I've been doing. It is also worthwhile to see what the larger frameworks are doing. Most can scaffold a directory structure that might be helpful to emulate if it makes sense.
Hope that helps!
Eric
> --
> You received this message because you are subscribed to the Google Groups "cherrypy-users" group.
> To post to this group, send email to cherryp...@googlegroups.com.
> To unsubscribe from this group, send email to cherrypy-user...@googlegroups.com.
> For more options, visit this group at http://groups.google.com/group/cherrypy-users?hl=en.
>
--
Eric Larson
Great example app Sylvain! The templates as an engine plugin is a really helpful example.
I'm not the OP, but there's a lot of good stuff in both of these
examples. Thanks!
Sylvain,
> You may also be interested
> in a snippet I've setup a while ago:
>
> https://bitbucket.org/Lawouach/twiseless/src
That was a very helpful example to get me started. I copied your
template plugin and tool and modified it slightly to use Jinja2
instead.
However I have found it not to be working. Reason: any dict() returned
by an exposed function is converted to a list() before it reaches the
template tool. What converts a dict() to a list() is the
lib.encoding.ResponseEncoder.encode_string() method that runs on
behalf of ResponseEncoder.find_acceptable_charset().
Any idea how to fix your template tool so that it does get a dict()
instead of a list() to work with?
--
Guido Kollerie
Any idea how to fix your template tool so that it does get a dict()
instead of a list() to work with?
PS : when I talk about the code you gave us as an example for Mako integration I talk about this file: https://bitbucket.org/Lawouach/twiseless/src/d171fde9e454/lib/tool/template.py
> --
> You received this message because you are subscribed to the Google Groups
> "cherrypy-users" group.
> To view this discussion on the web visit
> https://groups.google.com/d/msg/cherrypy-users/-/XYQpKPLLVkwJ.
> To post to this group, send email to cherryp...@googlegroups.com.
> To unsubscribe from this group, send email to
> cherrypy-user...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/cherrypy-users?hl=en.
>
--
EuGeNe -- follow me http://twitter.com/3kwa