~ubuntu-branches/ubuntu/quantal/python-django-compressor/quantal-201208160040

« back to all changes in this revision

Viewing changes to versiontools-1.9.1-py2.7.egg/versiontools/setuptools_hooks.py

debian/control: Add 'Provides: ${python:Provides}' to fix package
installation. (LP: #1036907)

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2010-2012 Linaro Limited
2
 
#
3
 
# Author: Zygmunt Krynicki <zygmunt.krynicki@linaro.org>
4
 
#
5
 
# This file is part of versiontools.
6
 
#
7
 
# versiontools is free software: you can redistribute it and/or modify
8
 
# it under the terms of the GNU Lesser General Public License version 3
9
 
# as published by the Free Software Foundation
10
 
#
11
 
# versiontools is distributed in the hope that it will be useful,
12
 
# but WITHOUT ANY WARRANTY; without even the implied warranty of
13
 
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
 
# GNU General Public License for more details.
15
 
#
16
 
# You should have received a copy of the GNU Lesser General Public License
17
 
# along with versiontools.  If not, see <http://www.gnu.org/licenses/>.
18
 
 
19
 
"""
20
 
versiontools.setuptools_hooks
21
 
=============================
22
 
 
23
 
Plugins for setuptools that add versintools features.
24
 
 
25
 
Setuptools has a framework where external packages, such as versiontools, can
26
 
hook into setup.py metadata and commands. We use this feature to intercept
27
 
special values of the ``version`` keyword argument to ``setup()``. This
28
 
argument handled by the following method:
29
 
"""
30
 
 
31
 
import sys
32
 
 
33
 
from distutils.errors import DistutilsSetupError
34
 
from versiontools import Version, _get_exception_message
35
 
 
36
 
 
37
 
def version(dist, attr, value):
38
 
    """
39
 
    Handle the ``version`` keyword to setuptools.setup()
40
 
 
41
 
    .. note::
42
 
        This function is normally called by setuptools, it is advertised in the
43
 
        entry points of versiontools as setuptools extension. There is no need
44
 
        to call in manually.
45
 
 
46
 
    .. versionadded:: 1.3
47
 
    """
48
 
    # We need to look at dist.metadata.version to actually see the version
49
 
    # that was passed to setup. Something in between does not seem to like our
50
 
    # version string and we get 0 here, odd.
51
 
    if value == 0:
52
 
        value = dist.metadata.version
53
 
    if sys.version_info[:1] < (3,):
54
 
        isstring = lambda string: isinstance(string, basestring)
55
 
    else:
56
 
        isstring = lambda string: isinstance(string, str)
57
 
    if not (isstring(value)
58
 
            and value.startswith(":versiontools:")):
59
 
        return
60
 
    # Peel away the magic tag
61
 
    value = value[len(":versiontools:"):]
62
 
    try:
63
 
        # Lookup the version object
64
 
        version = Version.from_expression(value)
65
 
        # Update distribution metadata
66
 
        dist.metadata.version = str(version) 
67
 
    except ValueError:
68
 
        message = _get_exception_message(*sys.exc_info())
69
 
        if message.startswith(": "):
70
 
            message = message[2:]
71
 
        raise DistutilsSetupError(message)