Move from semver to semantic_version package

Change-Id: I6acae60e8aeb9b7599c1117281023b06a514b503
Closes-bug: #1549239
This commit is contained in:
Jedrzej Nowak 2016-02-24 12:59:56 +01:00
parent f96c5bf0d4
commit 8766f11d96
2 changed files with 15 additions and 16 deletions

View File

@ -22,7 +22,7 @@ peewee >= 2.8.0
# lupa>=1.2 # lupa>=1.2
# if you want to use complex version check in repositories # if you want to use complex version check in repositories
semver>=2.4.0 semantic_version>=2.3.1
# plugins # plugins
stevedore>=1.5.0 stevedore>=1.5.0

View File

@ -17,7 +17,7 @@ from collections import defaultdict
import errno import errno
import os import os
import semver import semantic_version
import shutil import shutil
import yaml import yaml
@ -80,9 +80,8 @@ class Repository(object):
if os.path.exists(meta_path): if os.path.exists(meta_path):
# single normal # single normal
pth = os.path.split(source)[-1] pth = os.path.split(source)[-1]
try: valid = semantic_version.validate(pth)
semver.parse(pth) if not valid:
except ValueError:
name = pth name = pth
else: else:
# if it was semver then single_path may look like # if it was semver then single_path may look like
@ -101,9 +100,8 @@ class Repository(object):
pth = pth[:-5] pth = pth[:-5]
yield RES_TYPE.Composer, pth, single_path yield RES_TYPE.Composer, pth, single_path
elif os.path.exists(os.path.join(single_path, 'meta.yaml')): elif os.path.exists(os.path.join(single_path, 'meta.yaml')):
try: valid = semantic_version.validate(pth)
semver.parse(pth) if not valid:
except ValueError:
name = pth name = pth
else: else:
# if it was semver then single_path may look like # if it was semver then single_path may look like
@ -123,9 +121,8 @@ class Repository(object):
if not os.path.isdir(single_path): if not os.path.isdir(single_path):
continue continue
for single in os.listdir(single_path): for single in os.listdir(single_path):
try: valid = semantic_version.validate(single)
semver.parse(single) if not valid:
except ValueError:
fp = os.path.join(single_path, single) fp = os.path.join(single_path, single)
raise RepositoryException( raise RepositoryException(
"Unexpected repository content " "Unexpected repository content "
@ -299,7 +296,7 @@ class Repository(object):
return os.path.join(self.fpath, spec['resource_name'], version) return os.path.join(self.fpath, spec['resource_name'], version)
found = self.iter_contents(resource_name) found = self.iter_contents(resource_name)
if version is None: if version is None:
sc = semver.compare sc = semantic_version.compare
sorted_vers = sorted(found, sorted_vers = sorted(found,
cmp=lambda a, b: sc(a['version'], cmp=lambda a, b: sc(a['version'],
b['version']), b['version']),
@ -309,14 +306,16 @@ class Repository(object):
version = sorted_vers[0]['version'] version = sorted_vers[0]['version']
else: else:
version = '{}{}'.format(version_sign, version) version = '{}{}'.format(version_sign, version)
matched = filter(lambda x: semver.match(x['version'], version), matched = filter(lambda x: semantic_version.match(version,
x['version']),
found) found)
sorted_vers = sorted(matched, sorted_vers = sorted(matched,
cmp=lambda a, b: semver.compare(a['version'], cmp=lambda a, b: semantic_version.compare(
b['version']), a['version'],
b['version']),
reverse=True) reverse=True)
version = next((x['version'] for x in sorted_vers version = next((x['version'] for x in sorted_vers
if semver.match(x['version'], version)), if semantic_version.match(version, x['version'])),
None) None)
if version is None: if version is None:
raise ResourceNotFound(spec) raise ResourceNotFound(spec)