Tutorial: Use Coda with locally stored Django documentation

Coda is great tool for coding and offers nice feature to define your own reference books/documentation for programming languages you are using. While it is expected that you point to online versions of these it is much better to use local copies of documentation as it allows to use them while offline and it is much faster as well.

This tutorial (verified on Mac OS X Leopard) will explain how to locally store Django documentation in HTML form and how to set up Coda use it as a reference book.

1. Preparation

As Django documentation is stored as reStructuredText (reST) files you need to translate it into HTML. Therefore you should install Sphinx- Python document generation tool.

As i found on Mac OS X you may need to install few required components which will not autoinstall together with Sphinx.

a) Pygments- Python based syntax highlighter

sudo easy_install Pygments

b) Jinja2 template engine

download and extract Jinja2-2.1.1.tar.gz (you may try to easy_install it but it didn't work for me so this is another way):

cd ~/Downloads/Jinja2-2.1.1/
sudo python setup.py install

c) after that it should be easy to install Sphinx

sudo easy_install sphinx

2. Get latest Django documentation and translate it to HTML files

mkdir django
cd django
svn co http://code.djangoproject.com/svn/django/trunk/docs
cd docs
make html

Now let's move Django html documentation which resides in _build/html/ subdirectory to some more meaningful place- e.g. in docs folder under user home directory:

mv _build/html/ ~/docs/django

Doubleclick ~/docs/django/index.html in Finder and check if documentation works in web browser.

3. Add local Django documentation as a reference book in Coda

Last step is to create new book in Coda's Book section and put right parameters in book preferences. Replace [user shortname] with name of your user home.

Book URL: 
file:///Users/[user shortname]/docs/django/contents.html
Search URL:
file:///Users/[user shortname]/docs/django/search.html?q=*&check_keywords=yes&area=default
Use for mode: 
Django (If you use Django-Template Syntax Highlighting for Coda) or Python (otherwise)

From now ⌘-double-click on selected words in Django files (syntax mode in Coda should be set properly) will get you to appropriate Django documentation page. You can do the same for Django-template html files as well by defining another book with the same URLs but different mode.

And it will be fast (works offline as well).

Enjoy.

Filed under  //   coda   django   documentation   html   local   tutorial  

How to get Django doctests to work again

Not so long ago i started to play with Web development framework Django. After more than 10 years spent in marketing and public relations i felt strong need to do something REAL with my own hands (i started my professional career as a software developer back in 1992).

After launching first tiny project (small site that helps you understand background processes running on your Mac) i wanted to follow best practice and get serious about testing. So i wrote my first doctests, they worked until one day...

...my Django doctests did not work at all, they did not even execute. When i test my application (python manage.py test  <application name>) it shows "Run 0 tests". What's wrong?

Googling for insight i found article named Django Testing Gothas, so as i understand there are FUNDAMENTAL problem with Django doctests: they do not execute if there is a single error within a single line.

In my case there was
   >>>line="test string"
which failed all 200 lines of my Django doctests, because
   >>> line="test string"
was expected (this is matter of single spacing character after >>>).

Django (in fact- Python) won't notify you that you cannot execute your tests if there is a problem in doctests. It will ignore all doctests because of single error in single line. I find it ridiculous. I perfectly understand that doctests are just a comments in code however- it is not acceptable that after a explicit command (test) to apply them, a one invalid line can make all your valid lines in doctests disappear without a single warning.

So if one day your Django doctests don't work, make sure that your doctests are 100% executable. Also- make sure that you have not tests.py AND tests directory within application directory- you should choose only one option, otherwise both can silently fail.

And my small victory out of this is better understanding of Python/Django doctests behavior. 
Filed under  //   django   testing  

About