Browse files

upgrading for django-compressor

  • Loading branch information...
1 parent f7805f4 commit ed65e60b3ad17e46fc515683c359c45e7f886e21 @peterbe peterbe committed May 23, 2012
View
6 .gitmodules
@@ -52,3 +52,9 @@
[submodule "src/django-cronjobs"]
path = src/django-cronjobs
url = git://github.com/jsocol/django-cronjobs.git
+[submodule "src/django-compressor"]
+ path = src/django-compressor
+ url = git://github.com/jezdez/django_compressor.git
+[submodule "src/django-appconf"]
+ path = src/django-appconf
+ url = git://github.com/jezdez/django-appconf.git
View
2 bin/django-admin.py
@@ -1,4 +1,4 @@
-#!/Users/rlr/.virtualenvs/funfactory/bin/python
+#!/usr/bin/env python
from django.core import management
if __name__ == "__main__":
View
411 lib/python/versiontools/__init__.py
@@ -0,0 +1,411 @@
+# Copyright (C) 2010-2012 Linaro Limited
+#
+# Author: Zygmunt Krynicki <zygmunt.krynicki@linaro.org>
+#
+# This file is part of versiontools.
+#
+# versiontools is free software: you can redistribute it and/or modify
+# it under the terms of the GNU Lesser General Public License version 3
+# as published by the Free Software Foundation
+#
+# versiontools is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU Lesser General Public License
+# along with versiontools. If not, see <http://www.gnu.org/licenses/>.
+
+"""
+versiontools
+============
+
+Define *single* and *useful* ``__version__`` of a project.
+
+.. note: Since version 1.1 we should conform to PEP 386
+"""
+
+__version__ = (1, 9, 1, "final", 0)
+
+
+import inspect
+import operator
+import os
+import sys
+
+
+class Version(tuple):
+ """
+ Smart version class.
+
+ Version class is a tuple of five elements and has the same logical
+ components as :data:`sys.version_info`.
+
+ In addition to the tuple elements there is a special :attr:`vcs` attribute
+ that has all of the data exported by the version control system.
+ """
+
+ _RELEASELEVEL_TO_TOKEN = {
+ "alpha": "a",
+ "beta": "b",
+ "candidate": "c",
+ }
+
+ def __new__(cls, major, minor, micro=0, releaselevel="final", serial=0):
+ """
+ Construct a new version tuple.
+
+ There is some extra logic when initializing tuple elements. All
+ variables except for releaselevel are silently converted to integers
+ That is::
+
+ >>> Version("1.2.3.dev".split("."))
+ (1, 2, 3, "dev", 0)
+
+ :param major:
+ Major version number
+
+ :type major:
+ :class:`int` or :class:`str`
+
+ :param minor:
+ Minor version number
+
+ :type minor:
+ :class:`int` or :class:`str`
+
+ :param micro:
+ Micro version number, defaults to ``0``.
+
+ :type micro:
+ :class:`int` or :class:`str`
+
+ :param releaselevel:
+ Release level name.
+
+ There is a constraint on allowed values of releaselevel. Only the
+ following values are permitted:
+
+ * 'dev'
+ * 'alpha'
+ * 'beta'
+ * 'candidate'
+ * 'final'
+
+ :type releaselevel:
+ :class:`str`
+
+ :param serial:
+ Serial number, usually zero, only used for alpha, beta and
+ candidate versions where it must be greater than zero.
+
+ :type micro:
+ :class:`int` or :class:`str`
+
+ :raises ValueError:
+ If releaselevel is incorrect, a version component is negative or
+ serial is 0 and releaselevel is alpha, beta or candidate.
+ """
+ def to_int(v):
+ v = int(v)
+ if v < 0:
+ raise ValueError("Version components cannot be negative")
+ return v
+
+ major = to_int(major)
+ minor = to_int(minor)
+ micro = to_int(micro)
+ serial = to_int(serial)
+ if releaselevel not in ('dev', 'alpha', 'beta', 'candidate', 'final'):
+ raise ValueError(
+ "releaselevel %r is not permitted" % (releaselevel,))
+ if releaselevel in ('alpha', 'beta', 'candidate') and serial == 0:
+ raise ValueError(
+ ("serial must be greater than zero for"
+ " %s releases") % releaselevel)
+ obj = tuple.__new__(cls, (major, minor, micro, releaselevel, serial))
+ object.__setattr__(obj, '_source_tree', cls._find_source_tree())
+ object.__setattr__(obj, '_vcs', None)
+ return obj
+
+ major = property(
+ operator.itemgetter(0),
+ doc="Major version number")
+
+ minor = property(
+ operator.itemgetter(1),
+ doc="Minor version number")
+
+ micro = property(
+ operator.itemgetter(2),
+ doc="Micro version number")
+
+ releaselevel = property(
+ operator.itemgetter(3),
+ doc="Release level string")
+
+ serial = property(
+ operator.itemgetter(4),
+ doc="Serial number")
+
+ @property
+ def vcs(self):
+ """
+ Return VCS integration object, if any.
+
+ Accessing this attribute for the first time will query VCS lookup (may
+ be slower, will trigger imports of various VCS plugins).
+
+ The returned object, if not None, should have at least the `revno`
+ property. For details see your particular version control integration
+ plugin.
+
+ .. note::
+ This attribute is **not** an element of the version tuple
+ and thus does not break sorting.
+
+ .. versionadded:: 1.0.4
+ """
+ if self._vcs is None:
+ self._vcs = self._query_vcs()
+ return self._vcs
+
+ @classmethod
+ def from_tuple(cls, version_tuple):
+ """
+ Create version from 5-element tuple
+
+ .. note::
+ This method is identical to the constructor, just spelled in a way
+ that is more obvious to use.
+
+ .. versionadded:: 1.1
+ """
+ return cls(*version_tuple)
+
+ @classmethod
+ def from_tuple_and_hint(cls, version_tuple, hint):
+ """
+ Create version from a 5-element tuple and VCS location hint.
+
+ Similar to :meth:`~versiontools.Version.from_tuple` but uses the hint
+ object to locate the source tree if needed. A good candidate for hint
+ object is the module that contains the version_tuple. In general
+ anything that works with :meth:`inspect.getsourcefile()` is good.
+
+ .. versionadded:: 1.4
+ """
+ self = cls.from_tuple(version_tuple)
+ if self._source_tree is None:
+ path = inspect.getsourcefile(hint)
+ if path is not None:
+ self._source_tree = os.path.dirname(os.path.abspath(path))
+ return self
+
+ @classmethod
+ def from_expression(cls, pkg_expression):
+ """
+ Create a version from a python module name.
+
+ The argument must describe a module to import. The module must declare
+ a variable that holds the actual version. The version cannot be a plain
+ string and instead must be a tuple of five elements as described by the
+ :class:`~versiontools.Version` class.
+
+ The variable that holds the version should be called ``__version__``.
+ If it is called something else the actual name has to be specified
+ explicitly in ``pkg_expression`` by appending a colon (``:``) and the
+ name of the variable (for example ``package:version``).
+
+ .. versionadded:: 1.9
+ """
+ # Parse the version string
+ if ":" in pkg_expression:
+ module_or_package, identifier = pkg_expression.split(":", 1)
+ else:
+ # Allow people not to include the identifier separator
+ module_or_package = pkg_expression
+ identifier = ""
+ # Use __version__ unless specified otherwise
+ if identifier == "":
+ identifier = "__version__"
+ # Import module / package
+ try:
+ obj = __import__(module_or_package, globals(), locals(), [''])
+ except ImportError:
+ message = _get_exception_message(*sys.exc_info())
+ raise ValueError(
+ "Unable to import %r%s" % (module_or_package, message))
+ # Look up the version identifier.
+ try:
+ version = getattr(obj, identifier)
+ except AttributeError:
+ message = _get_exception_message(*sys.exc_info())
+ raise ValueError(
+ "Unable to access %r in %r%s" % (
+ identifier, module_or_package, message))
+ return cls.from_tuple_and_hint(version, hint=obj)
+
+ def __str__(self):
+ """
+ Return a string representation of the version tuple.
+
+ The string is not a direct concatenation of all version components.
+ Instead it's a more natural 'human friendly' version where components
+ with certain values are left out.
+
+ The following table shows how a version tuple gets converted to a
+ version string.
+
+ +-------------------------------+-------------------+
+ | __version__ | Formatter version |
+ +===============================+===================+
+ | ``(1, 2, 0, "final", 0)`` | ``"1.2"`` |
+ +-------------------------------+-------------------+
+ | ``(1, 2, 3, "final", 0)`` | ``"1.2.3"`` |
+ +-------------------------------+-------------------+
+ | ``(1, 3, 0, "alpha", 1)`` | ``"1.3a1"`` |
+ +-------------------------------+-------------------+
+ | ``(1, 3, 0, "beta", 1)`` | ``"1.3b1"`` |
+ +-------------------------------+-------------------+
+ | ``(1, 3, 0, "candidate", 1)`` | ``"1.3c1"`` |
+ +-------------------------------+-------------------+
+ | ``(1, 3, 0, "dev", 0)`` | ``"1.3.dev"`` |
+ +-------------------------------+-------------------+
+
+ Now when release level is set to ``"dev"`` then interesting things
+ start to happen. When possible, version control system is queried for
+ revision or changeset identifier. This information gets used to create
+ a more useful version string. The suffix gets appended to the base
+ version string. So for example a full version string, when using Bazaar
+ might look like this: ``"1.3.dev54"`` which indicates that the tree was
+ at revision 54 at that time.
+
+ The following table describes what gets appended by each version
+ control system.
+
+ +-----------+------------------------------------------------+
+ | VCS | Formatted version suffix |
+ +===========+================================================+
+ | Bazaar | Revision number (revno), e.g. ``54`` |
+ +-----------+------------------------------------------------+
+ | Git | Short commit ID of the current branch |
+ | | e.g. ``"763fbe3"`` |
+ +-----------+------------------------------------------------+
+ | Mercurial | Tip revision number, e.g. ``54`` |
+ +-----------+------------------------------------------------+
+ """
+ version = "%s.%s" % (self.major, self.minor)
+ if self.micro != 0:
+ version += ".%s" % self.micro
+ token = self._RELEASELEVEL_TO_TOKEN.get(self.releaselevel)
+ if token:
+ version += "%s%d" % (token, self.serial)
+ if self.releaselevel == "dev":
+ if self.vcs is not None:
+ version += ".dev%s" % self.vcs.revno
+ else:
+ version += ".dev"
+ return version
+
+ @classmethod
+ def _find_source_tree(cls):
+ """
+ Find the absolute pathname of the tree that contained the file that
+ called our __init__()
+ """
+ frame = inspect.currentframe()
+ outer_frames = inspect.getouterframes(frame)
+ for index0, record in enumerate(outer_frames):
+ frame, filename, lineno, func_name, context, context_index = record
+ if context is None or context_index >= len(context):
+ continue
+ if (func_name == "<module>" and "__version__" in
+ context[context_index]):
+ caller = frame
+ break
+ else:
+ caller = None
+ if caller:
+ return os.path.dirname(
+ os.path.abspath(
+ inspect.getsourcefile(caller)))
+
+ def _query_vcs(self):
+ """
+ Attempt to build a VCS object for the directory refrenced in
+ self._source_tree.
+
+ The actual version control integration is pluggable, anything that
+ provides an entrypoint for ``versintools.vcs_integration`` is
+ considered. The first version control system that indicates support for
+ the directory wins.
+
+ In practice you'd want to use the vcs property.
+ """
+ import pkg_resources
+ if self._source_tree is None:
+ return
+ for entrypoint in pkg_resources.iter_entry_points(
+ "versiontools.vcs_integration"):
+ try:
+ integration_cls = entrypoint.load()
+ integration = integration_cls.from_source_tree(
+ self._source_tree)
+ if integration:
+ return integration
+ except ImportError:
+ pass
+
+
+def format_version(version, hint=None):
+ """
+ Pretty formatting for 5-element version tuple.
+
+ Instead of using :class:`~versiontools.Version` class directly you may want
+ to use this simplified interface where you simply interpret an arbitrary
+ five-element version tuple as a version to get the pretty and
+ :pep:`386`-compliant version string.
+
+ :param version:
+ The version to format
+
+ :type version:
+ A :class:`tuple` with five elements, as the one provided to
+ :meth:`versiontools.Version.from_tuple`, or an existing instance of
+ :class:`versiontools.Version`.
+
+ :param hint:
+ The hint object, if provided, helps versiontools to locate the
+ directory which might host the project's source code. The idea is to
+ pass `module.__version__` as the first argument and `module` as the
+ hint. This way we can lookup where module came from, and look for
+ version control system data in that directory. Technically passing hint
+ will make us call :meth:`~versiontools.Version.from_tuple_and_hint()`
+ instead of :meth:`~versiontools.Version.from_tuple()`.
+
+ :type hint:
+ either :obj:`None`, or a module.
+
+ .. versionadded:: 1.1
+ """
+ if isinstance(version, Version):
+ return str(version)
+ elif isinstance(version, tuple) and len(version) == 5 and hint is not None:
+ return str(Version.from_tuple_and_hint(version, hint))
+ elif isinstance(version, tuple) and len(version) == 5:
+ return str(Version.from_tuple(version))
+ else:
+ raise ValueError("version must be a tuple of five items")
+
+
+def _get_exception_message(exception, value, traceback):
+ """
+ Helper for compatibility with older python versions
+ """
+ if value is not None: # the exception value
+ return ": %s" % value
+ return ""
+
+
+from versiontools.setuptools_hooks import version as handle_version
View
97 lib/python/versiontools/bzr_support.py
@@ -0,0 +1,97 @@
+# Copyright (C) 2010 -2012 Linaro Limited
+#
+# Author: Zygmunt Krynicki <zygmunt.krynicki@linaro.org>
+#
+# This file is part of versiontools.
+#
+# versiontools is free software: you can redistribute it and/or modify
+# it under the terms of the GNU Lesser General Public License version 3
+# as published by the Free Software Foundation
+#
+# versiontools is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU Lesser General Public License
+# along with versiontools. If not, see <http://www.gnu.org/licenses/>.
+
+"""
+.. _bzr:
+
+versiontools.bzr_support
+========================
+
+Bazaar support for versiontools
+
+.. note::
+
+ To work with Bazaar repositories you will need bzrlib. You can install it
+ with pip or from the ``bzr`` package on Ubuntu.
+
+.. warning::
+
+ On Windows the typical Bazaar installation bundles both the python
+ interpreter and a host of libraries and those libraries are not accessible
+ by the typically-installed python interpreter. If you wish to use Bazaar on
+ windows we would recommend to install Bazaar directly from pypi.
+"""
+import logging
+import sys
+
+
+class BzrIntegration(object):
+ """
+ Bazaar integration for versiontools
+ """
+ def __init__(self, branch):
+ self._revno = branch.last_revision_info()[0]
+ self._branch_nick = branch._get_nick(local=True)
+
+ @property
+ def revno(self):
+ """
+ Revision number of the branch
+ """
+ return self._revno
+
+ @property
+ def branch_nick(self):
+ """
+ Nickname of the branch
+
+ .. versionadded:: 1.0.4
+ """
+ return self._branch_nick
+
+ @classmethod
+ def from_source_tree(cls, source_tree):
+ """
+ Initialize :class:`~versiontools.bzr_support.BzrIntegration` by
+ pointing at the source tree. Any file or directory inside the
+ source tree may be used.
+ """
+ branch = None
+ try:
+ import bzrlib
+ if bzrlib.__version__ >= (2, 2, 1):
+ # Python 2.4 the with keyword is not supported
+ # and so you need to use the context manager manually, sigh.
+ library_state = bzrlib.initialize()
+ library_state.__enter__()
+ try:
+ from bzrlib.branch import Branch
+ branch = Branch.open_containing(source_tree)[0]
+ finally:
+ library_state.__exit__(None, None, None)
+ else:
+ from bzrlib.branch import Branch
+ branch = Branch.open_containing(source_tree)[0]
+ except Exception:
+ from versiontools import _get_exception_message
+ message = _get_exception_message(*sys.exc_info())
+ logging.debug("Unable to get branch revision because "
+ "directory %r is not a bzr branch. Erorr: %s",
+ (source_tree, message))
+ if branch:
+ return cls(branch)
View
113 lib/python/versiontools/git_support.py
@@ -0,0 +1,113 @@
+# -*- coding: utf-8 -*-"
+# Copyright (C) 2011 enn.io UG (haftungsbeschränkt)
+# Copyright (C) 2011-2012 Linaro Limited
+#
+# Author: Jannis Leidel <jannis@leidel.info>
+# Author: Zygmunt Krynicki <zygmunt.krynicki@linaro.org>
+#
+# This file is part of versiontools.
+#
+# versiontools is free software: you can redistribute it and/or modify
+# it under the terms of the GNU Lesser General Public License version 3
+# as published by the Free Software Foundation
+#
+# versiontools is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU Lesser General Public License
+# along with versiontools. If not, see <http://www.gnu.org/licenses/>.
+
+"""
+.. _git:
+
+versiontools.git_support
+========================
+
+Git support for versiontools
+
+.. note::
+
+ To work with Git repositories you will need `GitPython
+ <http://pypi.python.org/pypi/GitPython>`_. Version 0.1.6 is sufficient to
+ run the code. You can install it with pip.
+"""
+
+import logging
+import sys
+
+
+class GitIntegration(object):
+ """
+ Git integration for versiontools
+ """
+ def __init__(self, repo):
+ head = None
+ try:
+ # This path is for 0.3RC from pypi
+ head = repo.head
+ self._branch_nick = head.name
+ self._commit_id = head.commit.hexsha
+ except AttributeError:
+ pass
+ try:
+ # This is for python-git 0.1.6 (that is in debian and ubuntu)
+ head = [head for head in repo.heads if head.name==repo.active_branch][0]
+ self._branch_nick = head.name
+ self._commit_id = head.commit.id
+ except (IndexError, KeyError):
+ pass
+ if head is None:
+ raise ValueError("Unable to lookup head in %r" % repo)
+
+ @property
+ def revno(self):
+ """
+ Same as
+ :attr:`~versiontools.git_support.GitIntegration.commit_id_abbrev`
+ """
+ return self.commit_id_abbrev
+
+ @property
+ def commit_id(self):
+ """
+ The full commit id
+ """
+ return self._commit_id
+
+ @property
+ def commit_id_abbrev(self):
+ """
+ The abbreviated, 7 character commit id
+ """
+ return self._commit_id[:7]
+
+ @property
+ def branch_nick(self):
+ """
+ Nickname of the branch
+
+ .. versionadded:: 1.0.4
+ """
+ return self._branch_nick
+
+ @classmethod
+ def from_source_tree(cls, source_tree):
+ """
+ Initialize :class:`~versiontools.git_support.GitIntegration` by
+ pointing at the source tree. Any file or directory inside the
+ source tree may be used.
+ """
+ repo = None
+ try:
+ from git import Repo
+ repo = Repo(source_tree)
+ except Exception:
+ from versiontools import _get_exception_message
+ message = _get_exception_message(*sys.exc_info())
+ logging.debug("Unable to get branch revision because "
+ "directory %r is not a git repo. Error: %s",
+ (source_tree, message))
+ if repo:
+ return cls(repo)
View
87 lib/python/versiontools/hg_support.py
@@ -0,0 +1,87 @@
+# -*- coding: utf-8 -*-"
+# Copyright (C) 2011 enn.io UG (haftungsbeschränkt)
+# Copyright (C) 2011-2012 Linaro Limited
+#
+# Author: Jannis Leidel <jannis@leidel.info>
+# Author: Zygmunt Krynicki <zygmunt.krynicki@linaro.org>
+#
+# This file is part of versiontools.
+#
+# versiontools is free software: you can redistribute it and/or modify
+# it under the terms of the GNU Lesser General Public License version 3
+# as published by the Free Software Foundation
+#
+# versiontools is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU Lesser General Public License
+# along with versiontools. If not, see <http://www.gnu.org/licenses/>.
+
+"""
+.. _hg:
+
+versiontools.hg_support
+=======================
+
+Mercurial (Hg) support for versiontools.
+
+.. note::
+
+ To work with Mercurial repositories you will need `Mercurial
+ <http://mercurial.selenic.com/>`_. You can install it with pip or from the
+ `mercurial` package on Ubuntu.
+"""
+import logging
+import sys
+
+
+class HgIntegration(object):
+ """
+ Hg integration for versiontools
+ """
+ def __init__(self, repo):
+ tip = repo.changectx('tip')
+ self._revno = tip.rev()
+ try:
+ self._branch_nick = tip.branch()
+ except Exception:
+ self._branch_nick = None
+
+ @property
+ def revno(self):
+ """
+ Revision number of the branch
+ """
+ return self._revno
+
+ @property
+ def branch_nick(self):
+ """
+ Nickname of the branch
+
+ .. versionadded:: 1.0.4
+ """
+ return self._branch_nick
+
+ @classmethod
+ def from_source_tree(cls, source_tree):
+ """
+ Initialize :class:`~versiontools.hg_support.HgIntegration` by
+ pointing at the source tree. Any file or directory inside the
+ source tree may be used.
+ """
+ repo = None
+ try:
+ from mercurial.hg import repository
+ from mercurial.ui import ui
+ repo = repository(ui(), source_tree)
+ except Exception:
+ from versiontools import _get_exception_message
+ message = _get_exception_message(*sys.exc_info())
+ logging.debug("Unable to get branch revision because "
+ "directory %r is not a hg repo. Error: %s",
+ (source_tree, message))
+ if repo:
+ return cls(repo)
View
71 lib/python/versiontools/setuptools_hooks.py
@@ -0,0 +1,71 @@
+# Copyright (C) 2010-2012 Linaro Limited
+#
+# Author: Zygmunt Krynicki <zygmunt.krynicki@linaro.org>
+#
+# This file is part of versiontools.
+#
+# versiontools is free software: you can redistribute it and/or modify
+# it under the terms of the GNU Lesser General Public License version 3
+# as published by the Free Software Foundation
+#
+# versiontools is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU Lesser General Public License
+# along with versiontools. If not, see <http://www.gnu.org/licenses/>.
+
+"""
+versiontools.setuptools_hooks
+=============================
+
+Plugins for setuptools that add versintools features.
+
+Setuptools has a framework where external packages, such as versiontools, can
+hook into setup.py metadata and commands. We use this feature to intercept
+special values of the ``version`` keyword argument to ``setup()``. This
+argument handled by the following method:
+"""
+
+import sys
+
+from distutils.errors import DistutilsSetupError
+from versiontools import Version, _get_exception_message
+
+
+def version(dist, attr, value):
+ """
+ Handle the ``version`` keyword to setuptools.setup()
+
+ .. note::
+ This function is normally called by setuptools, it is advertised in the
+ entry points of versiontools as setuptools extension. There is no need
+ to call in manually.
+
+ .. versionadded:: 1.3
+ """
+ # We need to look at dist.metadata.version to actually see the version
+ # that was passed to setup. Something in between does not seem to like our
+ # version string and we get 0 here, odd.
+ if value == 0:
+ value = dist.metadata.version
+ if sys.version_info[:1] < (3,):
+ isstring = lambda string: isinstance(string, basestring)
+ else:
+ isstring = lambda string: isinstance(string, str)
+ if not (isstring(value)
+ and value.startswith(":versiontools:")):
+ return
+ # Peel away the magic tag
+ value = value[len(":versiontools:"):]
+ try:
+ # Lookup the version object
+ version = Version.from_expression(value)
+ # Update distribution metadata
+ dist.metadata.version = str(version)
+ except ValueError:
+ message = _get_exception_message(*sys.exc_info())
+ if message.startswith(": "):
+ message = message[2:]
+ raise DistutilsSetupError(message)
View
149 lib/python/versiontools/tests.py
@@ -0,0 +1,149 @@
+# Copyright (C) 2010, 2011 Linaro Limited
+#
+# Author: Zygmunt Krynicki <zygmunt.krynicki@linaro.org>
+#
+# This file is part of versiontools.
+#
+# versiontools is free software: you can redistribute it and/or modify
+# it under the terms of the GNU Lesser General Public License version 3
+# as published by the Free Software Foundation
+#
+# versiontools is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU Lesser General Public License
+# along with versiontools. If not, see <http://www.gnu.org/licenses/>.
+import sys
+
+from distutils.dist import Distribution
+from distutils.errors import DistutilsSetupError
+
+from unittest import TestCase
+
+from versiontools import Version
+from versiontools.setuptools_hooks import version as handle_version
+
+
+class VersionFormattingTests(TestCase):
+
+ def setUp(self):
+ # Inhibit Version.vcs from working
+ self._real_vcs = Version.vcs
+ Version.vcs = property(lambda self: None)
+
+ def tearDown(self):
+ Version.vcs = self._real_vcs
+
+ def test_defaults(self):
+ self.assertEqual(Version(1, 0), (1, 0, 0, "final", 0))
+
+ def test_serial_cannot_be_zero_for_certain_releaselevel(self):
+ self.assertRaises(ValueError, Version, 1, 2, 3, "alpha", 0)
+ self.assertRaises(ValueError, Version, 1, 2, 3, "beta", 0)
+ self.assertRaises(ValueError, Version, 1, 2, 3, "candidate", 0)
+
+ def test_serial_can_be_zero_for_certain_releaselevel(self):
+ self.assertEqual(Version(1, 2, 3, "final", 0).serial, 0)
+ self.assertEqual(Version(1, 2, 3, "dev", 0).serial, 0)
+
+ def test_releaselevel_values(self):
+ self.assertRaises(ValueError, Version, 1, 2, 3, "foobar", 0)
+
+ def test_accessors(self):
+ version = Version(1, 2, 3, "dev", 4)
+ self.assertEqual(version.major, 1)
+ self.assertEqual(version.minor, 2)
+ self.assertEqual(version.micro, 3)
+ self.assertEqual(version.releaselevel, "dev")
+ self.assertEqual(version.serial, 4)
+
+ def test_positional_accessors(self):
+ version = Version(1, 2, 3, "dev", 4)
+ self.assertEqual(version[0], 1)
+ self.assertEqual(version[1], 2)
+ self.assertEqual(version[2], 3)
+ self.assertEqual(version[3], "dev")
+ self.assertEqual(version[4], 4)
+
+ def test_formatting_zero_micro_discarded(self):
+ self.assertEqual(str(Version(1, 0)), "1.0")
+ self.assertEqual(str(Version(1, 0, 0)), "1.0")
+
+ def test_formatting_nonzero_micro_retained(self):
+ self.assertEqual(str(Version(1, 0, 1)), "1.0.1")
+
+ def test_formatting_serial_not_used_for_development(self):
+ self.assertEqual(str(Version(1, 2, 3, "dev", 4)), "1.2.3.dev")
+
+ def test_formatting_serial_not_used_for_final(self):
+ self.assertEqual(str(Version(1, 2, 3, "final", 4)), "1.2.3")
+
+ def test_formatting_serial_used_for_alpha_beta_and_candidate(self):
+ self.assertEqual(str(Version(1, 2, 3, "alpha", 4)), "1.2.3a4")
+ self.assertEqual(str(Version(1, 2, 3, "beta", 4)), "1.2.3b4")
+ self.assertEqual(str(Version(1, 2, 3, "candidate", 4)), "1.2.3c4")
+
+
+class MockedVCS(object):
+
+ def __init__(self, revno):
+ self.revno = revno
+
+
+class VersionFormattingTestsWithMockedVCS(TestCase):
+
+ def setUp(self):
+ # Inhibit Version.vcs from working
+ self._real_vcs = Version.vcs
+ self.mocked_vcs = None
+ Version.vcs = property(lambda x: self.mocked_vcs)
+
+ def mock_vcs_revno(self, revno):
+ self.mocked_vcs = MockedVCS(revno)
+
+ def tearDown(self):
+ Version.vcs = self._real_vcs
+
+ def test_formatting_without_vcs(self):
+ version = Version(1, 2, 3, "dev", 4)
+ self.assertEqual(str(version), "1.2.3.dev")
+
+ def test_formatting_with_vcs_and_revno(self):
+ self.mock_vcs_revno(5)
+ version = Version(1, 2, 3, "dev", 4)
+ self.assertEqual(str(version), "1.2.3.dev5")
+
+ def test_formatting_no_dev_suffix_for_alpha_beta_and_candidate(self):
+ self.mock_vcs_revno(5)
+ self.assertEqual(str(Version(1, 2, 3, "alpha", 4)), "1.2.3a4")
+ self.assertEqual(str(Version(1, 2, 3, "beta", 4)), "1.2.3b4")
+ self.assertEqual(str(Version(1, 2, 3, "candidate", 4)), "1.2.3c4")
+
+
+class HandleVersionTests(TestCase):
+
+ def setUp(self):
+ self.dist = Distribution()
+
+ def test_cant_import(self):
+ version = ':versiontools:nonexisting:'
+ try:
+ handle_version(self.dist, None, version)
+ except Exception:
+ e = sys.exc_info()[1]
+ self.assertTrue(isinstance(e, DistutilsSetupError))
+ self.assertEqual(str(e), "Unable to import 'nonexisting': "
+ "No module named nonexisting")
+
+ def test_not_found(self):
+ version = ':versiontools:versiontools:__nonexisting__'
+ try:
+ handle_version(self.dist, None, version)
+ except Exception:
+ e = sys.exc_info()[1]
+ self.assertTrue(isinstance(e, DistutilsSetupError))
+ self.assertEqual(str(e), "Unable to access '__nonexisting__' in "
+ "'versiontools': 'module' object has "
+ "no attribute '__nonexisting__'")
View
145 lib/python/versiontools/versiontools_support.py
@@ -0,0 +1,145 @@
+# Copyright (C) 2012 Linaro Limited
+#
+# Author: Zygmunt Krynicki <zygmunt.krynicki@linaro.org>
+#
+# This file is part of versiontools.
+#
+# versiontools is free software: you can redistribute it and/or modify
+# it under the terms of the GNU Lesser General Public License version 3
+# as published by the Free Software Foundation
+#
+# versiontools is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU Lesser General Public License
+# along with versiontools. If not, see <http://www.gnu.org/licenses/>.
+
+"""
+versiontools.versiontools_support
+=================================
+
+A small standalone module that allows any package to use versiontools.
+
+Typically you should copy this file verbatim into your source distribution.
+
+Historically versiontools was depending on a exotic feature of setuptools to
+work. Setuptools has so-called setup-time dependencies, that is modules that
+need to be downloaded and imported/interrogated for setup.py to run
+successfully. Versiontools supports this by installing a handler for the
+'version' keyword of the setup() function.
+
+This approach was always a little annoying as this setuptools feature is rather
+odd and very few other packages made any use of it. In the future the standard
+tools for python packaging (especially in python3 world) this feature may be
+removed or have equivalent thus rendering versiontools completely broken.
+
+Currently the biggest practical issue is the apparent inability to prevent
+setuptools from downloading packages designated as setup_requires. This is
+discussed in this pip issue: https://github.com/pypa/pip/issues/410
+
+To counter this issue I've redesigned versiontools to be a little smarter. The
+old mode stays as-is for compatibility. The new mode works differently, without
+the need for using setup_requires in your setup() call. Instead it requires
+each package that uses versiontools to ship a verbatim copy of this module and
+to import it in their setup.py script. This module helps setuptools find
+package version in the standard PKG-INFO file that is created for all source
+distributions. Remember that you only need this mode when you don't want to add
+a dependency on versiontools. This will still allow you to use versiontools (in
+a limited way) in your setup.py file.
+
+Technically this module defines an improved version of one of
+distutils.dist.DistributionMetadata class and monkey-patches distutils to use
+it. To retain backward compatibility the new feature is only active when a
+special version string is passed to the setup() call.
+"""
+
+__version__ = (1, 0, 0, "final", 0)
+
+import distutils.dist
+import distutils.errors
+
+
+class VersiontoolsEnchancedDistributionMetadata(distutils.dist.DistributionMetadata):
+ """
+ A subclass of distutils.dist.DistributionMetadata that uses versiontools
+
+ Typically you would not instantiate this class directly. It is constructed
+ by distutils.dist.Distribution.__init__() method. Since there is no other
+ way to do it, this module monkey-patches distutils to override the original
+ version of DistributionMetadata
+ """
+
+ # Reference to the original class. This is only required because distutils
+ # was created before the introduction of new-style classes to python.
+ __base = distutils.dist.DistributionMetadata
+
+ def get_version(self):
+ """
+ Get distribution version.
+
+ This method is enhanced compared to original distutils implementation.
+ If the version string is set to a special value then instead of using
+ the actual value the real version is obtained by querying versiontools.
+
+ If versiontools package is not installed then the version is obtained
+ from the standard section of the ``PKG-INFO`` file. This file is
+ automatically created by any source distribution. This method is less
+ useful as it cannot take advantage of version control information that
+ is automatically loaded by versiontools. It has the advantage of not
+ requiring versiontools installation and that it does not depend on
+ ``setup_requires`` feature of ``setuptools``.
+ """
+ if (self.name is not None and self.version is not None
+ and self.version.startswith(":versiontools:")):
+ return (self.__get_live_version() or self.__get_frozen_version()
+ or self.__fail_to_get_any_version())
+ else:
+ return self.__base.get_version(self)
+
+ def __get_live_version(self):
+ """
+ Get a live version string using versiontools
+ """
+ try:
+ import versiontools
+ except ImportError:
+ return None
+ else:
+ return str(versiontools.Version.from_expression(self.name))
+
+ def __get_frozen_version(self):
+ """
+ Get a fixed version string using an existing PKG-INFO file
+ """
+ try:
+ return self.__base("PKG-INFO").version
+ except IOError:
+ return None
+
+ def __fail_to_get_any_version(self):
+ """
+ Raise an informative exception
+ """
+ raise SystemExit(
+"""This package requires versiontools for development or testing.
+
+See http://versiontools.readthedocs.org/ for more information about
+what versiontools is and why it is useful.
+
+To install versiontools now please run:
+ $ pip install versiontools
+
+Note: versiontools works best when you have additional modules for
+integrating with your preferred version control system. Refer to
+the documentation for a full list of required modules.""")
+
+
+# If DistributionMetadata is not a subclass of
+# VersiontoolsEnhancedDistributionMetadata then monkey patch it. This should
+# prevent a (odd) case of multiple imports of this module.
+if not issubclass(
+ distutils.dist.DistributionMetadata,
+ VersiontoolsEnchancedDistributionMetadata):
+ distutils.dist.DistributionMetadata = VersiontoolsEnchancedDistributionMetadata
1 src/django-appconf
@@ -0,0 +1 @@
+Subproject commit d7ff3bb0c35a0c2ec83afdb31f7bb79e0f1b222c
1 src/django-compressor
@@ -0,0 +1 @@
+Subproject commit 90966edf9777a1c0b5f6389b15f5559a89081d39
2 src/funfactory
@@ -1 +1 @@
-Subproject commit ae93eb2a7775981404f31c21a8dbaa7cc63f6f5d
+Subproject commit 8c945106c5529433e98f51b81c314dd1b42284b7
View
2 vendor.pth
@@ -15,3 +15,5 @@ src/test-utils
src/tower
src/bleach
src/django-session-csrf
+src/django-compressor
+src/django-appconf

0 comments on commit ed65e60

Please sign in to comment.