1+ #! /usr/bin/env python3
2+
3+ import os , re , subprocess , sys
4+
5+ def version ():
6+ desc = subprocess .check_output (["git" , "describe" , "--tags" ], cwd = os .path .dirname (__file__ )).decode ("utf-8" )
7+ match = re .match (r"([0-9]+)\.([0-9]+)-([0-9]+)-([a-z0-9]+)" , desc )
8+ if match :
9+ major = int (match .group (1 ))
10+ minor = int (match .group (2 )) + int (match .group (3 ))
11+ sha = match .group (4 )
12+ return (major , minor , sha )
13+ else :
14+ raise Exception ("Can’t parse version from: " + desc )
15+
16+ def update_version (major , minor , src , dst ):
17+ with open (src , 'r' ) as f :
18+ contents = f .read ()
19+ contents = re .sub (r"versionMajor\s+=\s+\d+;" ,
20+ f"versionMajor = { major } ;" ,
21+ contents )
22+ contents = re .sub (r"versionMinor\s+=\s+\d+;" ,
23+ f"versionMinor = { minor } ;" ,
24+ contents )
25+ with open (dst , 'w' ) as f :
26+ f .write (contents )
27+
28+ if __name__ == '__main__' :
29+ os .chdir (os .path .abspath (os .path .dirname (__file__ ) + '/..' ))
30+ (major , minor , sha ) = version ()
31+ update_version (major , minor , 'FiraCode.glyphs' , 'FiraCode.glyphs' )
32+ print (f"{ major } .{ minor } -{ sha } " )
33+ sys .exit (0 )
0 commit comments