From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from lists.gentoo.org (pigeon.gentoo.org [208.92.234.80]) by finch.gentoo.org (Postfix) with ESMTP id 8F3D1138247 for ; Thu, 21 Nov 2013 09:06:58 +0000 (UTC) Received: from pigeon.gentoo.org (localhost [127.0.0.1]) by pigeon.gentoo.org (Postfix) with SMTP id 257D7E0A53; Thu, 21 Nov 2013 09:06:45 +0000 (UTC) Received: from smtp.gentoo.org (smtp.gentoo.org [140.211.166.183]) (using TLSv1 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by pigeon.gentoo.org (Postfix) with ESMTPS id 409F5E0A49 for ; Thu, 21 Nov 2013 09:06:39 +0000 (UTC) Received: from hornbill.gentoo.org (hornbill.gentoo.org [94.100.119.163]) (using TLSv1 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by smtp.gentoo.org (Postfix) with ESMTPS id 81EBB33F253 for ; Thu, 21 Nov 2013 09:06:37 +0000 (UTC) Received: from localhost.localdomain (localhost [127.0.0.1]) by hornbill.gentoo.org (Postfix) with ESMTP id CB763E54DA for ; Thu, 21 Nov 2013 09:06:33 +0000 (UTC) From: "Brian Dolbec" To: gentoo-commits@lists.gentoo.org Content-Transfer-Encoding: 8bit Content-type: text/plain; charset=UTF-8 Reply-To: gentoo-dev@lists.gentoo.org, "Brian Dolbec" Message-ID: <1385024411.6178a5aa2b6f490abe50155b30904ab422d48da6.dol-sen@gentoo> Subject: [gentoo-commits] proj/catalyst:3.0 commit in: catalyst/, / X-VCS-Repository: proj/catalyst X-VCS-Files: catalyst/__init__.py catalyst/version.py setup.py X-VCS-Directories: catalyst/ / X-VCS-Committer: dol-sen X-VCS-Committer-Name: Brian Dolbec X-VCS-Revision: 6178a5aa2b6f490abe50155b30904ab422d48da6 X-VCS-Branch: 3.0 Date: Thu, 21 Nov 2013 09:06:33 +0000 (UTC) Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: List-Id: Gentoo Linux mail X-BeenThere: gentoo-commits@lists.gentoo.org X-Archives-Salt: 03c3830e-d1f0-4632-8542-4b49201f485a X-Archives-Hash: 965849582a4ba80dad09762fd16937cf commit: 6178a5aa2b6f490abe50155b30904ab422d48da6 Author: Brian Dolbec gentoo org> AuthorDate: Thu Jun 6 15:57:41 2013 +0000 Commit: Brian Dolbec gmail com> CommitDate: Thu Nov 21 09:00:11 2013 +0000 URL: http://git.overlays.gentoo.org/gitweb/?p=proj/catalyst.git;a=commit;h=6178a5aa Add set_version command to setup.py. * Add/modify functions to save and retrieve the set version information or the live git version. * Change indent to tabs. --- catalyst/__init__.py | 7 ++++++- catalyst/version.py | 44 +++++++++++++++++++++++++++++++++++++++++--- setup.py | 38 ++++++++++++++++++++++++++++++++++++-- 3 files changed, 83 insertions(+), 6 deletions(-) diff --git a/catalyst/__init__.py b/catalyst/__init__.py index c2538aa..c9c2eab 100644 --- a/catalyst/__init__.py +++ b/catalyst/__init__.py @@ -1,3 +1,8 @@ "Catalyst is a release building tool used by Gentoo Linux" -from .version import __version__ +try: + from .verinfo import version as fullversion + __version__ = fullversion.split('\n')[0].split()[1] +except ImportError: + from .version import get_version, __version__ + fullversion = get_version(reset=True) diff --git a/catalyst/version.py b/catalyst/version.py index 03c77e4..d379d35 100644 --- a/catalyst/version.py +++ b/catalyst/version.py @@ -10,14 +10,52 @@ '''Version information and/or git version information ''' +import os + from snakeoil.version import format_version __version__="rewrite-git" _ver = None -def get_version(): + +def get_git_version(version=__version__): """Return: a string describing our version.""" global _ver - if _ver is None: - _ver = format_version('catalyst',__file__, __version__) + _ver = format_version('catalyst',__file__, version) return _ver + + +def get_version(reset=False): + '''Returns a saved release version string or the + generated git release version. + ''' + global __version__, _ver + if _ver and not reset: + return _ver + try: # getting the fixed version + from .verinfo import version + _ver = version + __version__ = version.split('\n')[0].split()[1] + except ImportError: # get the live version + version = get_git_version() + return version + + + +def set_release_version(version, root=None): + '''Saves the release version along with the + git log release information + + @param version: string + @param root: string, optional alternate root path to save to + ''' + #global __version__ + filename = "verinfo.py" + if not root: + path = os.path.join(os.path.dirname(__file__), filename) + else: + path = os.path.join(root, filename) + #__version__ = version + ver = get_git_version(version) + with open(path, 'w') as f: + f.write("version = {0!r}".format(ver)) diff --git a/setup.py b/setup.py old mode 100644 new mode 100755 index 34eae53..f585b99 --- a/setup.py +++ b/setup.py @@ -1,3 +1,5 @@ +#!/usr/bin/python2 -OO + # Copyright (C) 2013 W. Trevor King # # This program is free software: you can redistribute it and/or modify @@ -13,14 +15,19 @@ # You should have received a copy of the GNU General Public License # along with this program. If not, see . -"Catalyst is a release building tool used by Gentoo Linux" +"""Catalyst is a release building tool used by Gentoo Linux""" + +# py2.6 compatibility +from __future__ import print_function import codecs as _codecs -from distutils.core import setup as _setup +from distutils.core import setup as _setup, Command as _Command import itertools as _itertools import os as _os from catalyst import __version__ +from catalyst.version import set_release_version as _set_release_version +from catalyst.version import get_version as _get_version _this_dir = _os.path.dirname(__file__) @@ -44,6 +51,30 @@ def files(root): yield path +class set_version(_Command): + '''Saves the specified release version information + ''' + global __version__ + description = "hardcode script's version using VERSION from environment" + user_options = [] # [(long_name, short_name, desc),] + + def initialize_options (self): + pass + + def finalize_options (self): + pass + + def run(self): + try: + version = _os.environ['VERSION'] + except KeyError: + print("Try setting 'VERSION=x.y.z' on the command line... Aborting") + return + _set_release_version(version) + __version__ = _get_version() + print("Version set to:\n", __version__) + + _setup( name=package_name, version=__version__, @@ -86,4 +117,7 @@ _setup( ))), ], provides=[package_name], + cmdclass={ + 'set_version': set_version + }, )