Make relative imports work in gen scripts even when directly executed

This commit is contained in:
Kovid Goyal 2023-10-15 09:51:03 +05:30
parent 792b74503c
commit 119582a9d4
No known key found for this signature in database
GPG Key ID: 06BC317B515ACE7C
7 changed files with 37 additions and 0 deletions

View File

@ -7,6 +7,11 @@
from collections import defaultdict
from typing import Any, DefaultDict, Dict, FrozenSet, List, Tuple, Union
if __name__ == '__main__' and not __package__:
import __main__
__main__.__package__ = 'gen'
sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
KeymapType = Dict[str, Tuple[str, Union[FrozenSet[str], str]]]

View File

@ -10,6 +10,11 @@
from kitty.conf.generate import write_output
if __name__ == '__main__' and not __package__:
import __main__
__main__.__package__ = 'gen'
sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
def patch_color_list(path: str, colors: List[str], name: str, spc: str = ' ') -> None:
with open(path, 'r+') as f:

View File

@ -6,6 +6,11 @@
import sys
from typing import List
if __name__ == '__main__' and not __package__:
import __main__
__main__.__package__ = 'gen'
sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
from .key_constants import patch_file
# References for these names:

View File

@ -49,6 +49,12 @@
from kitty.remote_control import global_options_spec
from kitty.rgb import color_names
if __name__ == '__main__' and not __package__:
import __main__
__main__.__package__ = 'gen'
sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
changed: List[str] = []

View File

@ -7,6 +7,11 @@
from pprint import pformat
from typing import Any, Dict, List, Union
if __name__ == '__main__' and not __package__:
import __main__
__main__.__package__ = 'gen'
sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
functional_key_defs = '''# {{{
# kitty XKB macVK macU
escape Escape 0x35 -

View File

@ -6,6 +6,11 @@
from functools import lru_cache
from typing import List
if __name__ == '__main__' and not __package__:
import __main__
__main__.__package__ = 'gen'
sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
def to_linear(a: float) -> float:
if a <= 0.04045:

View File

@ -26,6 +26,12 @@
)
from urllib.request import urlopen
if __name__ == '__main__' and not __package__:
import __main__
__main__.__package__ = 'gen'
sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
non_characters = frozenset(range(0xfffe, 0x10ffff, 0x10000))
non_characters |= frozenset(range(0xffff, 0x10ffff + 1, 0x10000))
non_characters |= frozenset(range(0xfdd0, 0xfdf0))