-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathincrement_version.py
More file actions
40 lines (34 loc) · 1.35 KB
/
increment_version.py
File metadata and controls
40 lines (34 loc) · 1.35 KB
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
import urllib.request
import json
from typing import Dict, Any
from calculation.version import __name__ as name
from calculation.version import __major__ as major
from calculation.version import __minor__ as minor
from calculation.version import __patch__ as patch
def update_version(reqs: list, major: bool, minor: bool, patch:bool) -> str:
version = {}
version['major'] = reqs[0]
version['minor'] = reqs[1]
version['patch'] = reqs[2]
print(f"Old Version = {version['major']}.{version['minor']}.{version['patch']}")
if patch:
version['patch'] += 1
if minor:
version['patch'] = 0
version['minor'] += 1
if major:
version['patch'] = 0
version['minor'] = 0
version['major'] += 1
new_version = str(version['major']) + "." + str(version['minor']) + "." + str(version['patch'])
return new_version
def new_version(package: str, major: bool=False, minor:bool=False, patch:bool=True) -> str:
req = urllib.request.Request(f'https://pypi.python.org/pypi/{package}/json')
r = urllib.request.urlopen(req)
if r.code == 200:
t = json.loads(r.read())
releases = t['info']['version']
if releases:
results = list(map(int, releases.split(".")))
return update_version(results,major,minor,patch)
__version__ = new_version(name, major, minor, patch)