summaryrefslogtreecommitdiffstats
path: root/version.py
diff options
context:
space:
mode:
authorCalum Lind <calumlind+deluge@gmail.com>2013-05-01 04:52:23 +0200
committerCalum Lind <calumlind+deluge@gmail.com>2013-05-01 06:24:36 +0200
commit4dd6308db91a38311317ef5bd0f1bbd6788424e1 (patch)
tree1819e8899cd9335be2ff2a82cd923305b0ed5eed /version.py
parentMake sure prioritize first/last doesn't enable pieces in (diff)
downloaddeluge-4dd6308db91a38311317ef5bd0f1bbd6788424e1.tar.xz
deluge-4dd6308db91a38311317ef5bd0f1bbd6788424e1.zip
Add get_version script to automate release versions (PEP386 naming)deluge-2.0.0.dev0
Diffstat (limited to 'version.py')
-rw-r--r--version.py70
1 files changed, 70 insertions, 0 deletions
diff --git a/version.py b/version.py
new file mode 100644
index 000000000..f20fc4863
--- /dev/null
+++ b/version.py
@@ -0,0 +1,70 @@
+# -*- 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
+#
+
+__all__ = ("get_version")
+
+from subprocess import Popen, PIPE
+VERSION_FILE = "RELEASE-VERSION"
+
+def call_git_describe(prefix='', suffix=''):
+ cmd = 'git describe --tags --match %s[0-9]*' % prefix
+ try:
+ version = Popen(cmd.split(), stdout=PIPE).communicate()[0]
+ version = version.strip().replace(prefix, '')
+ if '-' in version:
+ version = '.dev'.join(version.replace(suffix,'').split('-')[:2])
+ return version
+ except:
+ return None
+
+def get_version(prefix='', suffix=''):
+ try:
+ with open(VERSION_FILE, "r") as f:
+ release_version = f.readline().strip()
+ except:
+ release_version = None
+
+ version = call_git_describe(prefix, suffix)
+
+ if version is None:
+ version = release_version
+ if version is None:
+ raise ValueError("Cannot find the version number!")
+
+ if version != release_version:
+ with open(VERSION_FILE, "w") as f:
+ f.write("%s\n" % version)
+
+ return version
+
+if __name__ == "__main__":
+ print get_version(prefix='deluge-', suffix='.dev0')