b1b7199a6202e5316a7cb9f73914a54cf10e8679
[hooke.git] / hooke / __init__.py
1 # Copyright (C) 2010-2012 W. Trevor King <wking@drexel.edu>
2 #
3 # This file is part of Hooke.
4 #
5 # Hooke is free software: you can redistribute it and/or modify it
6 # under the terms of the GNU Lesser General Public License as
7 # published by the Free Software Foundation, either version 3 of the
8 # License, or (at your option) any later version.
9 #
10 # Hooke is distributed in the hope that it will be useful, but WITHOUT
11 # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
12 # or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser General
13 # Public License for more details.
14 #
15 # You should have received a copy of the GNU Lesser General Public
16 # License along with Hooke.  If not, see
17 # <http://www.gnu.org/licenses/>.
18
19 """The hooke module does all the legwork for Hooke_.
20
21 .. _hooke: http://code.google.com/p/hooke/
22
23 To facilitate faster loading, submodules are not imported by default.
24 The available submodules are:
25
26 * :mod:`hooke.config`
27 * :mod:`hooke.compat`
28 """
29 try:
30     from .license import LICENSE as __license__
31 except ImportError, e:
32     import logging
33     logging.warn('could not load LICENSE from hooke.license')
34     __license__ = 'All rights reserved.' 
35
36 from .util import yaml  # extend YAML to parse Hooke-specific items.
37
38 __version__ = (1, 0, 0, 'alpha', None, 'Ninken')
39 """Version tuple::
40
41     (major, minor, release, type, patch, name)
42
43 Where 
44
45   * type: Python uses alpha, beta, candidate, and final.  Whatever
46     so long as the alphabetic sort gets them in the right order.
47   * patch: either manually incremented for each release, the packaging
48     date string, YYYYMMDD, date of last commit, whatever.
49
50 See `Greg Noel's post on scons-devel`_ for a good explaination of why this
51 versioning scheme is a good idea.
52
53 .. _Greg Noel's post on scons-devel
54   http://thread.gmane.org/gmane.comp.programming.tools.scons.devel/8740
55 """
56
57 def version(depth=-1, version_tuple=None):
58     """Return a nicely formatted version string.::
59
60         major.minor.release.type[.patch] (name)
61
62     Examples
63     --------
64
65     Since I seem to be unable to override __version__ in a Doctest,
66     we'll pass the version tuple in as an argument.  You can ignore
67     `version_tuple`.
68
69     >>> v = (1, 2, 3, 'devel', '20100501', 'Kenzo')
70
71     If depth -1, a full version string is returned
72
73     >>> version(depth=-1, version_tuple=v)
74     '1.2.3.devel.20100501 (Kenzo)'
75
76     Otherwise, only the first depth fields are used.
77
78     >>> version(depth=3, version_tuple=v)
79     '1.2.3'
80     >>> version(depth=4, version_tuple=v)
81     '1.2.3.devel'
82
83     Here's an example dropping the patch.
84
85     >>> v = (1, 2, 3, 'devel', None, 'Kenzo')
86     >>> version(depth=-1, version_tuple=v)
87     '1.2.3.devel (Kenzo)'
88     """
89     if version_tuple == None:
90         version_tuple = __version__
91     patch_index = 4
92     if version_tuple[patch_index] == None: # No patch field, drop that entry
93         version_tuple = version_tuple[0:patch_index] \
94             + version_tuple[patch_index+1:]
95         if depth >= patch_index:
96             depth -= 1
97     fields = version_tuple[0:depth]
98     string = '.'.join([str(x) for x in fields])
99     if depth == -1 or depth == len(version_tuple):
100         string += ' (%s)' % version_tuple[-1]
101     return string