77
88import typing
99
10+
1011def main (
1112 package : str ,
1213 from_manifest : bool ,
1314 path_manifest : str ,
14- * args , ** kwargs
15+ source : str ,
16+ version : str
1517) -> bool :
1618 # for all the files that are called code.py in the components folder
1719 # stamp on the second line of the file by not overwriting the first line
18- for root , dirs , files in os .walk ("./py/components/" ):
20+ for root , dirs , files in os .walk (source ):
1921 for file in files :
2022 if file == "code.py" :
2123 path = os .path .join (root , file )
2224 with open (path , "r" ) as f :
2325 lines = f .readlines ()
24- # check if the line # r: package_name is already in the first 10 lines
26+ # check if the line # r: package_name is already in the first 10 lines, erase it
2527 if any ([re .search (r"# r: .+==" , line ) for line in lines [:10 ]]):
2628 print (f"File { path } is already stamped with the package version." )
27- return False
29+ lines = [line for line in lines if not re .search (r"# r: .+==" , line )]
30+
2831 with open (path , "w" ) as f :
2932 f .write (lines [0 ])
30- f .write (f"# r: { package } =={ kwargs [ ' version' ] } \n " )
33+ f .write (f"# r: { package } =={ version } \n " )
3134 for line in lines [1 :]:
3235 f .write (line )
3336 print ("Done stamping components with version number of the pypi package." )
@@ -46,7 +49,7 @@ def main(
4649 parser .add_argument (
4750 "--source" ,
4851 type = str ,
49- required = False ,
52+ required = True ,
5053 default = "./py/components/" ,
5154 help = "The path to component folders."
5255 )
@@ -59,7 +62,7 @@ def main(
5962 parser .add_argument (
6063 "--path-manifest" ,
6164 type = str ,
62- required = False ,
65+ required = True ,
6366 default = "./manifest.yml" ,
6467 help = "The path to the manifest file."
6568 )
@@ -137,6 +140,7 @@ def main(
137140 package = args .package ,
138141 from_manifest = args .from_manifest ,
139142 path_manifest = args .path_manifest ,
143+ source = args .source ,
140144 version = _version
141145 )
142146
0 commit comments