1212
1313
1414DIST_PATH = 'dist'
15+ DIST_PATH_DELETE = 'dist_delete'
16+ CONTEXT_SETTINGS = dict (help_option_names = ['-h' , '--help' ])
1517
1618
17- @click .group ()
19+ @click .group (context_settings = CONTEXT_SETTINGS )
1820def cli ():
1921 pass
2022
2123
2224@cli .command ()
2325def build ():
26+ """ Builds the distribution files: wheels and source. """
2427 dist_path = Path (DIST_PATH )
2528 if dist_path .exists () and list (dist_path .glob ('*' )):
2629 if click .confirm ('{} is not empty - delete contents?' .format (dist_path )):
27- shutil .rmtree (dist_path )
30+ dist_path .rename (DIST_PATH_DELETE )
31+ shutil .rmtree (Path (DIST_PATH_DELETE ))
2832 dist_path .mkdir ()
2933 else :
3034 click .echo ('Aborting' )
@@ -38,22 +42,32 @@ def build():
3842@cli .command ()
3943@click .option ('--release/--no-release' , default = False )
4044def upload (release ):
45+ """ Uploads distribuition files to pypi or pypitest. """
46+ dist_path = Path (DIST_PATH )
47+ if not dist_path .exists () or not list (dist_path .glob ('*' )):
48+ print ("No distribution files found. Please run 'build' command first" )
49+ return
50+
4151 if release :
42- repository = 'pypi'
52+ args = [ 'twine' , 'upload' , 'dist/*' ]
4353 else :
44- repository = 'pypitest'
54+ repository = 'https://test.pypi.org/legacy/'
55+ args = ['twine' , 'upload' , '--repository-url' , repository , 'dist/*' ]
4556
4657 env = os .environ .copy ()
4758
48- args = ['twine' , 'upload' , '-r' , repository , 'dist/*' ]
49-
5059 p = subprocess .Popen (args , env = env )
5160 p .wait ()
5261
5362
5463@cli .command ()
5564def check ():
56- """ Checks the long description """
65+ """ Checks the long description. """
66+ dist_path = Path (DIST_PATH )
67+ if not dist_path .exists () or not list (dist_path .glob ('*' )):
68+ print ("No distribution files found. Please run 'build' command first" )
69+ return
70+
5771 subprocess .check_call (['twine' , 'check' , 'dist/*' ])
5872
5973
0 commit comments