Skip to content

Commit

Permalink
Merge pull request #247 from tetengo/python_upgrade
Browse files Browse the repository at this point in the history
Python upgrade
  • Loading branch information
kaorut authored Jun 18, 2022
2 parents 3fe9a4e + 62c6f7e commit 9ae7dc6
Show file tree
Hide file tree
Showing 9 changed files with 46 additions and 46 deletions.
1 change: 1 addition & 0 deletions configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,7 @@ AC_ARG_WITH(
AC_CHECK_PROG(MYPY, mypy, mypy)
test -z $MYPY && \
AC_MSG_WARN([You cannot check the python script files for lack of mypy.])
AC_SUBST([MYPY_OPTS], "--strict")

AC_ARG_WITH(
doxygen,
Expand Down
2 changes: 1 addition & 1 deletion kogyan
2 changes: 1 addition & 1 deletion setup/installer/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ EXTRA_DIST = \


mypy: ${script_files}
${MYPY} ${srcdir}
${MYPY} ${MYPY_OPTS} ${srcdir}

format: ${script_files}
${BLACK} ${srcdir}
Expand Down
12 changes: 6 additions & 6 deletions setup/installer/copy_libimage_files.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@
import re
import shutil
import sys
from typing import List, Optional, Tuple
from typing import Optional


def main(args: List[str]) -> None:
def main(args: list[str]) -> None:
"""The main function.
Args:
Expand All @@ -23,12 +23,12 @@ def main(args: List[str]) -> None:
file=sys.stderr,
)
sys.exit(0)
files: List[Tuple[pathlib.Path, pathlib.Path]] = _list_files(pathlib.Path(args[0]))
files: list[tuple[pathlib.Path, pathlib.Path]] = _list_files(pathlib.Path(args[0]))
_copy_files(files, pathlib.Path(args[1]))


def _list_files(source_path: pathlib.Path) -> List[Tuple[pathlib.Path, pathlib.Path]]:
files: List[Tuple[pathlib.Path, pathlib.Path]] = []
def _list_files(source_path: pathlib.Path) -> list[tuple[pathlib.Path, pathlib.Path]]:
files: list[tuple[pathlib.Path, pathlib.Path]] = []
with source_path.open(mode="r", encoding="UTF-8") as stream:
for line in stream:
matched: Optional[re.Match[str]] = re.match(
Expand Down Expand Up @@ -57,7 +57,7 @@ def _list_files(source_path: pathlib.Path) -> List[Tuple[pathlib.Path, pathlib.P


def _copy_files(
files: List[Tuple[pathlib.Path, pathlib.Path]], destination_root: pathlib.Path
files: list[tuple[pathlib.Path, pathlib.Path]], destination_root: pathlib.Path
) -> None:
shutil.rmtree(destination_root, ignore_errors=True)
for file in files:
Expand Down
24 changes: 12 additions & 12 deletions setup/installer/generate_content_wxs.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@
import pathlib
import re
import sys
from typing import Dict, List, Optional, TextIO, Tuple
from typing import Any, Optional, TextIO


def main(args: List[str]) -> None:
def main(args: list[str]) -> None:
"""The main function.
Args:
Expand All @@ -28,7 +28,7 @@ def main(args: List[str]) -> None:
wxs_path = pathlib.Path(args[1])

destination_tree: _DestinationDirectory = _build_destination_tree(source_path)
feature_map: Dict[str, List[str]] = _build_feature_map(destination_tree)
feature_map: dict[str, list[str]] = _build_feature_map(destination_tree)
_save_wxs(destination_tree, feature_map, wxs_path)


Expand Down Expand Up @@ -76,17 +76,17 @@ class _DestinationDirectory:

level: int

children: Dict
children: dict[str, Any]

files: List[File]
files: list[File]

envvars: List[EnvVar]
envvars: list[EnvVar]

def __init__(self, id: str, name: str, level: int):
self.id = id
self.name = name
self.level = level
self.children: Dict[str, _DestinationDirectory] = {}
self.children: dict[str, _DestinationDirectory] = {}
self.files = []
self.envvars = []

Expand Down Expand Up @@ -154,14 +154,14 @@ def _build_destination_tree(source_path: pathlib.Path) -> _DestinationDirectory:
return destination_tree


def _build_feature_map(destination_tree: _DestinationDirectory) -> Dict[str, List[str]]:
map: Dict[str, List[str]] = {}
def _build_feature_map(destination_tree: _DestinationDirectory) -> dict[str, list[str]]:
map: dict[str, list[str]] = {}
_build_feature_map_iter(destination_tree, map)
return map


def _build_feature_map_iter(
destination_tree: _DestinationDirectory, feature_map: Dict[str, List[str]]
destination_tree: _DestinationDirectory, feature_map: dict[str, list[str]]
) -> None:
for file in destination_tree.files:
if not file.feature in feature_map:
Expand All @@ -177,7 +177,7 @@ def _build_feature_map_iter(

def _save_wxs(
destination_tree: _DestinationDirectory,
feature_map: Dict[str, List[str]],
feature_map: dict[str, list[str]],
wxs_path: pathlib.Path,
) -> None:
preamble: str = """<?xml version="1.0" encoding="UTF-8"?>
Expand Down Expand Up @@ -248,7 +248,7 @@ def _write_directory_fragment_iter(
print("{}</Directory>".format(indent), file=stream)


def _write_feature_fragment(feature_map: Dict[str, List[str]], stream: TextIO):
def _write_feature_fragment(feature_map: dict[str, list[str]], stream: TextIO) -> None:
print(' <Fragment Id="Features">', file=stream)
print(' <Feature Id="All">', file=stream)
for feature in feature_map:
Expand Down
18 changes: 9 additions & 9 deletions setup/installer/generate_content_wxs_source.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@
import re
import sys
import uuid
from typing import Dict, List, Optional, Tuple
from typing import Optional


def main(args: List[str]) -> None:
def main(args: list[str]) -> None:
"""The main function.
Args:
Expand Down Expand Up @@ -48,8 +48,8 @@ def main(args: List[str]) -> None:

def _load_files_to_install(
path: pathlib.Path,
) -> List[Tuple[str, pathlib.Path, pathlib.Path]]:
files: List[Tuple[str, pathlib.Path, pathlib.Path]] = []
) -> list[tuple[str, pathlib.Path, pathlib.Path]]:
files: list[tuple[str, pathlib.Path, pathlib.Path]] = []
with path.open(mode="r", encoding="UTF-8") as stream:
for line in stream:
line = line.rstrip("\r\n")
Expand All @@ -68,8 +68,8 @@ def _load_files_to_install(
return files


def _load_envvars_to_install(path: pathlib.Path) -> List[Tuple[str, str, str]]:
envvars: List[Tuple[str, str, str]] = []
def _load_envvars_to_install(path: pathlib.Path) -> list[tuple[str, str, str]]:
envvars: list[tuple[str, str, str]] = []
with path.open(mode="r", encoding="UTF-8") as stream:
for line in stream:
matched: Optional[re.Match[str]] = re.match(
Expand All @@ -82,7 +82,7 @@ def _load_envvars_to_install(path: pathlib.Path) -> List[Tuple[str, str, str]]:


class _FileGuidMap:
_map: Dict[pathlib.Path, Tuple[str, bool]] = {}
_map: dict[pathlib.Path, tuple[str, bool]] = {}

def __init__(self, file_guid_map_path: pathlib.Path, solution_path: pathlib.Path):
with file_guid_map_path.open(mode="r", encoding="UTF-8") as stream:
Expand Down Expand Up @@ -111,9 +111,9 @@ def save(self, file_guid_map_path: pathlib.Path) -> None:


def _make_content_wxs_source(
files_to_install: List[Tuple[str, pathlib.Path, pathlib.Path]],
files_to_install: list[tuple[str, pathlib.Path, pathlib.Path]],
file_guid_map: _FileGuidMap,
envvars_to_install: List[Tuple[str, str, str]],
envvars_to_install: list[tuple[str, str, str]],
content_wxs_source_path: pathlib.Path,
solution_path: pathlib.Path,
) -> None:
Expand Down
2 changes: 1 addition & 1 deletion tool/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ EXTRA_DIST = \


mypy: ${script_files}
${MYPY} ${srcdir}
${MYPY} ${MYPY_OPTS} ${srcdir}

format: ${script_files}
${BLACK} ${srcdir}
Expand Down
20 changes: 10 additions & 10 deletions tool/make_character_property_map.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@
import pathlib
import re
import sys
from typing import List, Optional
from typing import Optional


def main(args: List[str]) -> None:
def main(args: list[str]) -> None:
"""The main function.
Args:
Expand All @@ -22,16 +22,16 @@ def main(args: List[str]) -> None:
file=sys.stderr,
)
sys.exit(0)
east_asian_width_map: List[str] = _load_file(pathlib.Path(args[0]), "N")
emoji_data_map: List[str] = _load_file(pathlib.Path(args[1]), "N")
grapheme_map: List[str] = _load_file(pathlib.Path(args[2]), "Other")
east_asian_width_map: list[str] = _load_file(pathlib.Path(args[0]), "N")
emoji_data_map: list[str] = _load_file(pathlib.Path(args[1]), "N")
grapheme_map: list[str] = _load_file(pathlib.Path(args[2]), "Other")
_save_file(
pathlib.Path(args[3]), east_asian_width_map, emoji_data_map, grapheme_map
)


def _load_file(path: pathlib.Path, default_value: str) -> List[str]:
map: List[str] = [default_value for code in range(0x110000)]
def _load_file(path: pathlib.Path, default_value: str) -> list[str]:
map: list[str] = [default_value for code in range(0x110000)]
with path.open(mode="r", encoding="UTF-8") as stream:
for line in stream:
line = _remove_comment(line)
Expand Down Expand Up @@ -64,9 +64,9 @@ def _remove_comment(line: str) -> str:

def _save_file(
path: pathlib.Path,
east_asian_width_map: List[str],
emoji_data_map: List[str],
grapheme_map: List[str],
east_asian_width_map: list[str],
emoji_data_map: list[str],
grapheme_map: list[str],
) -> None:
with path.open(mode="w", newline="\r\n", encoding="UTF-8") as stream:
previous_value: str = ""
Expand Down
11 changes: 5 additions & 6 deletions tool/make_character_property_map_cpp.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,9 @@

import pathlib
import sys
from typing import List


def main(args: List[str]) -> None:
def main(args: list[str]) -> None:
"""The main function.
Args:
Expand All @@ -21,13 +20,13 @@ def main(args: List[str]) -> None:
file=sys.stderr,
)
sys.exit(0)
elements: List[str] = _load_file(pathlib.Path(args[0]))
elements: list[str] = _load_file(pathlib.Path(args[0]))
content: str = _make_cpp_source(elements)
_save_file(pathlib.Path(args[1]), content)


def _load_file(path: pathlib.Path) -> List[str]:
elements: List[str] = []
def _load_file(path: pathlib.Path) -> list[str]:
elements: list[str] = []
with path.open(mode="r") as stream:
for line in stream:
line = line.rstrip("\r\n")
Expand Down Expand Up @@ -106,7 +105,7 @@ def _to_grapheme_break_property(symbol: str) -> str:
raise RuntimeError("Unknown grapheme: {}".format(symbol))


def _make_cpp_source(elements: List[str]) -> str:
def _make_cpp_source(elements: list[str]) -> str:
content: str = """/*! \\file
\\brief A character property map.
Expand Down

0 comments on commit 9ae7dc6

Please sign in to comment.