Tuesday, November 06, 2007

Setting-up of Mercurial to track a Pylons project

In order to track the changes in a Pylons project, I will describe here how to do that with the Mercurial Source Control Management system.

First of all, install the Mercurial program on your Ubuntu 7.10:

sudo apt-get install mercurial


Then create a directory for your Pylons projects: for example $HOME/dev/pylons-projects.

mkdir $HOME/dev/pylons-projects


Now you can create a new Pylons project into this directory (for example a project called test_proj):

cd $HOME/dev/pylons-projects
paster create -t pylons test_proj


Here is the print of the last command:

Selected and implied templates:
Pylons#pylons Pylons application template

Variables:
egg: test_proj
package: test_proj
project: test_proj
Creating template pylons
Creating directory ./test_proj
Recursing into +egg+.egg-info
Creating ./test_proj/test_proj.egg-info/
Copying paste_deploy_config.ini_tmpl_tmpl to ./test_proj/test_proj.egg-info/paste_deploy_config.ini_tmpl
Recursing into +package+
Creating ./test_proj/test_proj/
Copying __init__.py_tmpl to ./test_proj/test_proj/__init__.py
Recursing into config
Creating ./test_proj/test_proj/config/
Copying __init__.py_tmpl to ./test_proj/test_proj/config/__init__.py
Copying environment.py_tmpl to ./test_proj/test_proj/config/environment.py
Copying middleware.py_tmpl to ./test_proj/test_proj/config/middleware.py
Copying routing.py_tmpl to ./test_proj/test_proj/config/routing.py
Recursing into controllers
Creating ./test_proj/test_proj/controllers/
Copying __init__.py_tmpl to ./test_proj/test_proj/controllers/__init__.py
Copying error.py_tmpl to ./test_proj/test_proj/controllers/error.py
Copying template.py_tmpl to ./test_proj/test_proj/controllers/template.py
Recursing into lib
Creating ./test_proj/test_proj/lib/
Copying __init__.py_tmpl to ./test_proj/test_proj/lib/__init__.py
Copying app_globals.py_tmpl to ./test_proj/test_proj/lib/app_globals.py
Copying base.py_tmpl to ./test_proj/test_proj/lib/base.py
Copying helpers.py_tmpl to ./test_proj/test_proj/lib/helpers.py
Recursing into model
Creating ./test_proj/test_proj/model/
Copying __init__.py_tmpl to ./test_proj/test_proj/model/__init__.py
Recursing into public
Creating ./test_proj/test_proj/public/
Copying index.html_tmpl to ./test_proj/test_proj/public/index.html
Recursing into templates
Creating ./test_proj/test_proj/templates/
Recursing into tests
Creating ./test_proj/test_proj/tests/
Copying __init__.py_tmpl to ./test_proj/test_proj/tests/__init__.py
Recursing into functional
Creating ./test_proj/test_proj/tests/functional/
Copying __init__.py_tmpl to ./test_proj/test_proj/tests/functional/__init__.py
Copying test_models.py_tmpl to ./test_proj/test_proj/tests/test_models.py
Copying websetup.py_tmpl to ./test_proj/test_proj/websetup.py
Copying MANIFEST.in_tmpl to ./test_proj/MANIFEST.in
Copying README.txt_tmpl to ./test_proj/README.txt
Copying development.ini_tmpl to ./test_proj/development.ini
Recursing into docs
Creating ./test_proj/docs/
Copying index.txt_tmpl to ./test_proj/docs/index.txt
Copying setup.cfg_tmpl to ./test_proj/setup.cfg
Copying setup.py_tmpl to ./test_proj/setup.py
Copying test.ini_tmpl to ./test_proj/test.ini
Running /usr/bin/python setup.py egg_info
Adding Pylons to paster_plugins.txt
Adding WebHelpers to paster_plugins.txt


Let's setup Mercurial configuration file called .hgrc (this step must be done once). This file must be located in your home directory (replace firstname, lastname and example.com by values suitable for you):

