2424def normalize (name ):
2525 return re .sub (r"[-_.]+" , "-" , name ).lower ()
2626
27- CHANGELOGS_DIR = str (Path (__file__ ).parent / 'changelogs' )
27+
28+ CHANGELOGS_DIR = str (Path (__file__ ).parent / "changelogs" )
2829assert Path (CHANGELOGS_DIR ).is_dir ()
2930
3031
3132class Package (object ):
3233 # SourceForge Wiki syntax:
33- PATTERN = r' \[([a-zA-Z\-\:\/\.\_0-9]*)\]\(([^\]\ ]*)\) \| ([^\|]*) \| ([^\|]*)'
34+ PATTERN = r" \[([a-zA-Z\-\:\/\.\_0-9]*)\]\(([^\]\ ]*)\) \| ([^\|]*) \| ([^\|]*)"
3435 # Google Code Wiki syntax:
35- PATTERN_OLD = r' \[([a-zA-Z\-\:\/\.\_0-9]*) ([^\]\ ]*)\] \| ([^\|]*) \| ([^\|]*)'
36+ PATTERN_OLD = r" \[([a-zA-Z\-\:\/\.\_0-9]*) ([^\]\ ]*)\] \| ([^\|]*) \| ([^\|]*)"
3637
3738 def __init__ (self ):
3839 self .name = None
@@ -61,26 +62,23 @@ def to_wiki(self):
6162 def upgrade_wiki (self , other ):
6263 # wheel replace '-' per '_' in package name
6364 assert (
64- self .name .replace ('-' , '_' ).lower ()
65- == other .name .replace ('-' , '_' ).lower ()
65+ self .name .replace ("-" , "_" ).lower () == other .name .replace ("-" , "_" ).lower ()
6666 )
6767 return f" * [{ self .name } ]({ self .url } ) { other .version } → { self .version } ({ self .description } )\r \n "
6868
6969
7070class PackageIndex (object ):
71- WINPYTHON_PATTERN = (
72- r'\#\# WinPython\-*[0-9b-t]* ([0-9\.a-zA-Z]*)'
73- )
74- TOOLS_LINE = '### Tools'
75- PYTHON_PACKAGES_LINE = '### Python packages'
76- HEADER_LINE1 = 'Name | Version | Description'
77- HEADER_LINE2 = '-----|---------|------------'
71+ WINPYTHON_PATTERN = r"\#\# WinPython\-*[0-9b-t]* ([0-9\.a-zA-Z]*)"
72+ TOOLS_LINE = "### Tools"
73+ PYTHON_PACKAGES_LINE = "### Python packages"
74+ HEADER_LINE1 = "Name | Version | Description"
75+ HEADER_LINE2 = "-----|---------|------------"
7876
7977 def __init__ (
8078 self ,
8179 version ,
8280 basedir = None ,
83- flavor = '' ,
81+ flavor = "" ,
8482 architecture = 64 ,
8583 ):
8684 self .version = version
@@ -92,19 +90,17 @@ def __init__(
9290 self .from_file (basedir )
9391
9492 def from_file (self , basedir ):
95- fname = str (Path (CHANGELOGS_DIR ) /
96- f'WinPython{ self .flavor } -{ self .architecture } bit-{ self .version } .md' )
93+ fname = str (
94+ Path (CHANGELOGS_DIR )
95+ / f"WinPython{ self .flavor } -{ self .architecture } bit-{ self .version } .md"
96+ )
9797
98- with open (
99- fname , 'r'
100- ) as fdesc : # python3 doesn't like 'rb'
98+ with open (fname , "r" ) as fdesc : # python3 doesn't like 'rb'
10199 text = fdesc .read ()
102100 self .from_text (text )
103101
104102 def from_text (self , text ):
105- version = re .match (
106- self .WINPYTHON_PATTERN + self .flavor , text
107- ).groups ()[0 ]
103+ version = re .match (self .WINPYTHON_PATTERN + self .flavor , text ).groups ()[0 ]
108104 assert version == self .version
109105 tools_flag = False
110106 python_flag = False
@@ -120,21 +116,17 @@ def from_text(self, text):
120116 elif line in (
121117 self .HEADER_LINE1 ,
122118 self .HEADER_LINE2 ,
123- ' <details>' ,
124- ' </details>'
119+ " <details>" ,
120+ " </details>" ,
125121 ):
126122 continue
127123 if tools_flag or python_flag :
128124 package = Package ()
129125 package .from_text (line )
130126 if tools_flag :
131- self .other_packages [
132- package .name
133- ] = package
127+ self .other_packages [package .name ] = package
134128 else :
135- self .python_packages [
136- package .name
137- ] = package
129+ self .python_packages [package .name ] = package
138130
139131
140132def diff_package_dicts (dict1_in , dict2_in ):
@@ -144,9 +136,9 @@ def diff_package_dicts(dict1_in, dict2_in):
144136 dict1 = {}
145137 dict2 = {}
146138 for key in dict1_in :
147- dict1 [key .replace ('-' , '_' ).lower ()] = dict1_in [key ]
139+ dict1 [key .replace ("-" , "_" ).lower ()] = dict1_in [key ]
148140 for key in dict2_in :
149- dict2 [key .replace ('-' , '_' ).lower ()] = dict2_in [key ]
141+ dict2 [key .replace ("-" , "_" ).lower ()] = dict2_in [key ]
150142 set1 , set2 = set (dict1 .keys ()), set (dict2 .keys ())
151143 # New packages
152144 new = sorted (set2 - set1 )
@@ -155,46 +147,35 @@ def diff_package_dicts(dict1_in, dict2_in):
155147 for name in new :
156148 package = dict2 [name ]
157149 text += package .to_wiki ()
158- text += ' \r \n '
150+ text += " \r \n "
159151 # Upgraded packages
160152 upgraded_list = []
161153 for name in sorted (set1 & set2 ):
162154 package1 = dict1 [name ]
163155 package2 = dict2 [name ]
164156 if package1 .version != package2 .version :
165- upgraded_list .append (
166- package2 .upgrade_wiki (package1 )
167- )
157+ upgraded_list .append (package2 .upgrade_wiki (package1 ))
168158 if upgraded_list :
169- text += (
170- "Upgraded packages:\r \n \r \n " + f"{ '' .join (upgraded_list )} " + "\r \n "
171- )
159+ text += "Upgraded packages:\r \n \r \n " + f"{ '' .join (upgraded_list )} " + "\r \n "
172160 # Removed packages
173161 removed = sorted (set1 - set2 )
174162 if removed :
175163 text += "Removed packages:\r \n \r \n "
176164 for name in removed :
177165 package = dict1 [name ]
178166 text += package .to_wiki ()
179- text += ' \r \n '
167+ text += " \r \n "
180168 return text
181169
182170
183- def find_closer_version (
184- version1 , basedir = None , flavor = '' , architecture = 64
185- ):
171+ def find_closer_version (version1 , basedir = None , flavor = "" , architecture = 64 ):
186172 """Find version which is the closest to `version`"""
187- builddir = str (Path (basedir ) / f' bu{ flavor } ' )
173+ builddir = str (Path (basedir ) / f" bu{ flavor } " )
188174 func = lambda name : re .match (
189- r'WinPython%s-%sbit-([0-9\.]*)\.(txt|md)'
190- % (flavor , architecture ),
175+ r"WinPython%s-%sbit-([0-9\.]*)\.(txt|md)" % (flavor , architecture ),
191176 name ,
192177 )
193- versions = [
194- func (name ).groups ()[0 ]
195- for name in os .listdir (builddir )
196- if func (name )
197- ]
178+ versions = [func (name ).groups ()[0 ] for name in os .listdir (builddir ) if func (name )]
198179 try :
199180 index = versions .index (version1 )
200181 except ValueError :
@@ -209,7 +190,7 @@ def compare_package_indexes(
209190 version2 ,
210191 version1 = None ,
211192 basedir = None ,
212- flavor = '' ,
193+ flavor = "" ,
213194 flavor1 = None ,
214195 architecture = 64 ,
215196):
@@ -222,7 +203,7 @@ def compare_package_indexes(
222203 architecture = architecture ,
223204 )
224205 flavor1 = flavor1 if flavor1 is not None else flavor
225- text = ' \r \n ' .join (
206+ text = " \r \n " .join (
226207 [
227208 f"## History of changes for WinPython-{ architecture } bit { version2 + flavor } " ,
228209 "" ,
@@ -245,50 +226,36 @@ def compare_package_indexes(
245226 flavor = flavor ,
246227 architecture = architecture ,
247228 )
248- tools_text = diff_package_dicts (
249- pi1 .other_packages , pi2 .other_packages
250- )
229+ tools_text = diff_package_dicts (pi1 .other_packages , pi2 .other_packages )
251230 if tools_text :
252- text += (
253- PackageIndex .TOOLS_LINE
254- + '\r \n \r \n '
255- + tools_text
256- )
257- py_text = diff_package_dicts (
258- pi1 .python_packages , pi2 .python_packages
259- )
231+ text += PackageIndex .TOOLS_LINE + "\r \n \r \n " + tools_text
232+ py_text = diff_package_dicts (pi1 .python_packages , pi2 .python_packages )
260233 if py_text :
261- text += (
262- PackageIndex .PYTHON_PACKAGES_LINE
263- + '\r \n \r \n '
264- + py_text
265- )
266- text += '\r \n </details>\r \n * * *\r \n '
234+ text += PackageIndex .PYTHON_PACKAGES_LINE + "\r \n \r \n " + py_text
235+ text += "\r \n </details>\r \n * * *\r \n "
267236 return text
268237
269238
270- def _copy_all_changelogs (
271- version , basedir , flavor = '' , architecture = 64
272- ):
273- basever = '.' .join (version .split ('.' )[:2 ])
239+ def _copy_all_changelogs (version , basedir , flavor = "" , architecture = 64 ):
240+ basever = "." .join (version .split ("." )[:2 ])
274241 for name in os .listdir (CHANGELOGS_DIR ):
275242 if re .match (
276- r' WinPython%s-%sbit-%s([0-9\.]*)\.(txt|md)'
243+ r" WinPython%s-%sbit-%s([0-9\.]*)\.(txt|md)"
277244 % (flavor , architecture , basever ),
278245 name ,
279246 ):
280247 shutil .copyfile (
281248 str (Path (CHANGELOGS_DIR ) / name ),
282- str (Path (basedir ) / f' bu{ flavor } ' / name ),
249+ str (Path (basedir ) / f" bu{ flavor } " / name ),
283250 )
284251
285252
286253def write_changelog (
287254 version2 ,
288255 version1 = None ,
289256 basedir = None ,
290- flavor = '' ,
291- release_level = '' ,
257+ flavor = "" ,
258+ release_level = "" ,
292259 architecture = 64 ,
293260):
294261 """Write changelog between version1 and version2 of WinPython"""
@@ -299,7 +266,7 @@ def write_changelog(
299266 architecture = architecture ,
300267 )
301268 print (
302- ' comparing_package_indexes' ,
269+ " comparing_package_indexes" ,
303270 version2 ,
304271 basedir ,
305272 flavor ,
@@ -312,24 +279,19 @@ def write_changelog(
312279 flavor = flavor ,
313280 architecture = architecture ,
314281 )
315- fname = str (Path (basedir ) /
316- f'bu{ flavor } ' /
317- f'WinPython{ flavor } -{ architecture } bit-{ version2 } _History.md' )
318-
282+ fname = str (
283+ Path (basedir )
284+ / f"bu{ flavor } "
285+ / f"WinPython{ flavor } -{ architecture } bit-{ version2 } _History.md"
286+ )
319287
320- with open (
321- fname , 'w' , encoding = 'utf-8-sig'
322- ) as fdesc : # python 3 need
288+ with open (fname , "w" , encoding = "utf-8-sig" ) as fdesc : # python 3 need
323289 fdesc .write (text )
324290 # Copy to winpython/changelogs
325- shutil .copyfile (
326- fname , str (Path (CHANGELOGS_DIR ) / Path (fname ).name )
327- )
291+ shutil .copyfile (fname , str (Path (CHANGELOGS_DIR ) / Path (fname ).name ))
328292
329293
330- def test_parse_package_index_wiki (
331- version , basedir = None , flavor = '' , architecture = 64
332- ):
294+ def test_parse_package_index_wiki (version , basedir = None , flavor = "" , architecture = 64 ):
333295 """Parse the package index Wiki page"""
334296 pi = PackageIndex (
335297 version ,
@@ -341,16 +303,14 @@ def test_parse_package_index_wiki(
341303 utils .print_box ("Tools:" )
342304 for package in pi .other_packages .values ():
343305 print (package )
344- print ('' )
306+ print ("" )
345307 utils .print_box ("Python packages:" )
346308 for package in pi .python_packages .values ():
347309 print (package )
348- print ('' )
310+ print ("" )
349311
350312
351- def test_compare (
352- basedir , version2 , version1 , architecture = 64
353- ):
313+ def test_compare (basedir , version2 , version1 , architecture = 64 ):
354314 print (
355315 compare_package_indexes (
356316 basedir ,
@@ -361,23 +321,24 @@ def test_compare(
361321 )
362322
363323
364- if __name__ == ' __main__' :
324+ if __name__ == " __main__" :
365325 print (
366326 compare_package_indexes (
367- version2 = '3.7.4.0' ,
368- version1 = '3.7.2.0' ,
369- basedir = r'C:\WinP\bd37' ,
370- flavor = 'Zero' ,
371- flavor1 = 'Zero' ,
372- architecture = 32
373- ))
327+ version2 = "3.7.4.0" ,
328+ version1 = "3.7.2.0" ,
329+ basedir = r"C:\WinP\bd37" ,
330+ flavor = "Zero" ,
331+ flavor1 = "Zero" ,
332+ architecture = 32 ,
333+ )
334+ )
374335 write_changelog (
375- version2 = ' 3.7.4.0' ,
376- version1 = ' 3.7.2.0' ,
377- basedir = r' C:\WinP\bd37' ,
378- flavor = ' Ps2' ,
379- architecture = 64
380- )
336+ version2 = " 3.7.4.0" ,
337+ version1 = " 3.7.2.0" ,
338+ basedir = r" C:\WinP\bd37" ,
339+ flavor = " Ps2" ,
340+ architecture = 64 ,
341+ )
381342 # test_parse_package_index_wiki('2.7.3.3')
382343 # print(compare_package_indexes('2.7.3.3', '2.7.3.1'))
383344 # write_changelog('2.7.4.1', '2.7.4.0')
0 commit comments