Add/modify functions to save and retrieve the set version information or the live git version
Change indent to tabs.
"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)
'''Version information and/or git version information
'''
+import os
+
from snakeoil.version import format_version
+from catalyst.fileops import pjoin
__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 = pjoin(os.path.dirname(__file__), filename)
+ else:
+ path = pjoin(root, filename)
+ #__version__ = version
+ ver = get_git_version(version)
+ ver = ver.replace('\n', '\\n')
+ with open(path, 'w') as f:
+ f.write("version = '%s'" % ver)
+
+#!/usr/bin/python2 -OO
+
# Copyright (C) 2013 W. Trevor King <wking@tremily.us>
#
# This program is free software: you can redistribute it and/or modify
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
-"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
import itertools as _itertools
import os as _os
from catalyst import __version__
+from catalyst.version import set_release_version, get_version
_this_dir = _os.path.dirname(__file__)
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__,
))),
],
provides=[package_name],
+ cmdclass = {
+ 'set_version': set_version
+ }
)