From de039e914fc798269fe559a3a517ae648feaaabd Mon Sep 17 00:00:00 2001 From: Matt Davis Date: Thu, 8 Mar 2018 23:35:06 -0800 Subject: [PATCH] version_helper sanity fixes --- packaging/release/tests/version_helper_test.py | 1 + packaging/release/versionhelper/version_helper.py | 13 +++++++------ 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/packaging/release/tests/version_helper_test.py b/packaging/release/tests/version_helper_test.py index f928d4b1eef..054ba377a20 100644 --- a/packaging/release/tests/version_helper_test.py +++ b/packaging/release/tests/version_helper_test.py @@ -3,6 +3,7 @@ import pytest from packaging.version import InvalidVersion from versionhelper.version_helper import AnsibleVersionMunger + @pytest.mark.parametrize('version,revision,output_propname,expected', [ ('2.5.0dev1', None, 'raw', '2.5.0dev1'), ('2.5.0', None, 'raw', '2.5.0'), diff --git a/packaging/release/versionhelper/version_helper.py b/packaging/release/versionhelper/version_helper.py index e3e4513e695..6942e7fa516 100644 --- a/packaging/release/versionhelper/version_helper.py +++ b/packaging/release/versionhelper/version_helper.py @@ -5,6 +5,7 @@ import sys from packaging.version import Version, VERSION_PATTERN + class AnsibleVersionMunger(object): tag_offsets = dict( dev=0, @@ -52,7 +53,6 @@ class AnsibleVersionMunger(object): # it is a pre/dev release, include the tag value with a ~ return '{base_version}~{tag_value}'.format(base_version=self.base_version, tag_value=tag_value) - @property def deb_release(self): return '1' if self._revision is None else str(self._revision) @@ -85,7 +85,7 @@ class AnsibleVersionMunger(object): if not tag_type: if self._revision is None: self._revision = 1 - return '{revision}'.format(base_version=self.base_version, revision=self._revision) + return '{revision}'.format(revision=self._revision) # cleanse tag value in case it starts with . tag_value = tag_value.strip('.') @@ -101,7 +101,7 @@ class AnsibleVersionMunger(object): else: pkgrel = self._revision - return '{pkgrel}.{tag_value}'.format(pkgrel=pkgrel, tag_value=tag_value, base_version=self.base_version) + return '{pkgrel}.{tag_value}'.format(pkgrel=pkgrel, tag_value=tag_value) @property def raw(self): @@ -115,7 +115,8 @@ class AnsibleVersionMunger(object): # return the x.y version without any other modifiers present @property def major_version(self): - return re.match('^(\d+.\d+)', self._raw_version).group(1) + return re.match(r'^(\d+.\d+)', self._raw_version).group(1) + def main(): parser = argparse.ArgumentParser(description='Extract/transform Ansible versions to various packaging formats') @@ -160,10 +161,10 @@ def main(): elif args.rpmrelease: print(v.rpm_release) elif args.all: - props = [name for (name,impl) in vars(AnsibleVersionMunger).items() if isinstance(impl, property)] + props = [name for (name, impl) in vars(AnsibleVersionMunger).items() if isinstance(impl, property)] for propname in props: print('{0}: {1}'.format(propname, getattr(v, propname))) if __name__ == '__main__': - main() \ No newline at end of file + main()