Merge "Add post-tag versioning."
This commit is contained in:
commit
a325aad8a4
1
.gitignore
vendored
1
.gitignore
vendored
@ -7,3 +7,4 @@ dist/
|
|||||||
.DS_Store
|
.DS_Store
|
||||||
*.log
|
*.log
|
||||||
build
|
build
|
||||||
|
swiftclient/versioninfo
|
||||||
|
@ -3,6 +3,7 @@ include ChangeLog
|
|||||||
include LICENSE
|
include LICENSE
|
||||||
include README.rst
|
include README.rst
|
||||||
include run_tests.sh tox.ini
|
include run_tests.sh tox.ini
|
||||||
|
include swiftclient/versioninfo
|
||||||
recursive-include doc *
|
recursive-include doc *
|
||||||
recursive-include tests *
|
recursive-include tests *
|
||||||
recursive-include tools *
|
recursive-include tools *
|
||||||
|
6
setup.py
6
setup.py
@ -20,11 +20,7 @@ import setuptools
|
|||||||
import sys
|
import sys
|
||||||
|
|
||||||
from swiftclient.openstack.common import setup
|
from swiftclient.openstack.common import setup
|
||||||
from swiftclient import version
|
|
||||||
|
|
||||||
# TODO: Figuring out how we are going to do the versioning (and if
|
|
||||||
# any).
|
|
||||||
version = version
|
|
||||||
name = 'python-swiftclient'
|
name = 'python-swiftclient'
|
||||||
|
|
||||||
requires = setup.parse_requirements()
|
requires = setup.parse_requirements()
|
||||||
@ -36,7 +32,7 @@ def read(fname):
|
|||||||
|
|
||||||
setuptools.setup(
|
setuptools.setup(
|
||||||
name=name,
|
name=name,
|
||||||
version=version,
|
version=setup.get_post_version('swiftclient'),
|
||||||
description='Client Library for OpenStack Object Storage API',
|
description='Client Library for OpenStack Object Storage API',
|
||||||
long_description=read('README.rst'),
|
long_description=read('README.rst'),
|
||||||
url='https://github.com/openstack/python-swiftclient',
|
url='https://github.com/openstack/python-swiftclient',
|
||||||
|
@ -3,8 +3,3 @@
|
|||||||
OpenStack Swift Python client binding.
|
OpenStack Swift Python client binding.
|
||||||
"""
|
"""
|
||||||
from client import *
|
from client import *
|
||||||
|
|
||||||
#: Version information ``(major, minor, revision)``.
|
|
||||||
version_info = (1, 1, 0)
|
|
||||||
#: Version string ``'major.minor.revision'``.
|
|
||||||
version = '.'.join(map(str, version_info))
|
|
||||||
|
@ -19,9 +19,11 @@
|
|||||||
Utilities with minimum-depends for use in setup.py
|
Utilities with minimum-depends for use in setup.py
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
import datetime
|
||||||
import os
|
import os
|
||||||
import re
|
import re
|
||||||
import subprocess
|
import subprocess
|
||||||
|
import sys
|
||||||
|
|
||||||
from setuptools.command import sdist
|
from setuptools.command import sdist
|
||||||
|
|
||||||
@ -33,8 +35,7 @@ def parse_mailmap(mailmap='.mailmap'):
|
|||||||
for l in fp:
|
for l in fp:
|
||||||
l = l.strip()
|
l = l.strip()
|
||||||
if not l.startswith('#') and ' ' in l:
|
if not l.startswith('#') and ' ' in l:
|
||||||
canonical_email, alias = [x for x in l.split(' ')
|
canonical_email, alias = l.split(' ')
|
||||||
if x.startswith('<')]
|
|
||||||
mapping[alias] = canonical_email
|
mapping[alias] = canonical_email
|
||||||
return mapping
|
return mapping
|
||||||
|
|
||||||
@ -76,6 +77,10 @@ def parse_requirements(requirements_files=['requirements.txt',
|
|||||||
# -f lines are for index locations, and don't get used here
|
# -f lines are for index locations, and don't get used here
|
||||||
elif re.match(r'\s*-f\s+', line):
|
elif re.match(r'\s*-f\s+', line):
|
||||||
pass
|
pass
|
||||||
|
# argparse is part of the standard library starting with 2.7
|
||||||
|
# adding it to the requirements list screws distro installs
|
||||||
|
elif line == 'argparse' and sys.version_info >= (2, 7):
|
||||||
|
pass
|
||||||
else:
|
else:
|
||||||
requirements.append(line)
|
requirements.append(line)
|
||||||
|
|
||||||
@ -113,28 +118,54 @@ def write_requirements():
|
|||||||
def _run_shell_command(cmd):
|
def _run_shell_command(cmd):
|
||||||
output = subprocess.Popen(["/bin/sh", "-c", cmd],
|
output = subprocess.Popen(["/bin/sh", "-c", cmd],
|
||||||
stdout=subprocess.PIPE)
|
stdout=subprocess.PIPE)
|
||||||
return output.communicate()[0].strip()
|
out = output.communicate()
|
||||||
|
if len(out) == 0:
|
||||||
|
return None
|
||||||
|
if len(out[0].strip()) == 0:
|
||||||
|
return None
|
||||||
|
return out[0].strip()
|
||||||
|
|
||||||
|
|
||||||
def write_vcsversion(location):
|
def _get_git_next_version_suffix(branch_name):
|
||||||
"""Produce a vcsversion dict that mimics the old one produced by bzr.
|
datestamp = datetime.datetime.now().strftime('%Y%m%d')
|
||||||
"""
|
if branch_name == 'milestone-proposed':
|
||||||
if os.path.isdir('.git'):
|
revno_prefix = "r"
|
||||||
branch_nick_cmd = 'git branch | grep -Ei "\* (.*)" | cut -f2 -d" "'
|
else:
|
||||||
branch_nick = _run_shell_command(branch_nick_cmd)
|
revno_prefix = ""
|
||||||
revid_cmd = "git rev-parse HEAD"
|
_run_shell_command("git fetch origin +refs/meta/*:refs/remotes/meta/*")
|
||||||
revid = _run_shell_command(revid_cmd).split()[0]
|
milestone_cmd = "git show meta/openstack/release:%s" % branch_name
|
||||||
revno_cmd = "git log --oneline | wc -l"
|
milestonever = _run_shell_command(milestone_cmd)
|
||||||
revno = _run_shell_command(revno_cmd)
|
if not milestonever:
|
||||||
with open(location, 'w') as version_file:
|
milestonever = ""
|
||||||
version_file.write("""
|
post_version = _get_git_post_version()
|
||||||
# This file is automatically generated by setup.py, So don't edit it. :)
|
revno = post_version.split(".")[-1]
|
||||||
version_info = {
|
return "%s~%s.%s%s" % (milestonever, datestamp, revno_prefix, revno)
|
||||||
'branch_nick': '%s',
|
|
||||||
'revision_id': '%s',
|
|
||||||
'revno': %s
|
def _get_git_current_tag():
|
||||||
}
|
return _run_shell_command("git tag --contains HEAD")
|
||||||
""" % (branch_nick, revid, revno))
|
|
||||||
|
|
||||||
|
def _get_git_tag_info():
|
||||||
|
return _run_shell_command("git describe --tags")
|
||||||
|
|
||||||
|
|
||||||
|
def _get_git_post_version():
|
||||||
|
current_tag = _get_git_current_tag()
|
||||||
|
if current_tag is not None:
|
||||||
|
return current_tag
|
||||||
|
else:
|
||||||
|
tag_info = _get_git_tag_info()
|
||||||
|
if tag_info is None:
|
||||||
|
base_version = "0.0"
|
||||||
|
cmd = "git --no-pager log --oneline"
|
||||||
|
out = _run_shell_command(cmd)
|
||||||
|
revno = len(out.split("\n"))
|
||||||
|
else:
|
||||||
|
tag_infos = tag_info.split("-")
|
||||||
|
base_version = "-".join(tag_infos[:-2])
|
||||||
|
revno = tag_infos[-2]
|
||||||
|
return "%s.%s" % (base_version, revno)
|
||||||
|
|
||||||
|
|
||||||
def write_git_changelog():
|
def write_git_changelog():
|
||||||
@ -164,12 +195,46 @@ def generate_authors():
|
|||||||
with open(old_authors, "r") as old_authors_fh:
|
with open(old_authors, "r") as old_authors_fh:
|
||||||
new_authors_fh.write('\n' + old_authors_fh.read())
|
new_authors_fh.write('\n' + old_authors_fh.read())
|
||||||
|
|
||||||
|
_rst_template = """%(heading)s
|
||||||
|
%(underline)s
|
||||||
|
|
||||||
|
.. automodule:: %(module)s
|
||||||
|
:members:
|
||||||
|
:undoc-members:
|
||||||
|
:show-inheritance:
|
||||||
|
"""
|
||||||
|
|
||||||
|
|
||||||
|
def read_versioninfo(project):
|
||||||
|
"""Read the versioninfo file. If it doesn't exist, we're in a github
|
||||||
|
zipball, and there's really know way to know what version we really
|
||||||
|
are, but that should be ok, because the utility of that should be
|
||||||
|
just about nil if this code path is in use in the first place."""
|
||||||
|
versioninfo_path = os.path.join(project, 'versioninfo')
|
||||||
|
if os.path.exists(versioninfo_path):
|
||||||
|
with open(versioninfo_path, 'r') as vinfo:
|
||||||
|
version = vinfo.read().strip()
|
||||||
|
else:
|
||||||
|
version = "0.0.0"
|
||||||
|
return version
|
||||||
|
|
||||||
|
|
||||||
|
def write_versioninfo(project, version):
|
||||||
|
"""Write a simple file containing the version of the package."""
|
||||||
|
open(os.path.join(project, 'versioninfo'), 'w').write("%s\n" % version)
|
||||||
|
|
||||||
|
|
||||||
def get_cmdclass():
|
def get_cmdclass():
|
||||||
"""Return dict of commands to run from setup.py."""
|
"""Return dict of commands to run from setup.py."""
|
||||||
|
|
||||||
cmdclass = dict()
|
cmdclass = dict()
|
||||||
|
|
||||||
|
def _find_modules(arg, dirname, files):
|
||||||
|
for filename in files:
|
||||||
|
if filename.endswith('.py') and filename != '__init__.py':
|
||||||
|
arg["%s.%s" % (dirname.replace('/', '.'),
|
||||||
|
filename[:-3])] = True
|
||||||
|
|
||||||
class LocalSDist(sdist.sdist):
|
class LocalSDist(sdist.sdist):
|
||||||
"""Builds the ChangeLog and Authors files from VC first."""
|
"""Builds the ChangeLog and Authors files from VC first."""
|
||||||
|
|
||||||
@ -188,13 +253,90 @@ def get_cmdclass():
|
|||||||
from sphinx.setup_command import BuildDoc
|
from sphinx.setup_command import BuildDoc
|
||||||
|
|
||||||
class LocalBuildDoc(BuildDoc):
|
class LocalBuildDoc(BuildDoc):
|
||||||
|
def generate_autoindex(self):
|
||||||
|
print "**Autodocumenting from %s" % os.path.abspath(os.curdir)
|
||||||
|
modules = {}
|
||||||
|
option_dict = self.distribution.get_option_dict('build_sphinx')
|
||||||
|
source_dir = os.path.join(option_dict['source_dir'][1], 'api')
|
||||||
|
if not os.path.exists(source_dir):
|
||||||
|
os.makedirs(source_dir)
|
||||||
|
for pkg in self.distribution.packages:
|
||||||
|
if '.' not in pkg:
|
||||||
|
os.path.walk(pkg, _find_modules, modules)
|
||||||
|
module_list = modules.keys()
|
||||||
|
module_list.sort()
|
||||||
|
autoindex_filename = os.path.join(source_dir, 'autoindex.rst')
|
||||||
|
with open(autoindex_filename, 'w') as autoindex:
|
||||||
|
autoindex.write(""".. toctree::
|
||||||
|
:maxdepth: 1
|
||||||
|
|
||||||
|
""")
|
||||||
|
for module in module_list:
|
||||||
|
output_filename = os.path.join(source_dir,
|
||||||
|
"%s.rst" % module)
|
||||||
|
heading = "The :mod:`%s` Module" % module
|
||||||
|
underline = "=" * len(heading)
|
||||||
|
values = dict(module=module, heading=heading,
|
||||||
|
underline=underline)
|
||||||
|
|
||||||
|
print "Generating %s" % output_filename
|
||||||
|
with open(output_filename, 'w') as output_file:
|
||||||
|
output_file.write(_rst_template % values)
|
||||||
|
autoindex.write(" %s.rst\n" % module)
|
||||||
|
|
||||||
def run(self):
|
def run(self):
|
||||||
|
if not os.getenv('SPHINX_DEBUG'):
|
||||||
|
self.generate_autoindex()
|
||||||
|
|
||||||
for builder in ['html', 'man']:
|
for builder in ['html', 'man']:
|
||||||
self.builder = builder
|
self.builder = builder
|
||||||
self.finalize_options()
|
self.finalize_options()
|
||||||
|
self.project = self.distribution.get_name()
|
||||||
|
self.version = self.distribution.get_version()
|
||||||
|
self.release = self.distribution.get_version()
|
||||||
BuildDoc.run(self)
|
BuildDoc.run(self)
|
||||||
cmdclass['build_sphinx'] = LocalBuildDoc
|
cmdclass['build_sphinx'] = LocalBuildDoc
|
||||||
except ImportError:
|
except ImportError:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
return cmdclass
|
return cmdclass
|
||||||
|
|
||||||
|
|
||||||
|
def get_git_branchname():
|
||||||
|
for branch in _run_shell_command("git branch --color=never").split("\n"):
|
||||||
|
if branch.startswith('*'):
|
||||||
|
_branch_name = branch.split()[1].strip()
|
||||||
|
if _branch_name == "(no":
|
||||||
|
_branch_name = "no-branch"
|
||||||
|
return _branch_name
|
||||||
|
|
||||||
|
|
||||||
|
def get_pre_version(projectname, base_version):
|
||||||
|
"""Return a version which is based"""
|
||||||
|
if os.path.isdir('.git'):
|
||||||
|
current_tag = _get_git_current_tag()
|
||||||
|
if current_tag is not None:
|
||||||
|
version = current_tag
|
||||||
|
else:
|
||||||
|
branch_name = os.getenv('BRANCHNAME',
|
||||||
|
os.getenv('GERRIT_REFNAME',
|
||||||
|
get_git_branchname()))
|
||||||
|
version_suffix = _get_git_next_version_suffix(branch_name)
|
||||||
|
version = "%s~%s" % (base_version, version_suffix)
|
||||||
|
write_versioninfo(projectname, version)
|
||||||
|
return version.split('~')[0]
|
||||||
|
else:
|
||||||
|
version = read_versioninfo(projectname)
|
||||||
|
return version.split('~')[0]
|
||||||
|
|
||||||
|
|
||||||
|
def get_post_version(projectname):
|
||||||
|
"""Return a version which is equal to the tag that's on the current
|
||||||
|
revision if there is one, or tag plus number of additional revisions
|
||||||
|
if the current revision has no tag."""
|
||||||
|
|
||||||
|
if os.path.isdir('.git'):
|
||||||
|
version = _get_git_post_version()
|
||||||
|
write_versioninfo(projectname, version)
|
||||||
|
return version
|
||||||
|
return read_versioninfo(projectname)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user