From 14214b329e7d6179880ba51b7ebb4b2e89727b0a Mon Sep 17 00:00:00 2001 From: Jonathan Gamble Date: Sat, 16 Nov 2024 10:39:34 -0600 Subject: [PATCH] only touch lichess.sfd when changed --- bin/gen/licon.py | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/bin/gen/licon.py b/bin/gen/licon.py index f7abc53f2a7a8..068d981cfa8af 100755 --- a/bin/gen/licon.py +++ b/bin/gen/licon.py @@ -83,7 +83,7 @@ def main(): gen_fonts() - codes = parse_codes() + codes = read_write_codes() gen_sources(codes) @@ -110,32 +110,33 @@ def dash_camel(s): return ''.join([w.title() for w in s.split('-')]) -def parse_codes(): +def read_write_codes(): unnamed_re = re.compile(r'$|uni[a-f0-9]{4}', re.IGNORECASE) codes = {} warnings = [] corrected = [] + lines = [] with open('lichess.sfd', 'r') as f: lines = f.readlines() name = None n = 0 - line_ok = True for line in lines: if line.startswith('StartChar:'): name = dash_camel(line.split(': ')[1].strip()) elif line.startswith('Encoding:') and name is not None: code_point = int(line.split(' ')[1]) if code_point >= 0xe000 and code_point <= 0xefff: - code_point = 57344 + n n += 1 + code_point = 57343 + n line = f'Encoding: {code_point} {code_point} {n}\n' if unnamed_re.match(name): warnings.append(f' Unnamed glyph "{name}" at code point {code_point}\n') else: codes[name] = code_point corrected.append(line) - with open('lichess.sfd', 'w') as f: - f.write(''.join(corrected)) + if corrected != lines: + with open('lichess.sfd', 'w') as f: + f.write(''.join(corrected)) print('' if not warnings else f'\nWarnings:\n{"".join(warnings)}') return dict(sorted(codes.items(), key=lambda x: x[1]))