gen-config for third party kittens
This commit is contained in:
parent
6e77345263
commit
f8924286ce
2 changed files with 27 additions and 3 deletions
|
|
@ -426,6 +426,28 @@ def write_output(loc: str, defn: Definition) -> None:
|
|||
|
||||
|
||||
def main() -> None:
|
||||
# To use run it as:
|
||||
# kitty +runpy 'from kitty.conf.generate import main; main()' /path/to/kitten/file.py
|
||||
import importlib
|
||||
import sys
|
||||
|
||||
from kittens.runner import path_to_custom_kitten, resolved_kitten
|
||||
from kitty.constants import config_dir
|
||||
|
||||
kitten = sys.argv[-1]
|
||||
if not kitten.endswith(
|
||||
if not kitten.endswith('.py'):
|
||||
kitten += '.py'
|
||||
kitten = resolved_kitten(kitten)
|
||||
path = os.path.realpath(path_to_custom_kitten(config_dir, kitten))
|
||||
if not os.path.dirname(path):
|
||||
raise SystemExit(f'No custom kitten named {kitten} found')
|
||||
sys.path.insert(0, os.path.dirname(path))
|
||||
package_name = os.path.basename(os.path.dirname(path))
|
||||
m = importlib.import_module('kitten_options_definition')
|
||||
defn = getattr(m, 'definition')
|
||||
loc = package_name
|
||||
cls, tc = generate_class(defn, loc)
|
||||
with open(os.path.join(os.path.dirname(path), 'kitten_options_types.py'), 'w') as f:
|
||||
f.write(cls + '\n')
|
||||
with open(os.path.join(os.path.dirname(path), 'kitten_options_parse.py'), 'w') as f:
|
||||
f.write(tc + '\n')
|
||||
|
|
|
|||
|
|
@ -541,9 +541,11 @@ def resolve_imports(self, module: Any) -> 'Action':
|
|||
class Definition:
|
||||
|
||||
def __init__(self, package: str, *actions: Action, has_color_table: bool = False) -> None:
|
||||
self.module_for_parsers = import_module(f'{package}.options.utils')
|
||||
if package.startswith('!'):
|
||||
self.module_for_parsers = import_module(package[1:])
|
||||
else:
|
||||
self.module_for_parsers = import_module(f'{package}.options.utils')
|
||||
self.has_color_table = has_color_table
|
||||
self.package = package
|
||||
self.coalesced_iterator_data = CoalescedIteratorData()
|
||||
self.root_group = Group('', '', self.coalesced_iterator_data)
|
||||
self.current_group = self.root_group
|
||||
|
|
|
|||
Loading…
Reference in a new issue