1+ #!/usr/bin/env python3
2+
13import os
24import shutil
35
46
57def main ():
68 # pathes
79 here = os .path .abspath (os .path .dirname (__file__ ))
8- sphinx = os .path .join (here , 'sphinx/' )
9- docs = os .path .join (here , 'docs/' )
10- html_source = os .path .join (here , 'sphinx/_build/html/' )
11- html_target = os .path .join (here , 'docs/html/' )
12- epub_source = os .path .join (here , 'sphinx/_build/epub/' )
13- epub_target = os .path .join (here , 'docs/epub/' )
10+ root = os .path .abspath (os .path .join (here , '..' ))
11+ sphinx = os .path .join (root , 'sphinx/' )
12+ docs = os .path .join (root , 'docs/' )
13+ dist = os .path .join (root , 'dist/' )
14+ html_source = os .path .join (root , 'sphinx/_build/html/' )
15+ html_target = os .path .join (root , 'docs/html/' )
16+ epub_source = os .path .join (root , 'sphinx/_build/epub/' )
17+ epub_target = os .path .join (root , 'docs/epub/' )
1418 rst_challenges = os .path .join (sphinx , 'challenges.rst' )
1519 rst_modules = os .path .join (sphinx , 'modules.rst' )
1620 rst_hello = os .path .join (sphinx , 'HelloWorld.rst' )
@@ -20,6 +24,9 @@ def main():
2024 'release.py '
2125 genhtml = 'make html'
2226 genepub = 'make epub'
27+ gendist = './setup.py sdist'
28+ test = 'twine upload dist/* -r testpypi'
29+ upload = 'twine upload dist/* -r pypi'
2330
2431 # execute
2532 if os .path .exists (docs ):
@@ -28,7 +35,13 @@ def main():
2835 if not os .path .exists (docs ):
2936 os .makedirs (docs )
3037
31- with cd (here ):
38+ if os .path .exists (dist ):
39+ shutil .rmtree (dist )
40+
41+ if not os .path .exists (dist ):
42+ os .makedirs (dist )
43+
44+ with cd (root ):
3245 os .system (genapi )
3346
3447 with cd (sphinx ):
@@ -41,11 +54,28 @@ def main():
4154
4255 os .rename (epub_source , epub_target )
4356
57+ with cd (root ):
58+ os .system (gendist )
59+
4460 # cleanup autogenerated rst files
4561 os .remove (rst_challenges )
4662 os .remove (rst_hello )
4763 os .remove (rst_modules )
4864
65+ # Upload test
66+ print ('Trying upload on TESTPYPI' )
67+ with cd (root ):
68+ os .system (test )
69+
70+ var = input ('Uploading to live server? (y/n)' )
71+ if var .strip () == 'y' :
72+ with cd (root ):
73+ os .system (upload )
74+ else :
75+ print ('NOT UPLOADING. Please run the command manually!' )
76+ print (upload )
77+
78+
4979class cd :
5080 """Context manager for changing the current working directory"""
5181
@@ -59,5 +89,6 @@ def __enter__(self):
5989 def __exit__ (self , etype , value , traceback ):
6090 os .chdir (self .savedPath )
6191
92+
6293if __name__ == '__main__' :
6394 main ()
0 commit comments