How to start a new python package

From Jonathan Gardner's Tech Wiki
Jump to: navigation, search

Introduction

This details how to start a new Python package using my favorite tools: virtualenv and git.

Virtualenv

On Fedora systems, be sure you have python-virtualenv installed. This will allow you to keep your Python packages separate for separate projects.

$ sudo yum -y install python-virtualenv

Now, use it to create your new environment.

$ mkdir ~/Projects
$ cd ~/Projects
$ virtualenv --no-site-packages yourproj

Once you have it working, activate the environment:

$ . ~/Projects/yourproj/bin/activate

You'll need to do this every time you start a new shell. You can tell you are in the right environment when your shell starts with (yourproj).

Paster

Paster is a wonderful tool that helps you manage packages. Install it right away.

$ easy_install PasteScript

This should install the 'paster' command.

Package

Now create the package.

$ paster create YourProj

It will ask you a bunch of questions, but it's easy enough to change the answers later so don't sweat it.

Git Init

$ cd ~/Projects/yourproj/YourProj
$ git init
$ cat >> .gitignore
*.pyc
build
install
setup.cfg
<CTRL-d>
$ git add yourproj setup.py YourProj.egg-info .gitignore
$ git commit -m "Initial"