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