6
6
import json
7
7
import webbrowser
8
8
import requests
9
+ import datetime
9
10
from invoke import task
11
+
10
12
from rocketsled import __version__
11
13
from monty .os import cd
12
14
13
-
14
15
"""
15
16
Deployment file to facilitate releases.
16
17
"""
17
18
18
- __author__ = "Shyue Ping Ong, Anubhav Jain"
19
-
20
- __date__ = "Sep 1, 2014"
21
-
22
19
23
20
@task
24
21
def make_doc (ctx ):
@@ -37,26 +34,55 @@ def make_doc(ctx):
37
34
38
35
39
36
@task
40
- def update_doc (ctx ):
41
- make_doc (ctx )
42
- with cd ("docs" ):
43
- ctx .run ("git add ." )
44
- ctx .run ("git commit -a -m \" Update to v{}\" " .format (__version__ ))
45
- ctx .run ("git push" )
37
+ def open_doc (ctx ):
38
+ pth = os .path .abspath ("docs/index.html" )
39
+ webbrowser .open ("file://" + pth )
46
40
47
41
48
42
@task
49
- def publish (ctx ):
50
- ctx .run ("rm dist/*.*" , warn = True )
51
- ctx .run ("python3 setup.py sdist bdist_wheel" )
52
- ctx .run ("twine upload dist/*" )
43
+ def version_check (ctx ):
44
+ with open ("setup.py" , "r" ) as f :
45
+ setup_version = None
46
+ for l in f .readlines ():
47
+ if "version = " in l :
48
+ setup_version = l .split (" " )[- 1 ]
49
+ setup_version = setup_version .replace ('"' , "" ).replace ("\n " , "" )
50
+
51
+ if setup_version is None :
52
+ raise IOError ("Could not parse setup.py for version." )
53
+
54
+ if __version__ == setup_version :
55
+ print ("Setup and init versions match eachother." )
56
+ today = datetime .date .today ().strftime ("%Y.%-m.%-d" )
57
+ if today != __version__ :
58
+ raise ValueError (f"The version { __version__ } does not match "
59
+ f"the date!" )
60
+ else :
61
+ print ("Version matches the date." )
62
+ else :
63
+ raise ValueError (f"There is a mismatch in the date between the "
64
+ f"rocketsled __init__ and the setup. Please "
65
+ f"make sure they are the same."
66
+ f"\n DIFF: { __version__ } , { setup_version } " )
67
+
53
68
54
69
@task
55
70
def update_changelog (ctx ):
71
+ version_check (ctx )
56
72
ctx .run ('github_changelog_generator hackingmaterials/rocketsled' )
57
73
74
+
75
+ @task
76
+ def publish (ctx ):
77
+ version_check (ctx )
78
+ ctx .run ("rm dist/*.* build/*" , warn = True )
79
+ ctx .run ("python3 setup.py sdist bdist_wheel" )
80
+ ctx .run ("twine upload dist/*" )
81
+
82
+
58
83
@task
59
84
def release (ctx ):
85
+ version_check (ctx )
60
86
payload = {
61
87
"tag_name" : "v" + __version__ ,
62
88
"target_commitish" : "master" ,
@@ -68,10 +94,6 @@ def release(ctx):
68
94
response = requests .post (
69
95
"https://api.github.com/repos/hackingmaterials/rocketsled/releases" ,
70
96
data = json .dumps (payload ),
71
- headers = {"Authorization" : "token " + os .environ ["GITHUB_RELEASES_TOKEN" ]})
97
+ headers = {
98
+ "Authorization" : "token " + os .environ ["GITHUB_RELEASES_TOKEN" ]})
72
99
print (response .text )
73
-
74
- @task
75
- def open_doc (ctx ):
76
- pth = os .path .abspath ("docs/index.html" )
77
- webbrowser .open ("file://" + pth )
0 commit comments