-
Notifications
You must be signed in to change notification settings - Fork 5
/
make.py
138 lines (106 loc) · 3.84 KB
/
make.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
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
136
137
138
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
Created on Wed Jul 14 11:54:33 2021
@author: Jakob Lass
Tool to replace makefile in order to fully port development to windows
"""
import argparse
from ntpath import join
import os,glob
from MJOLNIR.Data.DataSet import OxfordList
possibleArguments = ['test', 'tutorials', 'wheel', 'html', 'upload', 'testVersion', 'version']
parser = argparse.ArgumentParser(description="Make tool replacing linux Makefile.")
parser.add_argument("task", nargs='?', default='help', type=str, help="Type of task to be performed. Possible tasks are: {}. Run without argument to see help menu.".format(OxfordList(possibleArguments)))
parser.add_argument("version", nargs='?',default=None, type=str, help="Version number to be created. Default is previous plus 1, i.e. x.y.z -> x.y.z+1")
def callHelp(parser=parser):
parser.print_help()
def test():
os.system("python -m pytest -vv test")
# def cleanTutorialFolders():
# folders = [f.path for f in os.scandir(os.path.join('docs','Tutorials')) if f.is_dir()]
# print('Cleaning tutorial folders: '+OxfordList(folders))
# for folder in folders:
# os.system('python clean.py '+folder)
def generateTutorials():
os.system('python '+str(os.path.join('docs','tutorials.py')))
def makeHTML():
print('Creating HTML through Sphinx')
os.system("sphinx-build docs build")
def makeWheel():
os.system("python setup.py sdist")
def getLatestBuild():
list_of_files = glob.glob(os.path.join('dist','*')) # * means all if need specific format then *.csv
return max(list_of_files, key=os.path.getctime)
def getCurrentVersion():
string = getLatestBuild()
versionList = string.split('-')[1].split('.')[:-2]
if 'post' in versionList[-1]:
versionList[-1] = versionList[-1].replace('post','')
adder = 'post'
else:
adder = ''
version = [int(x) for x in versionList]
if adder != '':
version[-1]=adder+str(version[-1]+1)
else:
version[-1]+=1
return '.'.join([str(x) for x in version])
def uploadPyPi(server='testpypi'):
build = getLatestBuild()
print('Uploading ' + str(build) + ' to '+server)
os.system('twine upload {} -r {}'.format(build,server))
def upload():
uploadPyPi(server='testpypi')
uploadPyPi(server='pypi')
def update(version):
os.system('python Update.py '+version)
def makeTutorials():
# cleanTutorialFolders()
generateTutorials()
makeHTML()
args = parser.parse_args()
if args.task == '' or args.task.lower() == 'help':
callHelp()
elif args.task.lower() == 'test':
test()
elif args.task.lower() == 'tutorials':
makeTutorials()
elif args.task.lower() == 'wheel':
makeWheel()
elif args.task.lower() == 'upload':
upload()
elif args.task.lower() == 'testversion':
if args.version is None:
version = getCurrentVersion()
else:
version = args.version
print('Creating test version '+version)
update(version=version)
makeWheel()
uploadPyPi(server='testpypi')
elif args.task.lower() == 'html':
makeHTML()
elif args.task.lower() == 'version':
if args.version is None:
version = getCurrentVersion()
else:
version = args.version
print('Creating version '+version)
update(version=version)
makeTutorials()
addFiles = ['setup.py',
os.path.join('docs','conf.py'),
os.path.join('docs','Tutorials','*'),
os.path.join('docs','index.rst'),
os.path.join('MJOLNIR','__init__.py'),
]
os.system("git add {}".format(' '.join(addFiles)))
os.system('git commit -m "Update version"')
os.system('git tag -a {0} -m "{0}"'.format(version))
makeWheel()
os.system("git push")
os.system("git push --tags")
else:
print('Provided argument not understood. Received',args.task,'\n\n')
callHelp()