lightweight way to create new projects from templates

Jonathan Hartley tartley at tartley.com
Wed May 11 14:34:32 EDT 2011


Hi.

I'm looking for a quick way to create new Python projects from a template.

I understand that 'Paste' (http://pythonpaste.org/) is one way to do 
this, but I find Paste very intimidating because of all the 
functionality it includes. I'm not even sure whether 'creating new 
projects from templates' is the central goal of Paste, or just an 
incidental benefit that it provides while performing some other task.

As a lightweight alternative, I'm creating a project called 'Genesis'. 
Functionally, it will be little more than a 'cp -r' followed by a few 
search and replace operations.


I realise this idea is modest, but I think it could be helpful for:

a) people who are just getting started with Python, and want to see how 
best to structure their projects, and

b) people who are already up-to-speed, and who want to create their own 
templates and spawn projects from them with a minimum of effort.

c) for the community, to exemplify and publicise best practices for new 
projects.


My goals include:

* Create a new project using the default template:

     $ genesis myproj

* or using a particular project template:

     $ genesis --template=mytemplate myproj

* Allow people to create their own templates, simply stored as 
directories under '~/.genesis'

* Files in a template contain 'tags' of the form 'G{author}'. When a new 
project is created, these tags are replaced. For example, G{author} will 
be replaced with the value for 'author' supplied either on the command-line:

     $ genesis myproj author=Jonathan

Or in your ~/.genesis/config file (a python file read using 'exec'):

     author = 'Jonathan'

* The default template should embody good practices like those 
demonstrated in the Python Project howto:
http://infinitemonkeycorps.net/docs/pph/

* The default template should include a setup.py, supporting sdist, 
register and upload commands.

* I'd also like the default template to include things like creating 
Windows binaries, so that it is easier for projects to include this out 
of the box. It would be nice to extend this to binaries for other 
platforms too.

* The default template for command-line applications should include an 
acceptance test, which invokes the script in a new process and makes 
assertions about stdout, stderr and exit value.

* One of my inspirations is to create a good template for events like 
pyweek, where many people set out to write opengl or pyglet applications 
from scratch, and yet every time, many entrants fail to properly create 
binaries, etc.


Genesis is only partially written, so is not yet on PyPI, but is on 
bitbucket:
https://bitbucket.org/tartley/genesis/overview

If you have any feedback, it would be very welcome. In particular:

What do you think about the approach in general?

What do you think about the contents of my default template:
https://bitbucket.org/tartley/genesis/src/tip/genesis/config/default/

Do you think a single default template containing all the above ideas is 
viable? Or is it likely to be so idiosyncratic that I might be better 
shipping with several built-in templates, including a 'minimal' one? Do 
I need different templates for applications than for libraries? For 
console apps vs GUI apps?

What do you think of my choice of 'G{name}' for replaceable tags in the 
template? I wanted something that would not be valid Python, and would 
be unlikely to occur naturally in a project.

Best regards,

     Jonathan

-- 
Jonathan Hartley    tartley at tartley.com    http://tartley.com
Made of meat.       +44 7737 062 225       twitter/skype: tartley




More information about the Python-list mailing list