11#!/usr/bin/env python
22
3+ import argparse as argpar
34import json
45import subprocess
56
@@ -9,14 +10,17 @@ def buildBundle():
910 subprocess .run (['jlpm' , 'clean:slate' ])
1011 subprocess .run (['jlpm' , 'build:labextension' ])
1112
12- def tag (version , kind = None ):
13+ def tag (version , dryrun = False , kind = None ):
1314 """git tagging
1415 """
1516 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 )
1718
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 ])
2024
2125def pypi (bdist = True , test = False ):
2226 """release on pypi
@@ -45,10 +49,14 @@ def npmjs(dryRun=False):
4549 # build and release
4650 subprocess .run (['npm' , 'publish' , '--access' , 'public' ])
4751
48- def labExtensionVersion (version = None ):
52+ def labExtensionVersion (dryrun = False , version = None ):
4953 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 )
5260 else :
5361 # get single source of truth from the Typescript labextension
5462 with open ('package.json' ) as f :
@@ -62,7 +70,7 @@ def serverExtensionVersion():
6270 # get single source of truth from the Python serverextension
6371 return get_version ('jupyterlab_hdf/_version.py' )
6472
65- def doRelease ():
73+ def doRelease (test = False ):
6674 # do a clean build of the bundle
6775 buildBundle ()
6876
@@ -72,11 +80,21 @@ def doRelease():
7280 labExtensionVersion (version = version )
7381
7482 # tag with version and push the tag
75- tag (version = version )
83+ tag (dryrun = test , version = version )
7684
7785 # 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' ])
8098
81- if __name__ == " __main__" :
82- doRelease ()
99+ if __name__ == ' __main__' :
100+ main ()
0 commit comments