Skip to content
Snippets Groups Projects

18.0 backport

Open Vincent Hatakeyama requested to merge topic/16.0/backport into branch/16.0
Files
24
+ 31
21
@@ -2,7 +2,7 @@
##############################################################################
#
# OpenERP, Open Source Management Solution
# Copyright © 2014, 2018, 2022, 2023 XCG Consulting
# Copyright © 2014, 2018, 2022-2024 XCG Consulting
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as
@@ -22,7 +22,7 @@
import os
import os.path
import sys
from collections.abc import Mapping
from collections.abc import MutableMapping
def main():
@@ -31,13 +31,13 @@
sys.exit(1)
folder = sys.argv[1]
exts = sys.argv[2].split(",")
tags = sys.argv[3].split(",")
todolist = {tag: [] for tag in tags}
path_file_length: Mapping[str, int] = {}
exts: list[str] = sys.argv[2].split(",")
tags: list[str] = sys.argv[3].split(",")
todolist: dict[str, list[tuple[str, int, str]]] = {tag: [] for tag in tags}
path_file_length: MutableMapping[str, int] = {}
for root, _dirs, files in os.walk(folder):
scan_folder((exts, tags, todolist, path_file_length), root, files)
create_autotodo(folder, todolist, path_file_length)
@@ -38,10 +38,10 @@
for root, _dirs, files in os.walk(folder):
scan_folder((exts, tags, todolist, path_file_length), root, files)
create_autotodo(folder, todolist, path_file_length)
def write_info(f, infos, folder, path_file_length: Mapping[str, int]):
def write_info(f, infos, folder, path_file_length: MutableMapping[str, int]):
# Check sphinx version for lineno-start support
import sphinx
@@ -55,5 +55,5 @@
path = i[0]
line = i[1]
lines = (line - 3, min(line + 4, path_file_length[path]))
class_name = ":class:`%s`" % os.path.basename(os.path.splitext(path)[0])
class_name = f":class:`{os.path.basename(os.path.splitext(path)[0])}`"
f.write(
@@ -59,6 +59,6 @@
f.write(
"%s\n"
"%s\n\n"
"Line %s\n"
"\t.. literalinclude:: %s\n"
"{}\n"
"{}\n\n"
"Line {}\n"
"\t.. literalinclude:: {}\n"
"\t\t:language: python\n"
@@ -64,7 +64,6 @@
"\t\t:language: python\n"
"\t\t:lines: %s-%s\n"
"\t\t:emphasize-lines: %s\n"
% (
"\t\t:lines: {}-{}\n"
"\t\t:emphasize-lines: {}\n".format(
class_name,
"-" * len(class_name),
line,
@@ -75,7 +74,7 @@
)
)
if lineno_start:
f.write("\t\t:lineno-start: %s\n" % lines[0])
f.write(f"\t\t:lineno-start: {lines[0]}\n")
f.write("\n")
@@ -79,6 +78,6 @@
f.write("\n")
def create_autotodo(folder, todolist, path_file_length: Mapping[str, int]):
def create_autotodo(folder, todolist, path_file_length: MutableMapping[str, int]):
with open("autotodo", "w+") as f:
for tag, info in list(todolist.items()):
@@ -83,6 +82,6 @@
with open("autotodo", "w+") as f:
for tag, info in list(todolist.items()):
f.write("%s\n%s\n\n" % (tag, "=" * len(tag)))
f.write("{}\n{}\n\n".format(tag, "=" * len(tag)))
write_info(f, info, folder, path_file_length)
@@ -86,7 +85,16 @@
write_info(f, info, folder, path_file_length)
def scan_folder(data_tuple, dirname, names):
def scan_folder(
data_tuple: tuple[
list[str],
list[str],
dict[str, list[tuple[str, int, str]]],
MutableMapping[str, int],
],
dirname: str,
names: list[str],
):
(exts, tags, res, path_file_length) = data_tuple
for name in names:
(root, ext) = os.path.splitext(name)
@@ -99,6 +107,8 @@
res[tag].extend(info)
def scan_file(filename, tags) -> tuple[dict[str, list[tuple[str, int, str]]], int]:
def scan_file(
filename: str, tags: list[str]
) -> tuple[dict[str, list[tuple[str, int, str]]], int]:
res: dict[str, list[tuple[str, int, str]]] = {tag: [] for tag in tags}
line_num: int = 0
@@ -103,6 +113,6 @@
res: dict[str, list[tuple[str, int, str]]] = {tag: [] for tag in tags}
line_num: int = 0
with open(filename, "r") as f:
with open(filename) as f:
for line_num, line in enumerate(f):
for tag in tags:
if tag in line:
Loading