Saturday, October 11, 2008

Creating new python project

How to set up development environment for new python project.

Some of the tools I use:

  • virtualenv - creates self contained python enviroment (you can even ignore systems site-packages). Its usefull for installing new python libraries or eggs that you may not want to install systemwide.
  • paster - (from pastescript)it helps you with crating project skeleton (including and eggs config). If this is wsgi project you can also use it for deploying.
  • nose - my preferred python testing framework. One of its biggest benefits is that it works with existing unittest tests and doctests.
So tipicly for crating new project cli session would look like:

$ cd py.virt/
py.virt$ virtualenv --no-site-packages Foo
py.virt$ cd Foo && source bin/activate
(Foo)$ easy_install nose
Searching for nose
(Foo)$ easy_install pastescript
Searching for pastescript
(Foo)$ paster create Foo
Selected and implied templates:
PasteScript#basic_package A basic setuptools-enabled package

egg: Foo
package: foo
project: Foo
(Foo)$ cd Foo
(Foo)$ python develop # creates registers with python so that ' import Foo works'
running develop
running egg_info
writing Foo.egg-info/PKG-INFO

Now our package should be created and registered with python. Lets see:

(Foo)$ python
Python 2.5.2 (r252:60911, Jul 31 2008, 17:28:52)
[GCC 4.2.3 (Ubuntu 4.2.3-2ubuntu7)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import foo
>>> dir(foo)
['__builtins__', '__doc__', '__file__', '__name__', '__path__']

Now we can start coding.

No comments: