1
0
mirror of https://github.com/weechat/weechat.git synced 2026-06-12 14:14:48 +02:00

ci: switch from bandit/flake8/pylint to ruff in CI for Python scripts

This commit is contained in:
Sébastien Helleu
2025-12-07 09:22:34 +01:00
parent a2a71b4d33
commit 9e814860ae
9 changed files with 1419 additions and 1302 deletions
+22 -28
View File
@@ -19,16 +19,16 @@
# along with this program. If not, see <https://www.gnu.org/licenses/>.
#
"""
Generate Python stub: API constants and functions, with type annotations.
"""Generate Python stub with API constants and functions.
This script requires Python 3.6+.
This script requires Python 3.10+.
"""
from pathlib import Path
from textwrap import indent
# ruff: noqa: T201
import re
from pathlib import Path
from textwrap import indent
DOC_DIR = Path(__file__).resolve().parent.parent / "doc" / "en"
SRC_DIR = Path(__file__).resolve().parent.parent / "src"
@@ -43,12 +43,12 @@ STUB_HEADER = """\
# DO NOT EDIT BY HAND!
#
# ruff: noqa: A002,D400,D205,D301,D415,E501,PIE790,PYI021,PYI048,UP006,UP007,UP035
from typing import Dict, Union
"""
CONSTANT_RE = (
r"WEECHAT_SCRIPT_CONST_(?P<type>(INT|STR))\((?P<constant>WEECHAT_[A-Z0-9_]+)\)"
)
CONSTANT_RE = r"WEECHAT_SCRIPT_CONST_(?P<type>(INT|STR))\((?P<constant>WEECHAT_[A-Z0-9_]+)\)"
FUNCTION_RE = r"""\[source,python\]
----
@@ -60,40 +60,34 @@ def (?P<function>\w+)(?P<args>[^)]*)(?P<return>\) -> [^:]+:) \.\.\.(?P<example>.
def print_stub_constants() -> None:
"""Print constants, extracted from the plugin-script.c."""
constant_pattern = re.compile(CONSTANT_RE)
with 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_public_header_file:
plugin_script_c = Path(SRC_DIR / "plugins" / "plugin-script.c")
weechat_plugin_h = Path(SRC_DIR / "plugins" / "weechat-plugin.h")
with (
plugin_script_c.open(encoding="utf-8") as plugin_script_file,
weechat_plugin_h.open(encoding="utf-8") 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_public_header, re.MULTILINE)
value = f' = {value_match["value"]}' if value_match else ""
print(f'{match["constant"]}: {match["type"].lower()}{value}')
value = f" = {value_match['value']}" if value_match else ""
print(f"{match['constant']}: {match['type'].lower()}{value}")
def print_stub_functions() -> None:
"""Print function prototypes, extracted from the Plugin API reference."""
function_pattern = re.compile(FUNCTION_RE, re.DOTALL)
with open(DOC_DIR / "weechat_plugin_api.en.adoc",
encoding="utf-8") as api_doc_file:
with Path(DOC_DIR / "weechat_plugin_api.en.adoc").open(encoding="utf-8") as api_doc_file:
api_doc = api_doc_file.read()
for match in function_pattern.finditer(api_doc):
url = f'https://weechat.org/doc/weechat/api/#_{match["function"]}'
example = (
f'\n ::\n\n{indent(match["example"].lstrip(), " " * 8)}'
if match["example"]
else ""
)
print(
f"""\n
url = f"https://weechat.org/doc/weechat/api/#_{match['function']}"
example = f"\n ::\n\n{indent(match['example'].lstrip(), ' ' * 8)}\n " if match["example"] else ""
str_func = f"""\n
def {match["function"]}{match["args"]}{match["return"]}
\"""`{match["function"]} in WeeChat plugin API reference <{url}>`_{example}
\"""
\"""`{match["function"]} in WeeChat plugin API reference <{url}>`_{example}\"""
..."""
)
print(str_func)
def stub_api() -> None: