1
0
mirror of https://github.com/weechat/weechat.git synced 2026-06-29 06:16:40 +02:00

python: Include constant values in python stub

This is useful for two reasons:

1. When running unit tests for a script weechat needs to be mocked. By
   having the constant values available in the stub file, they can be
   loaded from that, instead of having to define the constants manually
   for the mock.

2. If you log a constant value you have to look up what it means. This
   makes it easier, in the same vein as PR #1824.
This commit is contained in:
Trygve Aaberge
2022-10-02 19:16:00 +02:00
committed by Sébastien Helleu
parent 4d3a3c67ac
commit 236d22e364
2 changed files with 52 additions and 43 deletions
+12 -3
View File
@@ -28,6 +28,7 @@ from pathlib import Path
import re
DOC_DIR = Path(__file__).resolve().parent / "en"
SRC_DIR = Path(__file__).resolve().parent.parent / "src"
STUB_HEADER = """\
#
@@ -56,11 +57,19 @@ def print_stub_constants() -> None:
"string": "str",
}
constant_pattern = re.compile(CONSTANT_RE)
with open(DOC_DIR / "weechat_scripting.en.adoc",
encoding="utf-8") as scripting_file:
with open(
DOC_DIR / "weechat_scripting.en.adoc", encoding="utf-8"
) as scripting_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):
print(f'{match["constant"]}: {types[match["type"]]}')
value_re = rf'^#define {match["constant"]} +(?P<value>[\w"-]+)$'
value_match = re.search(value_re, plugin_header, re.MULTILINE)
value = f' = {value_match["value"]}' if value_match else ""
print(f'{match["constant"]}: {types[match["type"]]}{value}')
def print_stub_functions() -> None: