Added Sphinx documentation framework
[hooke.git] / hooke / __init__.py
1 """The hooke module does all the legwork for Hooke_ (BE).
2
3 .. _hooke: http://code.google.com/p/hooke/
4
5 To facilitate faster loading, submodules are not imported by default.
6 The available submodules are:
7
8 * :mod:`hooke.config`
9 * :mod:`hooke.compat`
10 """
11
12 __version__ = (0, 9, 0, 'devel', None, 'Kenzo')
13 """Version tuple::
14
15     (major, minor, release, type, patch, name)
16
17 Where 
18
19   * type: Python uses alpha, beta, candidate, and final.  Whatever
20     so long as the alphabetic sort gets them in the right order.
21   * patch: either manually incremented for each release, the packaging
22     date string, YYYYMMDD, date of last commit, whatever.
23
24 See `Greg Noel's post on scons-devel`_ for a good explaination of why this
25 versioning scheme is a good idea.
26
27 .. _Greg Noel's post on scons-devel
28   http://thread.gmane.org/gmane.comp.programming.tools.scons.devel/8740
29 """
30
31 def version(depth=-1, version_tuple=None):
32     """Return a nicely formatted version string.::
33
34         major.minor.release.type[.patch] (name)
35
36     Examples
37     --------
38
39     Since I seem to be unable to override __version__ in a Doctest,
40     we'll pass the version tuple in as an argument.  You can ignore
41     ``version_tuple``.
42
43     >>> v = (1, 2, 3, 'devel', '20100501', 'Kenzo')
44
45     If depth -1, a full version string is returned
46
47     >>> version(depth=-1, version_tuple=v)
48     '1.2.3.devel.20100501 (Kenzo)'
49
50     Otherwise, only the first depth fields are used.
51
52     >>> version(depth=3, version_tuple=v)
53     '1.2.3'
54     >>> version(depth=4, version_tuple=v)
55     '1.2.3.devel'
56
57     Here's an example dropping the patch.
58
59     >>> v = (1, 2, 3, 'devel', None, 'Kenzo')
60     >>> version(depth=-1, version_tuple=v)
61     '1.2.3.devel (Kenzo)'
62     """
63     if version_tuple == None:
64         version_tuple = __version__
65     patch_index = 4
66     if version_tuple[patch_index] == None: # No patch field, drop that entry
67         version_tuple = version_tuple[0:patch_index] \
68             + version_tuple[patch_index+1:]
69         if depth >= patch_index:
70             depth -= 1
71     fields = version_tuple[0:depth]
72     string = '.'.join([str(x) for x in fields])
73     if depth == -1 or depth == len(version_tuple):
74         string += ' (%s)' % version_tuple[-1]
75     return string