1 |
commit: 1ff4b0d5ad73bcd43c7939b1001aea5597330e8f |
2 |
Author: Brian Dolbec <dolsen <AT> gentoo <DOT> org> |
3 |
AuthorDate: Thu Jun 6 15:57:41 2013 +0000 |
4 |
Commit: Brian Dolbec <brian.dolbec <AT> gmail <DOT> com> |
5 |
CommitDate: Fri Nov 22 06:02:35 2013 +0000 |
6 |
URL: http://git.overlays.gentoo.org/gitweb/?p=proj/catalyst.git;a=commit;h=1ff4b0d5 |
7 |
|
8 |
Add set_version command to setup.py. |
9 |
|
10 |
* Add/modify functions to save and retrieve the set version |
11 |
information or the live git version. |
12 |
* Change indent to tabs. |
13 |
|
14 |
--- |
15 |
catalyst/__init__.py | 7 ++++++- |
16 |
catalyst/version.py | 44 +++++++++++++++++++++++++++++++++++++++++--- |
17 |
setup.py | 38 ++++++++++++++++++++++++++++++++++++-- |
18 |
3 files changed, 83 insertions(+), 6 deletions(-) |
19 |
|
20 |
diff --git a/catalyst/__init__.py b/catalyst/__init__.py |
21 |
index c2538aa..c9c2eab 100644 |
22 |
--- a/catalyst/__init__.py |
23 |
+++ b/catalyst/__init__.py |
24 |
@@ -1,3 +1,8 @@ |
25 |
"Catalyst is a release building tool used by Gentoo Linux" |
26 |
|
27 |
-from .version import __version__ |
28 |
+try: |
29 |
+ from .verinfo import version as fullversion |
30 |
+ __version__ = fullversion.split('\n')[0].split()[1] |
31 |
+except ImportError: |
32 |
+ from .version import get_version, __version__ |
33 |
+ fullversion = get_version(reset=True) |
34 |
|
35 |
diff --git a/catalyst/version.py b/catalyst/version.py |
36 |
index 03c77e4..d379d35 100644 |
37 |
--- a/catalyst/version.py |
38 |
+++ b/catalyst/version.py |
39 |
@@ -10,14 +10,52 @@ |
40 |
'''Version information and/or git version information |
41 |
''' |
42 |
|
43 |
+import os |
44 |
+ |
45 |
from snakeoil.version import format_version |
46 |
|
47 |
__version__="rewrite-git" |
48 |
_ver = None |
49 |
|
50 |
-def get_version(): |
51 |
+ |
52 |
+def get_git_version(version=__version__): |
53 |
"""Return: a string describing our version.""" |
54 |
global _ver |
55 |
- if _ver is None: |
56 |
- _ver = format_version('catalyst',__file__, __version__) |
57 |
+ _ver = format_version('catalyst',__file__, version) |
58 |
return _ver |
59 |
+ |
60 |
+ |
61 |
+def get_version(reset=False): |
62 |
+ '''Returns a saved release version string or the |
63 |
+ generated git release version. |
64 |
+ ''' |
65 |
+ global __version__, _ver |
66 |
+ if _ver and not reset: |
67 |
+ return _ver |
68 |
+ try: # getting the fixed version |
69 |
+ from .verinfo import version |
70 |
+ _ver = version |
71 |
+ __version__ = version.split('\n')[0].split()[1] |
72 |
+ except ImportError: # get the live version |
73 |
+ version = get_git_version() |
74 |
+ return version |
75 |
+ |
76 |
+ |
77 |
+ |
78 |
+def set_release_version(version, root=None): |
79 |
+ '''Saves the release version along with the |
80 |
+ git log release information |
81 |
+ |
82 |
+ @param version: string |
83 |
+ @param root: string, optional alternate root path to save to |
84 |
+ ''' |
85 |
+ #global __version__ |
86 |
+ filename = "verinfo.py" |
87 |
+ if not root: |
88 |
+ path = os.path.join(os.path.dirname(__file__), filename) |
89 |
+ else: |
90 |
+ path = os.path.join(root, filename) |
91 |
+ #__version__ = version |
92 |
+ ver = get_git_version(version) |
93 |
+ with open(path, 'w') as f: |
94 |
+ f.write("version = {0!r}".format(ver)) |
95 |
|
96 |
diff --git a/setup.py b/setup.py |
97 |
old mode 100644 |
98 |
new mode 100755 |
99 |
index 34eae53..f585b99 |
100 |
--- a/setup.py |
101 |
+++ b/setup.py |
102 |
@@ -1,3 +1,5 @@ |
103 |
+#!/usr/bin/python2 -OO |
104 |
+ |
105 |
# Copyright (C) 2013 W. Trevor King <wking@×××××××.us> |
106 |
# |
107 |
# This program is free software: you can redistribute it and/or modify |
108 |
@@ -13,14 +15,19 @@ |
109 |
# You should have received a copy of the GNU General Public License |
110 |
# along with this program. If not, see <http://www.gnu.org/licenses/>. |
111 |
|
112 |
-"Catalyst is a release building tool used by Gentoo Linux" |
113 |
+"""Catalyst is a release building tool used by Gentoo Linux""" |
114 |
+ |
115 |
+# py2.6 compatibility |
116 |
+from __future__ import print_function |
117 |
|
118 |
import codecs as _codecs |
119 |
-from distutils.core import setup as _setup |
120 |
+from distutils.core import setup as _setup, Command as _Command |
121 |
import itertools as _itertools |
122 |
import os as _os |
123 |
|
124 |
from catalyst import __version__ |
125 |
+from catalyst.version import set_release_version as _set_release_version |
126 |
+from catalyst.version import get_version as _get_version |
127 |
|
128 |
|
129 |
_this_dir = _os.path.dirname(__file__) |
130 |
@@ -44,6 +51,30 @@ def files(root): |
131 |
yield path |
132 |
|
133 |
|
134 |
+class set_version(_Command): |
135 |
+ '''Saves the specified release version information |
136 |
+ ''' |
137 |
+ global __version__ |
138 |
+ description = "hardcode script's version using VERSION from environment" |
139 |
+ user_options = [] # [(long_name, short_name, desc),] |
140 |
+ |
141 |
+ def initialize_options (self): |
142 |
+ pass |
143 |
+ |
144 |
+ def finalize_options (self): |
145 |
+ pass |
146 |
+ |
147 |
+ def run(self): |
148 |
+ try: |
149 |
+ version = _os.environ['VERSION'] |
150 |
+ except KeyError: |
151 |
+ print("Try setting 'VERSION=x.y.z' on the command line... Aborting") |
152 |
+ return |
153 |
+ _set_release_version(version) |
154 |
+ __version__ = _get_version() |
155 |
+ print("Version set to:\n", __version__) |
156 |
+ |
157 |
+ |
158 |
_setup( |
159 |
name=package_name, |
160 |
version=__version__, |
161 |
@@ -86,4 +117,7 @@ _setup( |
162 |
))), |
163 |
], |
164 |
provides=[package_name], |
165 |
+ cmdclass={ |
166 |
+ 'set_version': set_version |
167 |
+ }, |
168 |
) |