Commit a236225d authored by Nikos Skalkotos's avatar Nikos Skalkotos Committed by GitHub
Browse files

Merge pull request #4 from skalkoto/feature-pep440

Feature pep440
parents 77be530b 5c120e56
......@@ -22,6 +22,3 @@ dist
_build
.coverage
cover/
# version module created automatically from setup.py
/devflow/version.py
Copyright (C) 2012, 2013 GRNET S.A. All rights reserved.
Copyright (C) 2012-2016 GRNET S.A. All rights reserved.
Redistribution and use in source and binary forms, with or
without modification, are permitted provided that the following
......
......@@ -44,13 +44,15 @@ from collections import namedtuple
branch_type = namedtuple("branch_type", ["builds_snapshot", "builds_release",
"versioned", "allowed_version_re",
"debian_branch"])
VERSION_RE = "[0-9]+\.[0-9]+(\.[0-9]+)*" # pylint: disable=W1401
RC_RE = "rc[1-9][0-9]*"
VERSION_RE = r'[0-9]+\.[0-9]+(\.[0-9]+)*'
RC_RE = r'rc[1-9][0-9]*'
BRANCH_TYPES = {
"feature": branch_type(True, False, False, "^%snext$" % VERSION_RE,
"feature": branch_type(True, False, False,
"^%s(next|\.?dev)?$" % VERSION_RE,
"debian-develop"),
"develop": branch_type(True, False, False, "^%snext$" % VERSION_RE,
"develop": branch_type(True, False, False,
"^%s(next|\.?dev)?$" % VERSION_RE,
"debian-develop"),
"release": branch_type(True, True, True,
"^(?P<bverstr>%s)(%s)+$" % (VERSION_RE, RC_RE),
......
......@@ -58,34 +58,39 @@ def conflicts():
def get_release_version(develop_version):
version = develop_version.rstrip('next')
parts = version.split('.')
major_version = int(parts[0])
minor_version = int(parts[1])
# return str(major_version) + '.' + str(minor_version+1) + 'rc1'
return str(major_version) + '.' + str(minor_version+1)
'''Given a development version it will return the release version'''
# Old version scheme
if 'next' in develop_version:
version = develop_version.rstrip('next')
parts = version.split('.')
major = int(parts[0])
minor = int(parts[1])
return "%d.%d" % (major, minor+1)
# New version may or may not contain dev:
# 0.19 is fine, same as 0.19.dev or 0.19dev
return develop_version.rstrip('.dev').rstrip('dev')
def get_develop_version_from_release(release_version):
'''Given a release version it will return the next develop version'''
# version = re.sub('rc[0-9]+$', '', release_version)
version = release_version
parts = version.split('.')
major_version = int(parts[0])
minor_version = int(parts[1])
return str(major_version) + '.' + str(minor_version+1) + 'next'
major = int(parts[0])
minor = int(parts[1])
return "%d.%ddev" % (major, minor+1)
def get_hotfix_version(version):
"""Given a version it will return the next hotfix version"""
parts = version.split('.')
major_version = int(parts[0])
minor_version = int(parts[1])
if len(parts) > 2:
hotfix_version = int(parts[2])
else:
hotfix_version = 0
major = int(parts[0])
minor = int(parts[1])
hotfix = int(parts[2]) if len(parts) > 2 else 0
return str(major_version) + '.' + str(minor_version) + '.' \
+ str(hotfix_version+1)
return "%d.%d.%d" % (major, minor, hotfix+1)
class GitManager(object):
......@@ -100,6 +105,10 @@ class GitManager(object):
self.new_tags = []
# self.repo.git.pull("origin")
# Check if version is obsolete
versioning.check_obsolete_version()
def get_branch(self, mode, version):
if mode not in ["release", "hotfix"]:
raise ValueError("Unknown mode: %s" % mode)
......@@ -267,7 +276,7 @@ class GitManager(object):
new_develop_version = "%snext" % version
upstream_branch = self.get_branch("hotfix", version)
# debian_branch = self.get_debian_branch("hotfix", version)
debian_branch = self.get_debian_branch("hotfix", version)
# create hotfix branch
repo.git.branch(upstream_branch, upstream)
......
__version__ = "0.13.dev0"
......@@ -127,25 +127,30 @@ def python_version(base_version, vcs_info, mode):
b) a version is generated either in 'release' or in 'snapshot' mode
c) the choice of mode depends on the branch, see following table.
A python version is of the form A_NNN,
The older python version format was of the form A_NNN,
where A: X.Y.Z{,next,rcW} and NNN: a revision number for the commit,
as returned by vcs_info().
The new python version complies with PEP 440 and is of the form:
X.Y.Z{,rcW}.devNNN
were X.Y.Z denote the upcoming release.
For every combination of branch and mode, releases are numbered as follows:
BRANCH: / MODE: snapshot release
-------- ------------------------------
feature 0.14next_150 N/A
develop 0.14next_151 N/A
release 0.14rc2_249 0.14rc2
master N/A 0.14
hotfix 0.14.1rc6_121 0.14.1rc6
BRANCH: / MODE: old_snapshot new_snapshot release
-------- ---------------------------------------
feature 0.14next_150 0.15.dev150 N/A
develop 0.14next_151 0.15.dev151 N/A
release 0.14rc2_249 0.14rc2.dev249 0.14rc2
master N/A N/A 0.14
hotfix 0.14.1rc6_121 0.14.1rc6.dev121 0.14.1rc6
N/A 0.14.1
The suffix 'next' in a version name is used to denote the upcoming version,
the one being under development in the develop and release branches.
In the older form, the suffix 'next' in a version name used to denote the
upcoming version, the one being under development in the develop branch.
Version '0.14next' is the version following 0.14, and only lives on the
develop and feature branches.
develop and feature branches. In the newer form we can denote the upcoming
version either as 0.15dev or simply 0.15.
The suffix 'rc' is used to denote release candidates. 'rc' versions live
only in release and hotfix branches.
......@@ -240,11 +245,15 @@ def python_version(base_version, vcs_info, mode):
raise ValueError("Invalid mode '%s' in branch type '%s'" %
(mode, btypestr))
if snap:
v = "%s_%d_%s" % (base_version, vcs_info.revno, vcs_info.revid)
else:
v = base_version
return v
if 'next' in base_version:
# This is the old version format and we are in snapshot mode, otherwise
# validate_version() would have failed.
return "%s_%d_%s" % (base_version, vcs_info.revno, vcs_info.revid)
elif snap:
return "%s.dev%d+df.%s" % (base_version.rstrip('.dev').rstrip('dev'),
vcs_info.revno,
vcs_info.revid.replace('_', '.'))
return base_version
def debian_version_from_python_version(pyver):
......@@ -316,7 +325,13 @@ def debian_version_from_python_version(pyver):
True
"""
version = pyver.replace("_", "~").replace("rc", "~rc")
if "_" in pyver:
# This is the old format
version = pyver.replace("_", "~").replace("rc", "~rc")
else:
version = pyver.replace(
".dev", "~dev").replace("dev", "~dev").replace("rc", "~rc")
codename = utils.get_distribution_codename()
minor = str(get_revision(version, codename))
return version + "-" + minor + "~" + codename
......@@ -371,6 +386,7 @@ def update_version():
raise RuntimeError("Can not compute version outside of a git"
" repository.")
b = get_base_version(v)
check_obsolete_version(b)
mode = utils.get_build_mode()
version = python_version(b, v, mode)
debian_version_ = debian_version_from_python_version(version)
......@@ -424,6 +440,7 @@ def update_version():
def bump_version_main():
try:
version = sys.argv[1]
check_obsolete_version(version)
bump_version(version)
except IndexError:
sys.stdout.write("Give me a version %s!\n")
......@@ -464,9 +481,31 @@ def bump_version(new_version):
_bump_version(new_version, v)
def check_obsolete_version(version=None):
"""Check if the version is postfixed with 'next' which is deprecated.
Output a warning"""
if version is None:
v = utils.get_vcs_info()
version = get_base_version(v)
if not version.endswith('next'):
return
new_version = version.rstrip('next').split('.')
new_version[-1] = str(int(new_version[-1]) + 1)
new_version = ".".join(new_version)
sys.stderr.write(
"Warning: Version %s contains postfix 'next' which is obsolete.\n"
"Warning: Replace it to the forthcoming release version (e.g. %s).\n"
"Warning: Support for postfix next will be removed in the future.\n" %
(version, new_version))
def main():
v = utils.get_vcs_info()
b = get_base_version(v)
check_obsolete_version(b)
mode = utils.get_build_mode()
try:
......
# Copyright 2012, 2013 GRNET S.A. All rights reserved.
# Copyright 2012-2016 GRNET S.A. All rights reserved.
#
# Redistribution and use in source and binary forms, with or
# without modification, are permitted provided that the following
......@@ -33,26 +33,16 @@
#
import os
from setuptools import setup, find_packages
try:
from devflow.version import __version__
except ImportError:
# Bootstrap devflow
from devflow.versioning import update_version
update_version()
from devflow.version import __version__
from imp import load_source
HERE = os.path.abspath(os.path.normpath(os.path.dirname(__file__)))
VERSION = os.path.join(HERE, 'devflow', 'version.py')
# Package info
VERSION = __version__
README = open(os.path.join(HERE, 'README.md')).read()
CHANGES = open(os.path.join(HERE, 'Changelog')).read()
SHORT_DESCRIPTION = 'A set of tools to ease versioning and use of git flow.'
PACKAGES_ROOT = '.'
PACKAGES = find_packages(PACKAGES_ROOT)
# Package meta
CLASSIFIERS = [
'Environment :: Console',
......@@ -67,7 +57,7 @@ INSTALL_REQUIRES = ['gitpython>=0.3.2RC1', 'sh', 'configobj', 'ansicolors']
setup(
name='devflow',
version=VERSION,
version=getattr(load_source('version', VERSION), "__version__"),
license='BSD',
url='http://www.synnefo.org/',
description=SHORT_DESCRIPTION,
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment