forked from policratus/pupyl
-
Notifications
You must be signed in to change notification settings - Fork 0
/
version
executable file
·135 lines (112 loc) · 3.37 KB
/
version
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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
#!/usr/bin/env python3
"""Updates pupyl version."""
import re
import argparse
from os.path import join
from termcolor import cprint
with open('.version', 'rt') as VERSION_READ:
CURRENT_VERSION = VERSION_READ.read()
PARSER = argparse.ArgumentParser(
prog='Pupyl version updater.',
description='Updates pupyl version on entire library.'
)
PARSER.add_argument(
'version',
metavar='version',
type=str,
nargs=1,
help='Updates the current version of pupyl throughout the library.'
)
PARSER.add_argument(
'--patch',
help='Defines it as a patch update.',
action='store_true'
)
PARSER.add_argument(
'--minor',
help='Defines it as a minor update.',
action='store_true'
)
PARSER.add_argument(
'--major',
help='Defines it as a major update.',
action='store_true'
)
ARGUMENTS = PARSER.parse_args()
VERSION = ARGUMENTS.version[0]
SUITABLE_VERSION = CURRENT_VERSION.split('.')
if ARGUMENTS.patch:
COMPARISON_VERSION = '.'.join(
[
SUITABLE_VERSION[0][1:],
SUITABLE_VERSION[1],
str(int(SUITABLE_VERSION[2]) + 1)
]
)
elif ARGUMENTS.minor:
COMPARISON_VERSION = '.'.join(
[
SUITABLE_VERSION[0][1:],
str(int(SUITABLE_VERSION[1]) + 1),
'0'
]
)
elif ARGUMENTS.major:
COMPARISON_VERSION = '.'.join(
[
str(int(SUITABLE_VERSION[0][1:]) + 1),
'0',
'0'
]
)
if VERSION == COMPARISON_VERSION:
with open(join('pupyl', 'search.py')) as MAIN_MODULE, \
open('setup.py') as SETUP_MODULE, \
open(join('conda', 'meta.yaml')) as CONDA_META, \
open(join('docs', 'source', 'conf.py')) as DOCS:
FILE_MODULE = MAIN_MODULE.read()
SETUP_FILE = SETUP_MODULE.read()
CONDA_FILE = CONDA_META.read()
DOCS_CONF_FILE = DOCS.read()
NEW_VERSION = f"__version__ = 'v{VERSION}'"
MAIN_MODULE_MODIFIED = re.sub(
r'^.*\b(\w*__version__\w*)\b.*',
NEW_VERSION,
FILE_MODULE,
flags=re.MULTILINE
)
SETUP_MODULE_MODIFIED = re.sub(
r'^.*\b(\w*version\w*)\b.*',
f' version="{VERSION.replace("rc", "rc0")}",',
SETUP_FILE,
flags=re.MULTILINE
)
CONDA_META_MODIFIED = re.sub(
r'^.*\b(\w*\sversion\w*)\b.*',
'{% set version = "' + f'{VERSION}' + '"%}',
CONDA_FILE,
flags=re.MULTILINE
)
DOCS_CONF_FILE_MODIFIED = re.sub(
r'(release?)\b.*',
f"release = '{VERSION}'",
DOCS_CONF_FILE,
count=1
)
with open(join('pupyl', 'search.py'), 'w') as MAIN_MODULE, \
open('setup.py', 'w') as SETUP_MODULE, \
open(join('conda', 'meta.yaml'), 'w') as CONDA_META, \
open(join('docs', 'source', 'conf.py'), 'w') as DOCS, \
open('.version', 'w') as VERSION_FILE:
MAIN_MODULE.write(MAIN_MODULE_MODIFIED)
SETUP_MODULE.write(SETUP_MODULE_MODIFIED)
CONDA_META.write(CONDA_META_MODIFIED)
DOCS.write(DOCS_CONF_FILE_MODIFIED)
VERSION_FILE.write(f'v{VERSION}')
cprint(f'Version updated to {VERSION}', 'blue')
else:
cprint(
f"Version {VERSION} is not valid with "
f'next version {COMPARISON_VERSION}',
'red'
)