Simplify the get_version method

Use post segment instead of dev for non-dev tags.
Default to 'deluge-' and '.dev0' to simplify getting version.
Refactor to use subprocess.check_output
Use deluge.common.get_version as fallback in docs conf.
This commit is contained in:
Calum Lind 2019-06-05 19:53:17 +01:00
parent ce8595e8dd
commit 5e738cf73a
2 changed files with 14 additions and 15 deletions

View File

@ -14,7 +14,6 @@ import os
import sys import sys
from datetime import date from datetime import date
import pkg_resources
from recommonmark.states import DummyStateMachine from recommonmark.states import DummyStateMachine
from recommonmark.transform import AutoStructify from recommonmark.transform import AutoStructify
from six.moves import builtins from six.moves import builtins
@ -34,7 +33,7 @@ sys.path.append(
try: try:
from version import get_version from version import get_version
except ImportError: except ImportError:
get_version = None from deluge.common import get_version
# General configuration # General configuration
@ -71,10 +70,7 @@ current_year = date.today().year
copyright = '2008-%s, Deluge Team' % current_year # noqa: A001 copyright = '2008-%s, Deluge Team' % current_year # noqa: A001
# The full version, including alpha/beta/rc tags. # The full version, including alpha/beta/rc tags.
if get_version: release = get_version()
release = get_version(prefix='deluge-', suffix='.dev0')
else:
release = pkg_resources.get_distribution('Deluge').version
# The short X.Y version. # The short X.Y version.
version = '.'.join(release.split('.', 2)[:2]) version = '.'.join(release.split('.', 2)[:2])

View File

@ -34,7 +34,7 @@
from __future__ import print_function, unicode_literals from __future__ import print_function, unicode_literals
import os import os
from subprocess import PIPE, Popen import subprocess
__all__ = ('get_version',) __all__ = ('get_version',)
@ -44,16 +44,19 @@ VERSION_FILE = os.path.join(os.path.dirname(__file__), 'RELEASE-VERSION')
def call_git_describe(prefix='', suffix=''): def call_git_describe(prefix='', suffix=''):
cmd = 'git describe --tags --match %s[0-9]*' % prefix cmd = 'git describe --tags --match %s[0-9]*' % prefix
try: try:
output = Popen(cmd.split(), stdout=PIPE, stderr=PIPE).communicate() output = subprocess.check_output(cmd.split(), stderr=subprocess.PIPE)
version = output[0].decode('utf-8').strip().replace(prefix, '') except subprocess.CalledProcessError:
if '-' in version:
version = '.dev'.join(version.replace(suffix, '').split('-')[:2])
return version
except OSError:
return None return None
else:
version = output.decode('utf-8').strip().replace(prefix, '')
# A dash signifies git commit increments since parent tag.
if '-' in version:
segment = '.dev' if 'dev' in version else '.post'
version = segment.join(version.replace(suffix, '').split('-')[:2])
return version
def get_version(prefix='', suffix=''): def get_version(prefix='deluge-', suffix='.dev0'):
try: try:
with open(VERSION_FILE, 'r') as f: with open(VERSION_FILE, 'r') as f:
release_version = f.readline().strip() release_version = f.readline().strip()
@ -75,4 +78,4 @@ def get_version(prefix='', suffix=''):
if __name__ == '__main__': if __name__ == '__main__':
print(get_version(prefix='deluge-', suffix='.dev0')) print(get_version())