1
1
#!/usr/bin/env python
2
2
3
+ import argparse as argpar
3
4
import json
4
5
import subprocess
5
6
@@ -9,14 +10,17 @@ def buildBundle():
9
10
subprocess .run (['jlpm' , 'clean:slate' ])
10
11
subprocess .run (['jlpm' , 'build:labextension' ])
11
12
12
- def tag (version , kind = None ):
13
+ def tag (version , dryrun = False , kind = None ):
13
14
"""git tagging
14
15
"""
15
16
kw = {'version' : version , 'kind' : kind }
16
- tag = " {kind}_v{version}" .format (** kw ) if kind else " v{version}" .format (** kw )
17
+ tag = ' {kind}_v{version}' .format (** kw ) if kind else ' v{version}' .format (** kw )
17
18
18
- subprocess .run (['git' , 'tag' , tag ])
19
- subprocess .run (['git' , 'push' , 'origin' , tag ])
19
+ if dryrun :
20
+ print ("Would tag: {}" .format (tag ))
21
+ else :
22
+ subprocess .run (['git' , 'tag' , tag ])
23
+ subprocess .run (['git' , 'push' , 'origin' , tag ])
20
24
21
25
def pypi (bdist = True , test = False ):
22
26
"""release on pypi
@@ -45,10 +49,14 @@ def npmjs(dryRun=False):
45
49
# build and release
46
50
subprocess .run (['npm' , 'publish' , '--access' , 'public' ])
47
51
48
- def labExtensionVersion (version = None ):
52
+ def labExtensionVersion (dryrun = False , version = None ):
49
53
if version :
50
- # force the labextension version to match the supplied version
51
- subprocess .run (['npm' , '--no-git-tag-version' , 'version' , version , '--force' , '--allow-same-version' ])
54
+ force_ver_cmd = ['npm' , '--no-git-tag-version' , 'version' , version , '--force' , '--allow-same-version' ]
55
+ if dryrun :
56
+ print ("Would force npm version with: {}" .format (' ' .join (force_ver_cmd )))
57
+ else :
58
+ # force the labextension version to match the supplied version
59
+ subprocess .run (force_ver_cmd )
52
60
else :
53
61
# get single source of truth from the Typescript labextension
54
62
with open ('package.json' ) as f :
@@ -62,7 +70,7 @@ def serverExtensionVersion():
62
70
# get single source of truth from the Python serverextension
63
71
return get_version ('jupyterlab_hdf/_version.py' )
64
72
65
- def doRelease ():
73
+ def doRelease (test = False ):
66
74
# do a clean build of the bundle
67
75
buildBundle ()
68
76
@@ -72,11 +80,21 @@ def doRelease():
72
80
labExtensionVersion (version = version )
73
81
74
82
# tag with version and push the tag
75
- tag (version = version )
83
+ tag (dryrun = test , version = version )
76
84
77
85
# release to pypi and npmjs
78
- pypi ()
79
- npmjs ()
86
+ pypi (test = test )
87
+ npmjs (dryRun = test )
88
+
89
+ def main ():
90
+ parser = argpar .ArgumentParser ()
91
+
92
+ parser .add_argument ('--test' , action = 'store_true' ,
93
+ help = 'Release to Pypi test server; performs a dryrun of all other release actions' )
94
+
95
+ parsed = vars (parser .parse_args ())
96
+
97
+ doRelease (test = parsed ['test' ])
80
98
81
- if __name__ == " __main__" :
82
- doRelease ()
99
+ if __name__ == ' __main__' :
100
+ main ()
0 commit comments