2121####################################################################################################
2222
2323from pathlib import Path
24+ import re
25+ import shutil
2426
2527from invoke import task
2628
@@ -80,18 +82,35 @@ def find_package(ctx, name):
8082@task ()
8183def update_git_sha (ctx ):
8284 result = ctx .run ('git describe --tags --abbrev=0 --always' , hide = 'out' )
85+ tag = result .stdout .strip ()
86+ if tag .startswith ('v' ):
87+ version = tag [1 :]
88+ else :
89+ version = tag
90+ if not re .match ('\d+(\.\d+(\.\d+)?)?' , version ):
91+ raise ValueError ('Invalid version {}' .format (version ))
92+ result = ctx .run ('git rev-parse HEAD' , hide = 'out' )
8393 sha = result .stdout .strip ()
94+ print (sha )
95+ print (tag )
96+ print (version )
8497 filename = Path (ctx .Package , '__init__.py' )
8598 with open (str (filename ) + '.in' , 'r' ) as fh :
8699 lines = fh .readlines ()
87100 with open (filename , 'w' ) as fh :
88101 for line in lines :
89102 if '@' in line :
103+ line = line .replace ('@VERSION@' , version )
104+ line = line .replace ('@GIT_TAG@' , tag )
90105 line = line .replace ('@GIT_SHA@' , sha )
91106 fh .write (line )
92107
93108####################################################################################################
94109
110+ def clean (ctx ):
111+ for directory in ('build' , 'dist' ):
112+ shutil .rmtree (directory )
113+
95114def show_python_site (ctx ):
96115 ctx .run ('python3 -m site' )
97116
@@ -102,3 +121,17 @@ def build(ctx):
102121@task (build )
103122def install (ctx ):
104123 ctx .run ('python3 setup.py install' )
124+
125+ @task (build )
126+ def install (ctx ):
127+ ctx .run ('python3 setup.py install' )
128+
129+ @task (clean , build )
130+ def wheel (ctx ):
131+ ctx .run ('python3 setup.py bdist_wheel' )
132+
133+ @task (build )
134+ def upload (ctx ):
135+ ctx .run ('twine register dist/*whl' )
136+ ctx .run ('gpg --detach-sign -a dist/*whl' )
137+ ctx .run ('twine upload dist/*' )
0 commit comments