mirror of
https://github.com/kovidgoyal/kitty
synced 2026-06-08 14:18:26 +02:00
Move gen scripts into their own package
This commit is contained in:
4
gen/README.rst
Normal file
4
gen/README.rst
Normal file
@@ -0,0 +1,4 @@
|
|||||||
|
Scripts to generate code for various things like keys, mouse cursors, unicode
|
||||||
|
data etc. Some of these generate code that is checked into version control.
|
||||||
|
Some generate ephemeral code used during builds. Ephemeral code is in files
|
||||||
|
with a _generated.[h|go|c] extension.
|
||||||
0
gen/__init__.py
Normal file
0
gen/__init__.py
Normal file
39
gen/__main__.py
Normal file
39
gen/__main__.py
Normal file
@@ -0,0 +1,39 @@
|
|||||||
|
#!/usr/bin/env python
|
||||||
|
# License: GPLv3 Copyright: 2023, Kovid Goyal <kovid at kovidgoyal.net>
|
||||||
|
|
||||||
|
|
||||||
|
import os
|
||||||
|
import sys
|
||||||
|
|
||||||
|
|
||||||
|
def main(args: list[str]=sys.argv) -> None:
|
||||||
|
os.chdir(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
|
||||||
|
sys.path.insert(0, os.getcwd())
|
||||||
|
if len(args) == 1:
|
||||||
|
raise SystemExit('usage: python gen which')
|
||||||
|
which = args[1]
|
||||||
|
del args[1]
|
||||||
|
if which == 'apc-parsers':
|
||||||
|
from gen.apc_parsers import main
|
||||||
|
main(args)
|
||||||
|
elif which == 'config':
|
||||||
|
from gen.config import main
|
||||||
|
main(args)
|
||||||
|
elif which == 'srgb-lut':
|
||||||
|
from gen.srgb_lut import main
|
||||||
|
main(args)
|
||||||
|
elif which == 'key-constants':
|
||||||
|
from gen.key_constants import main
|
||||||
|
main(args)
|
||||||
|
elif which == 'go-code':
|
||||||
|
from gen.go_code import main
|
||||||
|
main(args)
|
||||||
|
elif which == 'wcwidth':
|
||||||
|
from gen.wcwidth import main
|
||||||
|
main(args)
|
||||||
|
else:
|
||||||
|
raise SystemExit(f'Unknown which: {which}')
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
main()
|
||||||
@@ -3,6 +3,7 @@
|
|||||||
|
|
||||||
import os
|
import os
|
||||||
import subprocess
|
import subprocess
|
||||||
|
import sys
|
||||||
from collections import defaultdict
|
from collections import defaultdict
|
||||||
from typing import Any, DefaultDict, Dict, FrozenSet, List, Tuple, Union
|
from typing import Any, DefaultDict, Dict, FrozenSet, List, Tuple, Union
|
||||||
|
|
||||||
@@ -281,4 +282,11 @@ def graphics_parser() -> None:
|
|||||||
write_header(text, 'kitty/parse-graphics-command.h')
|
write_header(text, 'kitty/parse-graphics-command.h')
|
||||||
|
|
||||||
|
|
||||||
graphics_parser()
|
def main(args: list[str]=sys.argv) -> None:
|
||||||
|
graphics_parser()
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
import runpy
|
||||||
|
m = runpy.run_path(os.path.dirname(os.path.abspath(__file__)))
|
||||||
|
m['main']([sys.executable, 'apc-parsers'])
|
||||||
@@ -2,8 +2,10 @@
|
|||||||
# License: GPLv3 Copyright: 2021, Kovid Goyal <kovid at kovidgoyal.net>
|
# License: GPLv3 Copyright: 2021, Kovid Goyal <kovid at kovidgoyal.net>
|
||||||
|
|
||||||
|
|
||||||
|
import os
|
||||||
import re
|
import re
|
||||||
import subprocess
|
import subprocess
|
||||||
|
import sys
|
||||||
from typing import List
|
from typing import List
|
||||||
|
|
||||||
from kitty.conf.generate import write_output
|
from kitty.conf.generate import write_output
|
||||||
@@ -33,7 +35,7 @@ def patch_color_list(path: str, colors: List[str], name: str, spc: str = ' ')
|
|||||||
subprocess.check_call(['gofmt', '-w', path])
|
subprocess.check_call(['gofmt', '-w', path])
|
||||||
|
|
||||||
|
|
||||||
def main() -> None:
|
def main(args: list[str]=sys.argv) -> None:
|
||||||
from kitty.options.definition import definition
|
from kitty.options.definition import definition
|
||||||
write_output('kitty', definition)
|
write_output('kitty', definition)
|
||||||
nullable_colors = []
|
nullable_colors = []
|
||||||
@@ -51,4 +53,6 @@ def main() -> None:
|
|||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
main()
|
import runpy
|
||||||
|
m = runpy.run_path(os.path.dirname(os.path.abspath(__file__)))
|
||||||
|
m['main']([sys.executable, 'config'])
|
||||||
@@ -834,7 +834,7 @@ def generate_ssh_kitten_data() -> None:
|
|||||||
write_compressed_data(buf.getvalue(), d)
|
write_compressed_data(buf.getvalue(), d)
|
||||||
|
|
||||||
|
|
||||||
def main() -> None:
|
def main(args: list[str]=sys.argv) -> None:
|
||||||
with replace_if_needed('constants_generated.go') as f:
|
with replace_if_needed('constants_generated.go') as f:
|
||||||
f.write(generate_constants())
|
f.write(generate_constants())
|
||||||
with replace_if_needed('tools/utils/style/color-names_generated.go') as f:
|
with replace_if_needed('tools/utils/style/color-names_generated.go') as f:
|
||||||
@@ -860,4 +860,7 @@ def main() -> None:
|
|||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
main() # }}}
|
import runpy
|
||||||
|
m = runpy.run_path(os.path.dirname(os.path.abspath(__file__)))
|
||||||
|
m['main']([sys.executable, 'go-code'])
|
||||||
|
# }}}
|
||||||
@@ -1,7 +1,9 @@
|
|||||||
#!/usr/bin/env python
|
#!/usr/bin/env python
|
||||||
# License: GPLv3 Copyright: 2021, Kovid Goyal <kovid at kovidgoyal.net>
|
# License: GPLv3 Copyright: 2021, Kovid Goyal <kovid at kovidgoyal.net>
|
||||||
|
|
||||||
|
import os
|
||||||
import string
|
import string
|
||||||
|
import sys
|
||||||
from pprint import pformat
|
from pprint import pformat
|
||||||
from typing import Any, Dict, List, Union
|
from typing import Any, Dict, List, Union
|
||||||
|
|
||||||
@@ -417,7 +419,7 @@ def generate_macos_mapping() -> None:
|
|||||||
patch_file('glfw/cocoa_window.m', 'functional to macu', '\n'.join(lines))
|
patch_file('glfw/cocoa_window.m', 'functional to macu', '\n'.join(lines))
|
||||||
|
|
||||||
|
|
||||||
def main() -> None:
|
def main(args: list[str]=sys.argv) -> None:
|
||||||
generate_glfw_header()
|
generate_glfw_header()
|
||||||
generate_xkb_mapping()
|
generate_xkb_mapping()
|
||||||
generate_functional_table()
|
generate_functional_table()
|
||||||
@@ -427,4 +429,6 @@ def main() -> None:
|
|||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
main()
|
import runpy
|
||||||
|
m = runpy.run_path(os.path.dirname(os.path.abspath(__file__)))
|
||||||
|
m['main']([sys.executable, 'key-constants'])
|
||||||
@@ -2,6 +2,7 @@
|
|||||||
# vim:fileencoding=utf-8
|
# vim:fileencoding=utf-8
|
||||||
|
|
||||||
import os
|
import os
|
||||||
|
import sys
|
||||||
from functools import lru_cache
|
from functools import lru_cache
|
||||||
from typing import List
|
from typing import List
|
||||||
|
|
||||||
@@ -41,11 +42,13 @@ def generate_srgb_gamma(declaration: str = 'static const GLfloat srgb_lut[256] =
|
|||||||
return "\n".join(lines)
|
return "\n".join(lines)
|
||||||
|
|
||||||
|
|
||||||
def main() -> None:
|
def main(args: list[str]=sys.argv) -> None:
|
||||||
c = generate_srgb_gamma()
|
c = generate_srgb_gamma()
|
||||||
with open(os.path.join('kitty', 'srgb_gamma.h'), 'w') as f:
|
with open(os.path.join('kitty', 'srgb_gamma.h'), 'w') as f:
|
||||||
f.write(f'{c}\n')
|
f.write(f'{c}\n')
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
main()
|
import runpy
|
||||||
|
m = runpy.run_path(os.path.dirname(os.path.abspath(__file__)))
|
||||||
|
m['main']([sys.executable, 'srgb-lut'])
|
||||||
@@ -26,8 +26,6 @@ from typing import (
|
|||||||
)
|
)
|
||||||
from urllib.request import urlopen
|
from urllib.request import urlopen
|
||||||
|
|
||||||
os.chdir(os.path.dirname(os.path.abspath(__file__)))
|
|
||||||
|
|
||||||
non_characters = frozenset(range(0xfffe, 0x10ffff, 0x10000))
|
non_characters = frozenset(range(0xfffe, 0x10ffff, 0x10000))
|
||||||
non_characters |= frozenset(range(0xffff, 0x10ffff + 1, 0x10000))
|
non_characters |= frozenset(range(0xffff, 0x10ffff + 1, 0x10000))
|
||||||
non_characters |= frozenset(range(0xfdd0, 0xfdf0))
|
non_characters |= frozenset(range(0xfdd0, 0xfdf0))
|
||||||
@@ -584,12 +582,19 @@ def gen_rowcolumn_diacritics() -> None:
|
|||||||
subprocess.check_call(['gofmt', '-w', '-s', go_file])
|
subprocess.check_call(['gofmt', '-w', '-s', go_file])
|
||||||
|
|
||||||
|
|
||||||
parse_ucd()
|
def main(args: list[str]=sys.argv) -> None:
|
||||||
parse_prop_list()
|
parse_ucd()
|
||||||
parse_emoji()
|
parse_prop_list()
|
||||||
parse_eaw()
|
parse_emoji()
|
||||||
gen_ucd()
|
parse_eaw()
|
||||||
gen_wcwidth()
|
gen_ucd()
|
||||||
gen_emoji()
|
gen_wcwidth()
|
||||||
gen_names()
|
gen_emoji()
|
||||||
gen_rowcolumn_diacritics()
|
gen_names()
|
||||||
|
gen_rowcolumn_diacritics()
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
import runpy
|
||||||
|
m = runpy.run_path(os.path.dirname(os.path.abspath(__file__)))
|
||||||
|
m['main']([sys.executable, 'wcwidth'])
|
||||||
2
kitty/parse-graphics-command.h
generated
2
kitty/parse-graphics-command.h
generated
@@ -1,4 +1,4 @@
|
|||||||
// This file is generated by gen-apc-parsers.py do not edit!
|
// This file is generated by apc_parsers.py do not edit!
|
||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
[tool.mypy]
|
[tool.mypy]
|
||||||
files = 'kitty,kittens,glfw,*.py,docs/conf.py'
|
files = 'kitty,kittens,glfw,*.py,docs/conf.py,gen'
|
||||||
no_implicit_optional = true
|
no_implicit_optional = true
|
||||||
sqlite_cache = true
|
sqlite_cache = true
|
||||||
cache_fine_grained = true
|
cache_fine_grained = true
|
||||||
|
|||||||
2
setup.py
2
setup.py
@@ -939,7 +939,7 @@ def update_go_generated_files(args: Options, kitty_exe: str) -> None:
|
|||||||
|
|
||||||
env = os.environ.copy()
|
env = os.environ.copy()
|
||||||
env['ASAN_OPTIONS'] = 'detect_leaks=0'
|
env['ASAN_OPTIONS'] = 'detect_leaks=0'
|
||||||
cp = subprocess.run([kitty_exe, '+launch', os.path.join(src_base, 'gen-go-code.py')], stdout=subprocess.PIPE, env=env)
|
cp = subprocess.run([kitty_exe, '+launch', os.path.join(src_base, 'gen/go_code.py')], stdout=subprocess.PIPE, env=env)
|
||||||
if cp.returncode != 0:
|
if cp.returncode != 0:
|
||||||
raise SystemExit(cp.returncode)
|
raise SystemExit(cp.returncode)
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user