diff options
author | Sébastien Helleu <flashcode@flashtux.org> | 2024-03-04 23:10:55 +0100 |
---|---|---|
committer | Sébastien Helleu <flashcode@flashtux.org> | 2024-03-05 19:52:21 +0100 |
commit | 81599b88d47fd740a073d47a47dc2481801f530b (patch) | |
tree | ef3f602d241e3f77122b9a5273d3965895f73e75 /tools/generate_python_stub.py | |
parent | 84437ab672b6866b7464cda51be91d13f3e2e446 (diff) | |
download | weechat-81599b88d47fd740a073d47a47dc2481801f530b.zip |
plugins: move scripting API constants to plugin-script.c
Diffstat (limited to 'tools/generate_python_stub.py')
-rwxr-xr-x | tools/generate_python_stub.py | 26 |
1 files changed, 10 insertions, 16 deletions
diff --git a/tools/generate_python_stub.py b/tools/generate_python_stub.py index 5d529ac28..b87f72642 100755 --- a/tools/generate_python_stub.py +++ b/tools/generate_python_stub.py @@ -41,8 +41,7 @@ from typing import Dict, Union """ CONSTANT_RE = ( - r"( |\|) `(?P<constant>WEECHAT_[A-Z0-9_]+)` " - r"\((?P<type>(string|integer))\)(?: \+)?" + r"WEECHAT_SCRIPT_CONST_(?P<type>(INT|STR))\((?P<constant>WEECHAT_[A-Z0-9_]+)\)" ) FUNCTION_RE = r"""\[source,python\] @@ -53,25 +52,20 @@ def (?P<function>\w+)(?P<args>[^)]*)(?P<return>\) -> [^:]+:) \.\.\.(?P<example>. def print_stub_constants() -> None: - """Print constants, extracted from the Scripting guide.""" - types = { - "integer": "int", - "string": "str", - } + """Print constants, extracted from the plugin-script.c.""" constant_pattern = re.compile(CONSTANT_RE) with open( - DOC_DIR / "weechat_scripting.en.adoc", encoding="utf-8" - ) as scripting_file, open( + SRC_DIR / "plugins" / "plugin-script.c", encoding="utf-8" + ) as plugin_script_file, open( SRC_DIR / "plugins" / "weechat-plugin.h", encoding="utf-8" - ) as plugin_header_file: - scripting = scripting_file.read() - plugin_header = plugin_header_file.read() - for match in constant_pattern.finditer(scripting): + ) as plugin_public_header_file: + plugin_script = plugin_script_file.read() + plugin_public_header = plugin_public_header_file.read() + for match in constant_pattern.finditer(plugin_script): value_re = rf'^#define {match["constant"]} +(?P<value>[\w"-]+)$' - value_match = re.search(value_re, plugin_header, re.MULTILINE) + value_match = re.search(value_re, plugin_public_header, re.MULTILINE) value = f' = {value_match["value"]}' if value_match else "" - - print(f'{match["constant"]}: {types[match["type"]]}{value}') + print(f'{match["constant"]}: {match["type"].lower()}{value}') def print_stub_functions() -> None: |