echo '[ui]' >> $HOME/.hgrc
echo 'username = Firstname Lastname <firstname.lastname@example.com>' >> $HOME/.hgrc
echo '' >> $HOME/.hgrc
echo '[diff]' >> $HOME/.hgrc
echo 'git = True' >> $HOME/.hgrc
echo 'ignorews = True' >> $HOME/.hgrc
echo 'ignorewsamount = True' >> $HOME/.hgrc
echo 'ignoreblanklines = True' >> $HOME/.hgrc


You are now ready to track your Pylons project thanks to Mercurial.

But as you will discover some files don't need to be tracked. For example Python compiled files that will appear at the first launch of your Pylons project and will be regenerated at each change of your source code.

In order to prevent Mercurial from tracking such files we will setup a .hgignore file in the Pylons project:

cd $HOME/dev/pylons-projects/test_proj
echo 'syntax: glob' >> .hgignore
echo '*.pyc' >> .hgignore


Then we will have to initialize the repository for the Pylons project:

cd $HOME/dev/pylons-projects/test_proj
hg init


You can now check the status of the files tracked by Mercurial for this Pylons project:

cd $HOME/dev/pylons-projects/test_proj
hg status


The result of the last command shows that no file is tracked:

? .hgignore
? MANIFEST.in
? README.txt
? development.ini
? docs/index.txt
? setup.cfg
? setup.py
? test.ini
? test_proj.egg-info/PKG-INFO
? test_proj.egg-info/SOURCES.txt
? test_proj.egg-info/dependency_links.txt
? test_proj.egg-info/entry_points.txt
? test_proj.egg-info/paste_deploy_config.ini_tmpl
? test_proj.egg-info/paster_plugins.txt
? test_proj.egg-info/requires.txt
? test_proj.egg-info/top_level.txt
? test_proj/__init__.py
? test_proj/config/__init__.py
? test_proj/config/environment.py
? test_proj/config/middleware.py
? test_proj/config/routing.py
? test_proj/controllers/__init__.py
? test_proj/controllers/error.py
? test_proj/controllers/template.py
? test_proj/lib/__init__.py
? test_proj/lib/app_globals.py
? test_proj/lib/base.py
? test_proj/lib/helpers.py
? test_proj/model/__init__.py
? test_proj/public/index.html
? test_proj/tests/__init__.py
? test_proj/tests/functional/__init__.py
? test_proj/tests/test_models.py
? test_proj/websetup.py


So we must add these files to the list of files that must be tracked:

cd $HOME/dev/pylons-projects/test_proj
hg add


The result of the last command shows that the files have been added and are waiting to be commited:

A .hgignore
A MANIFEST.in
A README.txt
A development.ini
A docs/index.txt
A setup.cfg
A setup.py
A test.ini
A test_proj.egg-info/PKG-INFO
A test_proj.egg-info/SOURCES.txt
A test_proj.egg-info/dependency_links.txt
A test_proj.egg-info/entry_points.txt
A test_proj.egg-info/paste_deploy_config.ini_tmpl
A test_proj.egg-info/paster_plugins.txt
A test_proj.egg-info/requires.txt
A test_proj.egg-info/top_level.txt
A test_proj/__init__.py
A test_proj/config/__init__.py
A test_proj/config/environment.py
A test_proj/config/middleware.py
A test_proj/config/routing.py
A test_proj/controllers/__init__.py
A test_proj/controllers/error.py
A test_proj/controllers/template.py
A test_proj/lib/__init__.py
A test_proj/lib/app_globals.py
A test_proj/lib/base.py
A test_proj/lib/helpers.py
A test_proj/model/__init__.py
A test_proj/public/index.html
A test_proj/tests/__init__.py
A test_proj/tests/functional/__init__.py
A test_proj/tests/test_models.py
A test_proj/websetup.py


So the last thing that must be done is to commit the files to the repository:

cd $HOME/dev/pylons-projects/test_proj
hg commit -m 'Initial commit'


I invite you to spend some time to learn how to use Mercurial (it's a great tool): you will find lot's of informations on its wiki and and by reading the book Distributed revision control with Mercurial.

No comments: