Revision 00351409 devtools/version.py
b/devtools/version.py | ||
---|---|---|
85 | 85 |
revno = len(list(repo.iter_commits())) |
86 | 86 |
desc = repo.git.describe("--tags") |
87 | 87 |
toplevel = repo.working_dir |
88 |
except subprocess.CalledProcessError:
|
|
88 |
except git.InvalidGitRepositoryError:
|
|
89 | 89 |
log.error("Could not retrieve git information. " + |
90 | 90 |
"Current directory not a git repository?") |
91 |
raise
|
|
91 |
return None
|
|
92 | 92 |
|
93 | 93 |
info = namedtuple("vcs_info", ["branch", "revid", "revno", |
94 | 94 |
"desc", "toplevel"]) |
... | ... | |
160 | 160 |
develop and feature branches. |
161 | 161 |
|
162 | 162 |
The suffix 'rc' is used to denote release candidates. 'rc' versions live |
163 |
only release and hotfix branches. |
|
163 |
only in release and hotfix branches.
|
|
164 | 164 |
|
165 | 165 |
Suffixes 'next' and 'rc' have been chosen to ensure proper ordering |
166 | 166 |
according to setuptools rules: |
... | ... | |
244 | 244 |
if brnorm == "debian": |
245 | 245 |
brnorm = "debian-master" |
246 | 246 |
if brnorm.startswith("debian-"): |
247 |
brnorm = brnorm.split("debian-")[1]
|
|
247 |
brnorm = brnorm.replace("debian-", "", 1)
|
|
248 | 248 |
|
249 | 249 |
# Sanity checks |
250 | 250 |
if "-" in brnorm: |
251 | 251 |
btypestr = brnorm.split("-")[0] |
252 |
bverstr = brnorm.split("-")[1] |
|
253 |
if bverstr == "": |
|
254 |
raise ValueError("Malformed branch name '%s'" % branch) |
|
255 |
versioned = True |
|
256 | 252 |
else: |
257 |
btypestr = branch
|
|
258 |
versioned = False |
|
253 |
btypestr = brnorm
|
|
254 |
|
|
259 | 255 |
try: |
260 | 256 |
btype = BRANCH_TYPES[btypestr] |
261 | 257 |
except KeyError: |
... | ... | |
263 | 259 |
raise ValueError("Malformed branch name '%s', cannot classify as one " |
264 | 260 |
"of %s" % (btypestr, allowed_branches)) |
265 | 261 |
|
266 |
if versioned != btype.versioned: |
|
267 |
raise ValueError(("Branch name '%s' should %s contain version" % |
|
268 |
(branch, "not" if versioned else ""))) |
|
269 |
if btype.versioned and not re.match(VERSION_RE, bverstr): |
|
270 |
raise ValueError(("Malformed version '%s' in branch name '%s'" % |
|
271 |
(bverstr, branch))) |
|
262 |
if btype.versioned: |
|
263 |
try: |
|
264 |
bverstr = brnorm.split("-")[1] |
|
265 |
except IndexError: |
|
266 |
# No version |
|
267 |
raise ValueError("Branch name '%s' should contain version" % |
|
268 |
branch) |
|
269 |
|
|
270 |
# Check that version is well-formed |
|
271 |
if not re.match(VERSION_RE, bverstr): |
|
272 |
raise ValueError("Malformed version '%s' in branch name '%s'" % |
|
273 |
(bverstr, branch)) |
|
272 | 274 |
|
273 | 275 |
m = re.match(btype.allowed_version_re, base_version) |
274 | 276 |
if not m or (btype.versioned and m.groupdict()["bverstr"] != bverstr): |
275 |
raise ValueError(("Base version '%s' unsuitable for branch name '%s'" %
|
|
276 |
(base_version, branch)))
|
|
277 |
raise ValueError("Base version '%s' unsuitable for branch name '%s'" % |
|
278 |
(base_version, branch)) |
|
277 | 279 |
|
278 | 280 |
if mode not in ["snapshot", "release"]: |
279 |
raise ValueError(("Specified mode '%s' should be one of 'snapshot' or "
|
|
280 |
"'release'" % mode))
|
|
281 |
raise ValueError("Specified mode '%s' should be one of 'snapshot' or " |
|
282 |
"'release'" % mode)
|
|
281 | 283 |
snap = (mode == "snapshot") |
282 | 284 |
|
283 | 285 |
if ((snap and not btype.builds_snapshot) or |
284 | 286 |
(not snap and not btype.builds_release)): |
285 |
raise ValueError(("Invalid mode '%s' in branch type '%s'" %
|
|
286 |
(mode, btypestr)))
|
|
287 |
raise ValueError("Invalid mode '%s' in branch type '%s'" % |
|
288 |
(mode, btypestr))
|
|
287 | 289 |
|
288 | 290 |
if snap: |
289 | 291 |
v = "%s_%d_%s" % (base_version, vcs_info.revno, vcs_info.revid) |
... | ... | |
361 | 363 |
True |
362 | 364 |
|
363 | 365 |
""" |
364 |
return pyver.replace("_", "~").replace("rc", "~rc") |
|
366 |
return pyver.replace("_", "~").replace("rc", "~rc") + "-1"
|
|
365 | 367 |
|
366 | 368 |
|
367 | 369 |
def debian_version(base_version, vcs_info, mode): |
... | ... | |
369 | 371 |
return debian_version_from_python_version(p) |
370 | 372 |
|
371 | 373 |
|
374 |
def user_info(): |
|
375 |
import getpass |
|
376 |
import socket |
|
377 |
return "%s@%s" % (getpass.getuser(), socket.getfqdn()) |
|
378 |
|
|
379 |
|
|
372 | 380 |
def update_version(module, name="version", root="."): |
373 | 381 |
""" |
374 | 382 |
Generate or replace version.py as a submodule of `module`. |
... | ... | |
378 | 386 |
|
379 | 387 |
""" |
380 | 388 |
|
381 |
# FIXME: exit or fail if not in development environment? |
|
382 | 389 |
v = vcs_info() |
390 |
if not v: |
|
391 |
# Return early if not in development environment |
|
392 |
return |
|
383 | 393 |
b = base_version(v) |
384 | 394 |
mode = build_mode() |
385 | 395 |
paths = [root] + module.split(".") + ["%s.py" % name] |
386 | 396 |
module_filename = os.path.join(*paths) |
397 |
version = python_version(b, v, mode) |
|
387 | 398 |
content = """ |
388 | 399 |
__version__ = "%(version)s" |
389 |
__version_info__ = __version__.split(".")
|
|
400 |
__version_info__ = %(version_info)s
|
|
390 | 401 |
__version_vcs_info__ = %(vcs_info)s |
391 |
""" % dict(version=python_version(b, v, mode), |
|
392 |
vcs_info=pprint.PrettyPrinter().pformat(dict(v._asdict()))) |
|
402 |
__version_user_info__ = %(user_info)s |
|
403 |
""" % dict(version=version, version_info=version.split("."), |
|
404 |
vcs_info=pprint.PrettyPrinter().pformat(dict(v._asdict())), |
|
405 |
user_info=user_info()) |
|
393 | 406 |
|
394 | 407 |
module_file = file(module_filename, "w+") |
395 | 408 |
module_file.write(content) |
Also available in: Unified diff