2015-08-25 12:20:14 +00:00
|
|
|
#!/usr/bin/env python
|
2013-05-01 02:52:23 +00:00
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
# Authors: Douglas Creager <dcreager@dcreager.net>
|
|
|
|
# Calum Lind <calumlind@gmail.com>
|
|
|
|
#
|
|
|
|
# This file is placed into the public domain.
|
|
|
|
#
|
|
|
|
# Calculates the current version number by first checking output of “git describe”,
|
|
|
|
# modified to conform to PEP 386 versioning scheme. If “git describe” fails
|
|
|
|
# (likely due to using release tarball rather than git working copy), then fall
|
|
|
|
# back on reading the contents of the RELEASE-VERSION file.
|
|
|
|
#
|
|
|
|
# Usage: Import in setup.py, and use result of get_version() as package version:
|
|
|
|
#
|
|
|
|
# from version import *
|
|
|
|
#
|
|
|
|
# setup(
|
|
|
|
# ...
|
|
|
|
# version=get_version(),
|
|
|
|
# ...
|
|
|
|
# )
|
|
|
|
#
|
|
|
|
# Script will automatically update the RELEASE-VERSION file, if needed.
|
|
|
|
# Note that RELEASE-VERSION file should *not* be checked into git; please add
|
|
|
|
# it to your top-level .gitignore file.
|
|
|
|
#
|
|
|
|
# You'll probably want to distribute the RELEASE-VERSION file in your
|
|
|
|
# sdist tarballs; to do this, just create a MANIFEST.in file that
|
|
|
|
# contains the following line:
|
|
|
|
#
|
|
|
|
# include RELEASE-VERSION
|
|
|
|
#
|
|
|
|
|
2017-02-12 11:26:31 +00:00
|
|
|
from __future__ import print_function, unicode_literals
|
2013-05-01 02:52:23 +00:00
|
|
|
|
2015-08-25 18:42:07 +00:00
|
|
|
import os
|
2019-06-05 18:53:17 +00:00
|
|
|
import subprocess
|
2014-09-03 23:27:11 +00:00
|
|
|
|
2018-10-02 14:39:51 +00:00
|
|
|
__all__ = ('get_version',)
|
2015-10-23 23:58:14 +00:00
|
|
|
|
2016-11-03 21:26:46 +00:00
|
|
|
VERSION_FILE = os.path.join(os.path.dirname(__file__), 'RELEASE-VERSION')
|
2013-05-01 02:52:23 +00:00
|
|
|
|
2014-09-03 21:28:28 +00:00
|
|
|
|
2016-11-03 21:26:46 +00:00
|
|
|
def call_git_describe(prefix='', suffix=''):
|
|
|
|
cmd = 'git describe --tags --match %s[0-9]*' % prefix
|
2013-05-01 02:52:23 +00:00
|
|
|
try:
|
2019-06-05 18:53:17 +00:00
|
|
|
output = subprocess.check_output(cmd.split(), stderr=subprocess.PIPE)
|
2019-06-07 13:43:52 +00:00
|
|
|
except (OSError, subprocess.CalledProcessError):
|
2019-06-05 18:53:17 +00:00
|
|
|
return None
|
|
|
|
else:
|
|
|
|
version = output.decode('utf-8').strip().replace(prefix, '')
|
|
|
|
# A dash signifies git commit increments since parent tag.
|
2016-11-03 21:26:46 +00:00
|
|
|
if '-' in version:
|
2019-06-05 18:53:17 +00:00
|
|
|
segment = '.dev' if 'dev' in version else '.post'
|
|
|
|
version = segment.join(version.replace(suffix, '').split('-')[:2])
|
2013-05-01 02:52:23 +00:00
|
|
|
return version
|
|
|
|
|
2014-09-03 21:28:28 +00:00
|
|
|
|
2019-06-05 18:53:17 +00:00
|
|
|
def get_version(prefix='deluge-', suffix='.dev0'):
|
2013-05-01 02:52:23 +00:00
|
|
|
try:
|
2016-11-03 21:26:46 +00:00
|
|
|
with open(VERSION_FILE, 'r') as f:
|
2013-05-01 02:52:23 +00:00
|
|
|
release_version = f.readline().strip()
|
2015-08-23 18:27:14 +00:00
|
|
|
except IOError:
|
2013-05-01 02:52:23 +00:00
|
|
|
release_version = None
|
|
|
|
|
|
|
|
version = call_git_describe(prefix, suffix)
|
|
|
|
|
2015-08-23 18:27:14 +00:00
|
|
|
if not version:
|
2013-05-01 02:52:23 +00:00
|
|
|
version = release_version
|
2015-08-23 18:27:14 +00:00
|
|
|
if not version:
|
2016-11-03 21:26:46 +00:00
|
|
|
raise ValueError('Cannot find the version number!')
|
2013-05-01 02:52:23 +00:00
|
|
|
|
|
|
|
if version != release_version:
|
2016-11-03 21:26:46 +00:00
|
|
|
with open(VERSION_FILE, 'w') as f:
|
|
|
|
f.write('%s\n' % version)
|
2013-05-01 02:52:23 +00:00
|
|
|
|
|
|
|
return version
|
|
|
|
|
2016-11-16 22:18:18 +00:00
|
|
|
|
2016-11-03 21:26:46 +00:00
|
|
|
if __name__ == '__main__':
|
2019-06-05 18:53:17 +00:00
|
|
|
print(get_version())
|