-
-
Notifications
You must be signed in to change notification settings - Fork 4
/
analyser.py
61 lines (47 loc) · 1.53 KB
/
analyser.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
# -*- coding: utf-8 -*-
from pkg_resources import parse_version
def uptodate_analysis(pkginfo, pypiinfo):
"""analyse if used version is current:
result:
if empty then most recent
if 'cfg' in result, some cfg is newer
if 'pypifinal' in result, some pypi final release is newer
if 'pypiprerelease' in result, some pypi prerelease is newer
"""
result = []
if is_cfg_newer(pkginfo):
result.append("cfg")
newer = is_pypi_newer(pypiinfo)
if newer:
result.append(newer)
return result
def is_cfgidx_newer(pkginfo, target_idx):
"""check if a given idx (>0) version is newer than the firstversion
returns boolean
"""
vcur = None
for idx, key in enumerate(pkginfo):
version = pkginfo[key]["v"]
if not version:
continue
if idx == 0:
vcur = parse_version(version)
if idx == target_idx:
return parse_version(version) > vcur
return False
def is_cfg_newer(pkginfo):
"""checks if one of the cfg is newer
returns boolean
"""
for idx in range(1, len(pkginfo)):
if is_cfgidx_newer(pkginfo, idx):
return True
TEST_FINALS = set(["major", "minor", "bugfix"])
TEST_PRERELEASE = set(["majorpre", "minorpre", "bugfixpre"])
def is_pypi_newer(pypiinfo):
keys = {_ for _ in pypiinfo if pypiinfo.get(_, False)}
if TEST_FINALS.intersection(keys):
return "pypifinal"
if TEST_PRERELEASE.intersection(keys):
return "pypiprerelease"
return False