1111import re
1212import shutil
1313from packaging import version
14- from winpython import utils
14+ from . import utils
1515
16- CHANGELOGS_DIR = Path (__file__ ).parent / "changelogs"
16+ CHANGELOGS_DIR = Path (__file__ ).parent . parent / "changelogs"
1717assert CHANGELOGS_DIR .is_dir ()
1818
1919class Package :
@@ -45,16 +45,16 @@ class PackageIndex:
4545 HEADERS = {"tools" : "### Tools" , "python" : "### Python packages" , "wheelhouse" : "### WheelHouse packages" }
4646 BLANKS = ["Name | Version | Description" , "-----|---------|------------" , "" , "<details>" , "</details>" ]
4747
48- def __init__ (self , version , basedir = None , flavor = "" , architecture = 64 ):
48+ def __init__ (self , version , searchdir = None , flavor = "" , architecture = 64 ):
4949 self .version = version
5050 self .flavor = flavor
51- self .basedir = basedir
51+ self .searchdir = searchdir
5252 self .architecture = architecture
5353 self .packages = {"tools" : {}, "python" : {}, "wheelhouse" : {}}
5454 self ._load_index ()
5555
5656 def _load_index (self ):
57- filename = CHANGELOGS_DIR / f"WinPython{ self .flavor } -{ self .architecture } bit-{ self .version } .md"
57+ filename = self . searchdir / f"WinPython{ self .flavor } -{ self .architecture } bit-{ self .version } .md"
5858 if not filename .exists ():
5959 raise FileNotFoundError (f"Changelog not found: { filename } " )
6060
@@ -93,20 +93,20 @@ def normalize(d): return {k.replace("-", "_").lower(): v for k, v in d.items()}
9393 output += "Removed packages:\r \n \r \n " + "" .join (removed ) + "\r \n "
9494 return output
9595
96- def find_previous_version (target_version , basedir = None , flavor = "" , architecture = 64 ):
96+ def find_previous_version (target_version , searchdir = None , flavor = "" , architecture = 64 ):
9797 """Find version which is the closest to `version`"""
98- build_dir = Path (basedir ) / f"bu { flavor } "
98+ search_dir = Path (searchdir ) if searchdir else CHANGELOGS_DIR
9999 pattern = re .compile (rf"WinPython{ flavor } -{ architecture } bit-([0-9\.]+)\.(txt|md)" )
100- versions = [pattern .match (f ).group (1 ) for f in os .listdir (build_dir ) if pattern .match (f )]
100+ versions = [pattern .match (f ).group (1 ) for f in os .listdir (search_dir ) if pattern .match (f )]
101101 versions = [v for v in versions if version .parse (v ) < version .parse (target_version )]
102102 return max (versions , key = version .parse , default = target_version )
103103
104- def compare_package_indexes (version2 , version1 = None , basedir = None , flavor = "" , flavor1 = None , architecture = 64 ):
105- version1 = version1 or find_previous_version (version2 , basedir , flavor , architecture )
104+ def compare_package_indexes (version2 , version1 = None , searchdir = None , flavor = "" , flavor1 = None , architecture = 64 ):
105+ version1 = version1 or find_previous_version (version2 , searchdir , flavor , architecture )
106106 flavor1 = flavor1 or flavor
107107
108- pi1 = PackageIndex (version1 , basedir , flavor1 , architecture )
109- pi2 = PackageIndex (version2 , basedir , flavor , architecture )
108+ pi1 = PackageIndex (version1 , searchdir , flavor1 , architecture )
109+ pi2 = PackageIndex (version2 , searchdir , flavor , architecture )
110110
111111 text = (
112112 f"## History of changes for WinPython-{ architecture } bit { version2 + flavor } \r \n \r \n "
@@ -121,25 +121,27 @@ def compare_package_indexes(version2, version1=None, basedir=None, flavor="", fl
121121
122122 return text + "\r \n </details>\r \n * * *\r \n "
123123
124- def copy_changelogs (version , basedir , flavor = "" , architecture = 64 ):
124+ def copy_changelogs (version , searchdir , flavor = "" , architecture = 64 , basedir = None ):
125125 basever = "." .join (version .split ("." )[:2 ])
126126 pattern = re .compile (rf"WinPython{ flavor } -{ architecture } bit-{ basever } [0-9\.]*\.(txt|md)" )
127- dest = Path (basedir ) / f"bu { flavor } "
128- for fname in os .listdir (CHANGELOGS_DIR ):
127+ dest = Path (basedir )
128+ for fname in os .listdir (searchdir ):
129129 if pattern .match (fname ):
130- shutil .copyfile (CHANGELOGS_DIR / fname , dest / fname )
130+ shutil .copyfile (searchdir / fname , dest / fname )
131131
132- def write_changelog (version2 , version1 = None , basedir = None , flavor = "" , architecture = 64 ):
132+ def write_changelog (version2 , version1 = None , searchdir = None , flavor = "" , architecture = 64 , basedir = None ):
133133 """Write changelog between version1 and version2 of WinPython"""
134- copy_changelogs (version2 , basedir , flavor , architecture )
135- print ("comparing_package_indexes" , version2 , basedir , flavor , architecture )
136- changelog = compare_package_indexes (version2 , version1 , basedir , flavor , architecture = architecture )
137- output_file = Path (basedir ) / f"bu{ flavor } " / f"WinPython{ flavor } -{ architecture } bit-{ version2 } _History.md"
134+ if basedir :
135+ copy_changelogs (version2 , searchdir , flavor , architecture , basedir )
136+ print ("comparing_package_indexes" , version2 , searchdir , flavor , architecture )
137+ changelog = compare_package_indexes (version2 , version1 , searchdir , flavor , architecture = architecture )
138+ output_file = searchdir / f"WinPython{ flavor } -{ architecture } bit-{ version2 } _History.md"
138139 with open (output_file , "w" , encoding = "utf-8" ) as f :
139140 f .write (changelog )
140- # Copy to winpython/changelogs
141- shutil .copyfile (output_file , CHANGELOGS_DIR / output_file .name )
141+ # Copy to winpython/changelogs back to basedir
142+ if basedir :
143+ shutil .copyfile (output_file , basedir / output_file .name )
142144
143145if __name__ == "__main__" :
144- print (compare_package_indexes ("3.7.4.0" , "3.7.2.0" , r"C:\WinP\bd37" , "Zero" , architecture = 32 ))
145- write_changelog ("3.7.4.0" , "3.7.2.0" , r"C:\WinP\bd37" , "Ps2" , architecture = 64 )
146+ print (compare_package_indexes ("3.7.4.0" , "3.7.2.0" , r"C:\WinP\bd37\budot " , "Zero" , architecture = 32 ))
147+ write_changelog ("3.7.4.0" , "3.7.2.0" , r"C:\WinP\bd37\budot " , "Ps2" , architecture = 64 )
0 commit comments