versiontools-1.9.1/0000775000175000017500000000000011727520660014246 5ustar zygazyga00000000000000versiontools-1.9.1/doc/0000775000175000017500000000000011727520660015013 5ustar zygazyga00000000000000versiontools-1.9.1/doc/changes.rst0000664000175000017500000002303411727520446017161 0ustar zygazyga00000000000000Release history *************** .. _version_1_9_1: Version 1.9.1 ============= * Just bump version to final, sorry .. _version_1_9: Version 1.9 =========== * Reorganize and update documentation. * Add a new way of using versiontools that does not require using ``setup_requires``. This way is based on bundling a small helper module to help you bootstrap your project when installed from source. * Add :meth:`versiontools.Version.from_expression()` that creates a Version object from a python import expression (and an optional variable identifer) * Move and rename private function ``versiontools.handle_version`` to :func:`versiontools.setuptools_hooks:version`. * Move and rename private function ``versiontools.get_exception_message`` to :func:`versiontools._get_exception_message`. * Remove private function ``versiontools.isstring``. .. _version_1_8_3: Version 1.8.3 ============= * Fix incorrectly specified line in git support. Previosuly a KeyError may bleed to the outside calling code, depending on python version. * Fix incorrectly specified line in bzr support. Previously a non-bzr directory could be associated as a malformed bzr branch. .. _version_1_8_2: Version 1.8.2 ============= * Improve git support by adding code paths compatible with python-git 0.1.6 (which is easier to get on Debian) * Change git support to default to short commit id. If you want to access the long commit id you need to access it directly as GitIntegration.commit_id .. _version_1_8_1: Version 1.8.1 ============= * Improve performance when working with checkouts. The use of branch.nick has been replaced with branch._get_nick(local=True). This avoids network operations and is much more responsive. .. _version_1_8: Version 1.8 =========== * Fixed all pep8 issues (prettier syntax) * Fixed an issue with using __import__ on Python 2.4. * Fixed an issue with using :versiontools:path.to.symbol with nested modules * Fixed an issue with using exceptions on Python 3.x * Added test that demostrated that exception handling works on all Python versions. * Unified error handling across version control plugins. * General documentation improvements, installation, usage, code refrerence, and writing additional plug-ins. * Added a *backwards incompatible* constraint on serial to be greater than zero on alpha, beta and release candidates as required by :pep:`386`. .. _version_1_7: Version 1.7 =========== * Add support for Mercurial repositories * Fix a bug in exception handling that affected 1.6 .. _version_1_6: Version 1.6 =========== * Add support for python2.4 and python2.5 thanks to Jannis Leidel (thanks!). * Add tox (http://codespeak.net/~hpk/tox/) configuration file for easier testing. .. _version_1_5: Version 1.5 =========== * Added Git support, contributed by Jannis Leidel (thanks!). To use it you need GitPython >= 0.3.2.RC1. It does not currently work on GitPython packaged in Ubuntu Natty (0.1.6). .. _version_1_4: Version 1.4 =========== * Work harder to figure out the source tree a __version__ object comes from. This is possible with a new function :meth:`versiontools.Version.from_tuple_and_hint`. * Allow people to omit the version identifier in setup.py (defaulting to ``__version__``) .. _version_1_3_2: Version 1.3.2 ============= * Change version string produced by :meth:`versiontools.Version.__str__` and `versiontools.format_version` to be more useful when vcs integration is not available and the release is not final. Consult the table below for details. +----------------------+----------------------+--------------------------------+ | Prior to 1.3.2 | 1.3.2 | Comment | +======================+======================+================================+ | ``1.2.3`` | ``1.2.3.dev`` | When releaselevel==dev but | | | | VCS integration is not | | When VCS integration | | available we now add a .dev | | is not available | | suffix to differentiate from | | | | released versions | +----------------------+----------------------+--------------------------------+ | ``1.2.3a5`` or | ``1.2.3a5`` | ``.devREVNO`` is only added | | ``1.2.3a5.devREVNO`` | ` | when releaselevel==dev. | +----------------------+----------------------+ | | ``1.2.3b5`` or | ``1.2.3b5`` | It will never appear on alphas | | ``1.2.3b5.devREVNO`` | | , betas or release candidates. | +----------------------+----------------------+ | | ``1.2.3c5`` or | ``1.2.3c5`` | | | ``1.2.3c5.devREVNO`` | | | +----------------------+----------------------+--------------------------------+ .. _version_1_3_1: Version 1.3.1 ============= * To make `setup.py test` work in third party components we cannot use versiontools in our own setup. .. _version_1_3: Version 1.3 =========== * Add integration with setuptools (or more accurately, distribute) so that you no longer have to try-import versiontools. This means that you may finally install your packages with pip and everything will work correctly. * Prevent an unexplained crash when following the backtrace in ``Version._find_source_tree()``. .. seealso:: To get started quickly see :ref:`usage` .. _version_1_2: Version 1.2 =========== * Change how vcs objects are constructed. With this change they are only constructed lazily when needed. This speeds up common operations, delays the time any additional modules are imported (if any) and retains backwards comp ability. * Updated documentation on installation instructions to point to the new PPA * Updated recommended usage guide so that installed programs do not depend on versiontools. This allows you to use versiontools in setup.py and still benefit from the smart version formatting and keep your deployment lightweight. * Added basic unit tests * Fixed most PEP8 issues .. _version_1_1: Version 1.1 =========== * Change version string produced by :meth:`versiontools.Version.__str__` to be compatible with :pep:`386` The following table shows how old versions map to new versions: +-----------------------+----------------------+--------------------------------+ | Old Version | New Version | Comment | +=======================+======================+================================+ | ``1.2`` | ``1.2`` | | +-----------------------+----------------------+--------------------------------+ | ``1.2.3`` | ``1.2.3`` | | +-----------------------+----------------------+--------------------------------+ | ``1.2.3.dev.5`` | ``1.2.3.devREVNO`` | VCS revision and serial are | | | | two distinct fields. Serial | | | | is no longer displayed for | | | | development releases. | +-----------------------+----------------------+--------------------------------+ | ``1.2.3.alpha.5`` | ``1.2.3a5`` or | ``.devREVNO`` is only added | | | ``1.2.3a5.devREVNO`` | when VCS integration is | +-----------------------+----------------------+ available. | | ``1.2.3.beta.5`` | ``1.2.3b5`` or | | | | ``1.2.3b5.devREVNO`` | | +-----------------------+----------------------+ | | ``1.2.3.candidate.5`` | ``1.2.3c5`` or | | | | ``1.2.3c5.devREVNO`` | | +-----------------------+----------------------+--------------------------------+ * Add :func:`versiontools.format_version` that converts a 5-element tuple to a proper version string and is more obvious in intent. * Change default of Version releaselevel to "final" * Change default of Version serial to 0 * Serial field is no longer initialized with revision number from vcs, instead it is used to count alphas, betas and release candidates. * All version components except for releaselevel must be non-negative integers or strings that can be converted to such integers * Do not warn about "directory foo is not a bzr branch". This message was changed to debug as it is now legitimate for released code not to have bzr version control files. .. _version_1_0_4: Version 1.0.4 ============= * Add support to obtain VCS integration object via :data:`~versiontools.Version.vcs` attribute * Add support to obtain branch nickname from :class:`~versiontools.bzr_support.BzrIntegration` (via :data:`~versiontools.bzr_support.BzrIntegration.branch_nick` property) * Add :ref:`code_reference`. Version 1.0.3 ============= * Don't crash when :class:`ImportError` occurs during VCS integration initialization Version 1.0.2 ============= * Add documentation * Fix chicken-and-egg problem so that packages can now depend on versiontools and still be installed correctly with pip Version 1.0.1 ============= * Make VCS integration more robust in the way it locates source tree Version 1.0 =========== * Initial release versiontools-1.9.1/doc/conf.py0000664000175000017500000001501711727510614016314 0ustar zygazyga00000000000000# -*- coding: utf-8 -*- # # Linaro JSON documentation build configuration file, created by # sphinx-quickstart on Mon Dec 27 16:39:47 2010. # # This file is execfile()d with the current directory set to its containing dir. # # Note that not all possible configuration values are present in this # autogenerated file. # # All configuration values have a default; values that are commented out # serve to show the default. import sys import os # If extensions (or modules to document with autodoc) are in another directory, # add these directories to sys.path here. If the directory is relative to the # documentation root, use os.path.abspath to make it absolute, like shown here. sys.path.append(os.path.abspath('..')) # -- General configuration ----------------------------------------------------- # Add any Sphinx extension module names here, as strings. They can be extensions # coming with Sphinx (named 'sphinx.ext.*') or your custom ones. extensions = ['sphinx.ext.autodoc', 'sphinx.ext.doctest', 'sphinx.ext.intersphinx', 'sphinx.ext.todo', 'sphinx.ext.coverage'] # Add any paths that contain templates here, relative to this directory. templates_path = [] # The suffix of source filenames. source_suffix = '.rst' # The encoding of source files. #source_encoding = 'utf-8' # The master toctree document. master_doc = 'index' # General information about the project. project = u'Version Tools' copyright = u'2010-2011, Linaro Limited' # The version info for the project you're documenting, acts as replacement for # |version| and |release|, also used in various other places throughout the # built documents. # from versiontools import Version ver = Version.from_expression("versiontools") # The short X.Y version. version = "%d.%d" % (ver.major, ver.minor) # The full version, including alpha/beta/rc tags. release = str(ver) # The language for content autogenerated by Sphinx. Refer to documentation # for a list of supported languages. #language = None # There are two options for replacing |today|: either, you set today to some # non-false value, then it is used: #today = '' # Else, today_fmt is used as the format for a strftime call. #today_fmt = '%B %d, %Y' # List of documents that shouldn't be included in the build. #unused_docs = [] # List of directories, relative to source directory, that shouldn't be searched # for source files. exclude_trees = [] # The reST default role (used for this markup: `text`) to use for all documents. #default_role = None # If true, '()' will be appended to :func: etc. cross-reference text. #add_function_parentheses = True # If true, the current module name will be prepended to all description # unit titles (such as .. function::). #add_module_names = True # If true, sectionauthor and moduleauthor directives will be shown in the # output. They are ignored by default. #show_authors = False # The name of the Pygments (syntax highlighting) style to use. pygments_style = 'sphinx' # A list of ignored prefixes for module index sorting. #modindex_common_prefix = [] # -- Options for HTML output --------------------------------------------------- # The theme to use for HTML and HTML Help pages. Major themes that come with # Sphinx are currently 'default' and 'sphinxdoc'. html_theme = 'default' # Theme options are theme-specific and customize the look and feel of a theme # further. For a list of options available for each theme, see the # documentation. #html_theme_options = {} # Add any paths that contain custom themes here, relative to this directory. #html_theme_path = [] # The name for this set of Sphinx documents. If None, it defaults to # " v documentation". #html_title = None # A shorter title for the navigation bar. Default is the same as html_title. #html_short_title = None # The name of an image file (relative to this directory) to place at the top # of the sidebar. #html_logo = None # The name of an image file (within the static path) to use as favicon of the # docs. This file should be a Windows icon file (.ico) being 16x16 or 32x32 # pixels large. #html_favicon = None # Add any paths that contain custom static files (such as style sheets) here, # relative to this directory. They are copied after the builtin static files, # so a file named "default.css" will overwrite the builtin "default.css". html_static_path = [] # If not '', a 'Last updated on:' timestamp is inserted at every page bottom, # using the given strftime format. #html_last_updated_fmt = '%b %d, %Y' # If true, SmartyPants will be used to convert quotes and dashes to # typographically correct entities. #html_use_smartypants = True # Custom sidebar templates, maps document names to template names. #html_sidebars = {} # Additional templates that should be rendered to pages, maps page names to # template names. #html_additional_pages = {} # If false, no module index is generated. #html_use_modindex = True # If false, no index is generated. #html_use_index = True # If true, the index is split into individual pages for each letter. #html_split_index = False # If true, links to the reST sources are added to the pages. #html_show_sourcelink = True # If true, an OpenSearch description file will be output, and all pages will # contain a tag referring to it. The value of this option must be the # base URL from which the finished HTML is served. #html_use_opensearch = '' # If nonempty, this is the file name suffix for HTML files (e.g. ".xhtml"). #html_file_suffix = '' # Output file base name for HTML help builder. htmlhelp_basename = 'VersionToolsDocumentation' # -- Options for LaTeX output -------------------------------------------------- # The paper size ('letter' or 'a4'). #latex_paper_size = 'letter' # The font size ('10pt', '11pt' or '12pt'). #latex_font_size = '10pt' # Grouping the document tree into LaTeX files. List of tuples # (source start file, target name, title, author, documentclass [howto/manual]). latex_documents = [ ('index', 'VersionTools.tex', u'Version Tools Documentation', u'Zygmunt Krynicki', 'manual'), ] # The name of an image file (relative to this directory) to place at the top of # the title page. #latex_logo = None # For "manual" documents, if this is true, then toplevel headings are parts, # not chapters. #latex_use_parts = False # Additional stuff for the LaTeX preamble. #latex_preamble = '' # Documents to append as an appendix to all manuals. #latex_appendices = [] # If false, no module index is generated. #latex_use_modindex = True # Example configuration for intersphinx: refer to the Python standard library. intersphinx_mapping = {'http://docs.python.org/': None} versiontools-1.9.1/doc/vcs-integration.rst0000664000175000017500000000455611727510614020671 0ustar zygazyga00000000000000Integration with version control ******************************** versiontools supports a form of version control system integration. This code is *only* triggered for development versions of your project (indicated by setting ``releaselevel`` to ``dev"``) In development mode the generated version string will include the revision number or the abbreviated hash of the current commit. This makes it nice for ongoing releases on pypi as after each commit your source tarballs will be different. Batteries included ================== The following version control systems are supported out of the box. To use them you need to have the corresponding libraries installed. Check the links below for details. .. note: Users of your packages will *not* need those libraries. They are most useful for the developer during project life-cycle, especially between releases, to identify tarballs easily. Bazaar ++++++ Using bazaar appends the branch revision to the version string. See :ref:`bzr` Git +++ Using git appends the short commit id of the active branch. See :ref:`git` Mercurial +++++++++ Mercurial plug-in appends the branch revision to the development version. See :ref:`hg` Custom version control systems ============================== VCS integration is not hard-coded into versiontools. Instead any package that uses setuptools and provides an entry point ``versiontools.vcs_integration`` can add support for integration with additional version control systems. To see how to implement this simple API refer to the bundled plug-in for Bazaar :class:`~versiontools.bzr_support.BzrIntegration`, Git :class:`~versiontools.git_support.GitIntegration` or Mercurial :class:`~versiontools.hg_support.HgIntegration`. To make versiontools aware of additional plug-ins they need to be registered in the entry points database. To do that make sure your package uses setuptools and put the following snippet into your ``setup.py``:: setup( name="foo", description="The imaginary foo version control system", entry_points=""" [versiontools.vcs_integration] foo=foo.versiontools_plugin:FooIntegration """ ) This will make versiontools look for the ``foo`` system by importing ``foo.versiontools_plugin`` and extracting the ``FooIntegration`` class. Remember that your ``foo`` package needs to be installed for this system to work. versiontools-1.9.1/doc/usage.rst0000664000175000017500000000524511727510614016655 0ustar zygazyga00000000000000.. _usage: Usage instructions ****************** Using versiontools is very easy. Just follow those steps to do it. Declare package version ^^^^^^^^^^^^^^^^^^^^^^^ Put this code your package's ``__init__.py`` or in your main module:: __version__ = (1, 2, 3, 'final', 0) # replace with your project version .. note: There is some rationale for each component of the tuple. This has been standardized in :pep:`386`. Make sure you understand what each field represents. There are a few constraints, such as having serial (the last component) greater than zero if the release is 'alpha', 'beta' or 'candidate'. Copy versiontools_support.py ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ You will need to keep a copy of ``versiontools_support.py`` file in your source tree. This file will be needed by your users that don't have versiontools to still be able to run setup.py to install your package. Update MANIFEST.in ^^^^^^^^^^^^^^^^^^ You will need to update (or create) ``MANIFEST.in`` to ensure that each source distribution you make with ``setup.py sdist`` will ship a copy of the support file. All that you have to do is to append this line to your ``MANIFEST.in``:: include versiontools_support.py Patch setup.py ^^^^^^^^^^^^^^ Edit your ``setup.py`` to have code that looks like this:: import versiontools_support setup( version = ":versiontools:your_package", ) The trick here is to use a magic value for version keyword. The format of that magic value is:: ":versiontools:" - a magic string that versiontools matches your_package - name of your package or module to import ":" - colon separating package from identifier (optional) identifier - Object to import from your_package. (optional) Can be omitted if equal to __version__. This will make versiontools use :meth:`versiontools.format_version()` on whatever `your_package.__version__` contains. Since your `__version__` is a tuple as described above you'll get a correctly formatted version identifier. This code will ensure that: #. Your package will use version tools #. Your package will correctly install via pip Developing with versiontools ============================ While you are working on the next version of your project you should make sure that ``releaselevel`` is set to ``"dev"``. This will (if you have proper vcs integration in place) allow you to get the most benefit. Releases ======== Each time you make a release (with setup.py sdist or any bdist commands) make sure to change the ``releaselevel`` to something other than ``"dev"``. You can use the following strings: * ``"alpha"`` * ``"beta"`` * ``"candidate"`` * ``"final"`` versiontools-1.9.1/doc/reference.rst0000664000175000017500000000113411727510614017500 0ustar zygazyga00000000000000.. _code_reference: Code reference ************** .. automodule:: versiontools .. autoclass:: versiontools.Version :members: __new__, major, minor, micro, releaselevel, serial, from_tuple, from_tuple_and_hint, from_expression, vcs, __str__ .. autofunction:: versiontools.format_version .. automodule:: versiontools.setuptools_hooks :members: .. automodule:: versiontools.versiontools_support :members: .. automodule:: versiontools.bzr_support :members: .. automodule:: versiontools.git_support :members: .. automodule:: versiontools.hg_support :members: versiontools-1.9.1/doc/index.rst0000664000175000017500000000450611727520466016665 0ustar zygazyga00000000000000Version Tools Documentation =========================== .. seealso:: To get started quickly see :ref:`usage` .. seealso:: See what's new in :ref:`version_1_9_1` .. note:: This document may be out of date, the bleeding edge version is always available at http://versiontools.rtfd.org/ Installation ============ This package is being actively maintained and published in the `Python Package Index `_. You can install it if you have `pip `_ tool using just one line:: $ pip install versiontools Features ======== * A piece of code that allows you to keep a **single version definition** inside your package or module. No more hacks in setup.py, no more duplicates in setup.py and somewhere else. Just **one** version per package. * :class:`~versiontools.Version` objects can produce nice version strings for released files that are compliant with :pep:`386`. Releases, alphas, betas, development snaphots. All of those get good version strings out of the box. * Version objects understand the :abbr:`VCS (Version Control System)` used by your project. Git, Mercurial and Bazaar are supported out of the box. Custom systems can be added by 3rd party plugins. * Version object that compares as a tuple of values and sorts properly. * Zero-dependency install! If all you care about is handling setup() to get nice tarball names then you don't need to depend on versiontools (no setup_requires, no install_requires!). You will need to bundle a small support module though. __version__ to string conversion ================================ This is pulled from the documentation of the string method on the :class:`~versiontools.Version` class. In general you don't need to explicitly use that class to benefit from this system. To learn more check the :ref:`usage` section. .. automethod:: versiontools.Version.__str__ :noindex: .. note:: This logic is implemented in :meth:`versiontools.Version.__str__()` and can be overridden by sub-classes. You can use project-specific logic if required. To do that replace __version__ with an instance of your sub-class. Indices and tables ================== .. toctree:: :maxdepth: 3 usage.rst vcs-integration.rst reference.rst changes.rst * :ref:`genindex` * :ref:`modindex` * :ref:`search` versiontools-1.9.1/PKG-INFO0000664000175000017500000000165111727520660015346 0ustar zygazyga00000000000000Metadata-Version: 1.1 Name: versiontools Version: 1.9.1 Summary: Smart replacement for plain tuple used in __version__ Home-page: https://launchpad.net/versiontools Author: Zygmunt Krynicki Author-email: zygmunt.krynicki@linaro.org License: UNKNOWN Description: UNKNOWN Platform: UNKNOWN Classifier: Development Status :: 5 - Production/Stable Classifier: Intended Audience :: Developers Classifier: License :: OSI Approved :: GNU Library or Lesser General Public License (LGPL) Classifier: Operating System :: OS Independent Classifier: Programming Language :: Python :: 2.4 Classifier: Programming Language :: Python :: 2.5 Classifier: Programming Language :: Python :: 2.6 Classifier: Programming Language :: Python :: 2.7 Classifier: Programming Language :: Python :: 3.0 Classifier: Programming Language :: Python :: 3.1 Classifier: Programming Language :: Python :: 3.2 Classifier: Topic :: Software Development :: Version Control versiontools-1.9.1/versiontools.egg-info/0000775000175000017500000000000011727520660020506 5ustar zygazyga00000000000000versiontools-1.9.1/versiontools.egg-info/dependency_links.txt0000664000175000017500000000000111727520660024554 0ustar zygazyga00000000000000 versiontools-1.9.1/versiontools.egg-info/PKG-INFO0000664000175000017500000000165111727520660021606 0ustar zygazyga00000000000000Metadata-Version: 1.1 Name: versiontools Version: 1.9.1 Summary: Smart replacement for plain tuple used in __version__ Home-page: https://launchpad.net/versiontools Author: Zygmunt Krynicki Author-email: zygmunt.krynicki@linaro.org License: UNKNOWN Description: UNKNOWN Platform: UNKNOWN Classifier: Development Status :: 5 - Production/Stable Classifier: Intended Audience :: Developers Classifier: License :: OSI Approved :: GNU Library or Lesser General Public License (LGPL) Classifier: Operating System :: OS Independent Classifier: Programming Language :: Python :: 2.4 Classifier: Programming Language :: Python :: 2.5 Classifier: Programming Language :: Python :: 2.6 Classifier: Programming Language :: Python :: 2.7 Classifier: Programming Language :: Python :: 3.0 Classifier: Programming Language :: Python :: 3.1 Classifier: Programming Language :: Python :: 3.2 Classifier: Topic :: Software Development :: Version Control versiontools-1.9.1/versiontools.egg-info/entry_points.txt0000664000175000017500000000040611727520660024004 0ustar zygazyga00000000000000 [versiontools.vcs_integration] bzr=versiontools.bzr_support:BzrIntegration git=versiontools.git_support:GitIntegration hg=versiontools.hg_support:HgIntegration [distutils.setup_keywords] version=versiontools.setuptools_hooks:version versiontools-1.9.1/versiontools.egg-info/zip-safe0000664000175000017500000000000111670475637022150 0ustar zygazyga00000000000000 versiontools-1.9.1/versiontools.egg-info/SOURCES.txt0000664000175000017500000000103611727520660022372 0ustar zygazyga00000000000000MANIFEST.in setup.cfg setup.py doc/changes.rst doc/conf.py doc/index.rst doc/reference.rst doc/usage.rst doc/vcs-integration.rst versiontools/__init__.py versiontools/bzr_support.py versiontools/git_support.py versiontools/hg_support.py versiontools/setuptools_hooks.py versiontools/tests.py versiontools/versiontools_support.py versiontools.egg-info/PKG-INFO versiontools.egg-info/SOURCES.txt versiontools.egg-info/dependency_links.txt versiontools.egg-info/entry_points.txt versiontools.egg-info/top_level.txt versiontools.egg-info/zip-safeversiontools-1.9.1/versiontools.egg-info/top_level.txt0000664000175000017500000000001511727520660023234 0ustar zygazyga00000000000000versiontools versiontools-1.9.1/setup.py0000775000175000017500000000415711727510614015770 0ustar zygazyga00000000000000#!/usr/bin/env python # # Copyright (C) 2010-2012 Linaro Limited # # Author: Zygmunt Krynicki # # 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 . import versiontools.versiontools_support from setuptools import setup, find_packages setup( name='versiontools', version=':versiontools:versiontools', author="Zygmunt Krynicki", author_email="zygmunt.krynicki@linaro.org", packages=find_packages(), test_suite='versiontools.tests', description="Smart replacement for plain tuple used in __version__", url='https://launchpad.net/versiontools', entry_points=""" [versiontools.vcs_integration] bzr=versiontools.bzr_support:BzrIntegration git=versiontools.git_support:GitIntegration hg=versiontools.hg_support:HgIntegration [distutils.setup_keywords] version=versiontools.setuptools_hooks:version """, classifiers=[ "Development Status :: 5 - Production/Stable", "Intended Audience :: Developers", ("License :: OSI Approved :: GNU Library or Lesser General Public" " License (LGPL)"), "Operating System :: OS Independent", "Programming Language :: Python :: 2.4", "Programming Language :: Python :: 2.5", "Programming Language :: Python :: 2.6", "Programming Language :: Python :: 2.7", "Programming Language :: Python :: 3.0", "Programming Language :: Python :: 3.1", "Programming Language :: Python :: 3.2", "Topic :: Software Development :: Version Control", ], zip_safe=True) versiontools-1.9.1/versiontools/0000775000175000017500000000000011727520660017014 5ustar zygazyga00000000000000versiontools-1.9.1/versiontools/versiontools_support.py0000664000175000017500000001420711727510614023732 0ustar zygazyga00000000000000# Copyright (C) 2012 Linaro Limited # # Author: Zygmunt Krynicki # # 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 . """ 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 versiontools-1.9.1/versiontools/hg_support.py0000664000175000017500000000501611727510614021560 0ustar zygazyga00000000000000# -*- coding: utf-8 -*-" # Copyright (C) 2011 enn.io UG (haftungsbeschränkt) # Copyright (C) 2011-2012 Linaro Limited # # Author: Jannis Leidel # Author: Zygmunt Krynicki # # 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 . """ .. _hg: versiontools.hg_support ======================= Mercurial (Hg) support for versiontools. .. note:: To work with Mercurial repositories you will need `Mercurial `_. 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) versiontools-1.9.1/versiontools/bzr_support.py0000664000175000017500000000615511727510614021764 0ustar zygazyga00000000000000# Copyright (C) 2010 -2012 Linaro Limited # # Author: Zygmunt Krynicki # # 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 . """ .. _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) versiontools-1.9.1/versiontools/tests.py0000664000175000017500000001247711727510614020541 0ustar zygazyga00000000000000# Copyright (C) 2010, 2011 Linaro Limited # # Author: Zygmunt Krynicki # # 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 . 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__'") versiontools-1.9.1/versiontools/git_support.py0000664000175000017500000000636011727510614021750 0ustar zygazyga00000000000000# -*- coding: utf-8 -*-" # Copyright (C) 2011 enn.io UG (haftungsbeschränkt) # Copyright (C) 2011-2012 Linaro Limited # # Author: Jannis Leidel # Author: Zygmunt Krynicki # # 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 . """ .. _git: versiontools.git_support ======================== Git support for versiontools .. note:: To work with Git repositories you will need `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) versiontools-1.9.1/versiontools/__init__.py0000664000175000017500000003465411727520362021140 0ustar zygazyga00000000000000# Copyright (C) 2010-2012 Linaro Limited # # Author: Zygmunt Krynicki # # 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 . """ 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 == "" 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 versiontools-1.9.1/versiontools/setuptools_hooks.py0000664000175000017500000000506211727510614023013 0ustar zygazyga00000000000000# Copyright (C) 2010-2012 Linaro Limited # # Author: Zygmunt Krynicki # # 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 . """ 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) versiontools-1.9.1/setup.cfg0000664000175000017500000000017711727520660016074 0ustar zygazyga00000000000000[upload_docs] upload-dir = build/sphinx/html [upload] sign = True [egg_info] tag_build = tag_date = 0 tag_svn_revision = 0 versiontools-1.9.1/MANIFEST.in0000664000175000017500000000006011670475471016006 0ustar zygazyga00000000000000include doc/conf.py recursive-include doc *.rst