Exemplo n.º 1
0
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)
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)
Exemplo n.º 3
0
 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)
Exemplo n.º 4
0
 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)