diff --git a/build_files/cmake/cmake_print_build_options.py b/build_files/cmake/cmake_print_build_options.py index 1ff08e90f38..5bdd4320280 100644 --- a/build_files/cmake/cmake_print_build_options.py +++ b/build_files/cmake/cmake_print_build_options.py @@ -8,8 +8,6 @@ import re import sys -from typing import Optional - cmakelists_file = sys.argv[-1] @@ -24,7 +22,7 @@ def count_backslashes_before_pos(file_data: str, pos: int) -> int: return slash_count -def extract_cmake_string_at_pos(file_data: str, pos_beg: int) -> Optional[str]: +def extract_cmake_string_at_pos(file_data: str, pos_beg: int) -> str | None: assert file_data[pos_beg - 1] == '"' pos = pos_beg diff --git a/build_files/cmake/cmake_static_check_clang.py b/build_files/cmake/cmake_static_check_clang.py index 0f39e816098..2b6d3ccd1f6 100644 --- a/build_files/cmake/cmake_static_check_clang.py +++ b/build_files/cmake/cmake_static_check_clang.py @@ -21,11 +21,9 @@ import sys from typing import ( Any, - Dict, - List, - Type, +) +from collections.abc import ( Sequence, - Tuple, ) @@ -95,7 +93,7 @@ class ClangChecker: """ __slots__ = () - def __new__(cls, *args: Tuple[Any], **kwargs: Dict[str, Any]) -> Any: + def __new__(cls, *args: tuple[Any], **kwargs: dict[str, Any]) -> Any: raise RuntimeError("%s should not be instantiated" % cls) @staticmethod @@ -104,7 +102,7 @@ class ClangChecker: _file_data: bytes, _tu: ClangTranslationUnit, _shared_check_data: Any, - ) -> List[str]: + ) -> list[str]: raise RuntimeError("This function must be overridden by it's subclass!") return [] @@ -150,9 +148,9 @@ class clang_checkers: node_parent: ClangNode, level: int, # Used to build data. - struct_decl_map: Dict[str, ClangNode], - struct_type_map: Dict[str, str], - output: List[str], + struct_decl_map: dict[str, ClangNode], + struct_type_map: dict[str, str], + output: list[str], ) -> None: # Needed to read back the node. @@ -344,11 +342,11 @@ class clang_checkers: filepath: str, file_data: bytes, tu: ClangTranslationUnit, - _shared_check_data: Any) -> List[str]: - output: List[str] = [] + _shared_check_data: Any) -> list[str]: + output: list[str] = [] - struct_decl_map: Dict[str, Any] = {} - struct_type_map: Dict[str, str] = {} + struct_decl_map: dict[str, Any] = {} + struct_type_map: dict[str, str] = {} clang_checkers.struct_comments._struct_check_comments_recursive( filepath, file_data, tu.cursor, None, 0, @@ -361,7 +359,7 @@ class clang_checkers: # ----------------------------------------------------------------------------- # Checker Class Access -def check_function_get_all() -> List[str]: +def check_function_get_all() -> list[str]: checkers = [] for name in dir(clang_checkers): value = getattr(clang_checkers, name) @@ -371,7 +369,7 @@ def check_function_get_all() -> List[str]: return checkers -def check_class_from_id(name: str) -> Type[ClangChecker]: +def check_class_from_id(name: str) -> type[ClangChecker]: result = getattr(clang_checkers, name) assert issubclass(result, ClangChecker) # MYPY 0.812 doesn't recognize the assert above. @@ -402,7 +400,7 @@ def check_source_file( with open(filepath, "rb") as fh: file_data = fh.read() - output: List[str] = [] + output: list[str] = [] # we don't really care what we are looking at, just scan entire file for # function calls. @@ -415,14 +413,14 @@ def check_source_file( return "\n".join(output) -def check_source_file_for_imap(args: Tuple[str, Sequence[str], Sequence[str], Sequence[Any]]) -> str: +def check_source_file_for_imap(args: tuple[str, Sequence[str], Sequence[str], Sequence[Any]]) -> str: return check_source_file(*args) def source_info_filter( - source_info: List[Tuple[str, List[str], List[str]]], + source_info: list[tuple[str, list[str], list[str]]], regex_list: Sequence[re.Pattern[str]], -) -> List[Tuple[str, List[str], List[str]]]: +) -> list[tuple[str, list[str], list[str]]]: source_dir = project_source_info.SOURCE_DIR if not source_dir.endswith(os.sep): source_dir += os.sep diff --git a/build_files/cmake/cmake_static_check_cppcheck.py b/build_files/cmake/cmake_static_check_cppcheck.py index 6e6d8d52b75..c6bcac0c467 100644 --- a/build_files/cmake/cmake_static_check_cppcheck.py +++ b/build_files/cmake/cmake_static_check_cppcheck.py @@ -13,10 +13,7 @@ import time from typing import ( Any, - Dict, IO, - List, - Tuple, ) USE_VERBOSE = (os.environ.get("VERBOSE", None) is not None) @@ -135,10 +132,10 @@ CHECKER_EXCLUDE_FROM_SUMMARY = { def source_info_filter( - source_info: List[Tuple[str, List[str], List[str]]], + source_info: list[tuple[str, list[str], list[str]]], source_dir: str, cmake_dir: str, -) -> List[Tuple[str, List[str], List[str]]]: +) -> list[tuple[str, list[str], list[str]]]: source_dir = source_dir.rstrip(os.sep) + os.sep cmake_dir = cmake_dir.rstrip(os.sep) + os.sep @@ -238,7 +235,7 @@ def cppcheck(cppcheck_dir: str, temp_dir: str, log_fh: IO[bytes]) -> None: process_functions = [] - def my_process(i: int, c: str, cmd: List[str]) -> subprocess.Popen[Any]: + def my_process(i: int, c: str, cmd: list[str]) -> subprocess.Popen[Any]: proc = subprocess.Popen( cmd, stderr=subprocess.PIPE, @@ -256,7 +253,7 @@ def cppcheck(cppcheck_dir: str, temp_dir: str, log_fh: IO[bytes]) -> None: index_current = 0 index_count = 0 - proc_results_by_index: Dict[int, Tuple[bytes, bytes]] = {} + proc_results_by_index: dict[int, tuple[bytes, bytes]] = {} def process_finalize( proc: subprocess.Popen[Any], @@ -321,7 +318,7 @@ def cppcheck_generate_summary( # Avoids many duplicate lines generated by headers. lines_unique = set() - category: Dict[str, List[str]] = {} + category: dict[str, list[str]] = {} re_match = re.compile(".* \\[([a-zA-Z_]+)\\]$") for line in log_fh: if not line.startswith(filter_line_prefix): diff --git a/build_files/cmake/project_info.py b/build_files/cmake/project_info.py index 84fd49bec2a..ee16b6709fd 100755 --- a/build_files/cmake/project_info.py +++ b/build_files/cmake/project_info.py @@ -28,12 +28,10 @@ __all__ = ( ) from typing import ( - Callable, Generator, - List, - Optional, - Union, - Tuple, +) +from collections.abc import ( + Callable, ) @@ -86,7 +84,7 @@ def init(cmake_path: str) -> bool: def source_list( path: str, - filename_check: Optional[Callable[[str], bool]] = None, + filename_check: Callable[[str], bool] | None = None, ) -> Generator[str, None, None]: for dirpath, dirnames, filenames in os.walk(path): # skip '.git' @@ -138,7 +136,10 @@ def is_project_file(filename: str) -> bool: return (is_c_any(filename) or is_cmake(filename) or is_glsl(filename)) # and is_svn_file(filename) -def cmake_advanced_info() -> Union[Tuple[List[str], List[Tuple[str, str]]], Tuple[None, None]]: +def cmake_advanced_info() -> ( + tuple[list[str], list[tuple[str, str]]] | + tuple[None, None] +): """ Extract includes and defines from cmake. """ @@ -219,7 +220,7 @@ def cmake_advanced_info() -> Union[Tuple[List[str], List[Tuple[str, str]]], Tupl return includes, defines -def cmake_cache_var(var: str) -> Optional[str]: +def cmake_cache_var(var: str) -> str | None: with open(os.path.join(CMAKE_DIR, "CMakeCache.txt"), encoding='utf-8') as cache_file: lines = [ l_strip for l in cache_file @@ -233,7 +234,7 @@ def cmake_cache_var(var: str) -> Optional[str]: return None -def cmake_compiler_defines() -> Optional[List[str]]: +def cmake_compiler_defines() -> list[str] | None: compiler = cmake_cache_var("CMAKE_C_COMPILER") # could do CXX too if compiler is None: @@ -255,5 +256,5 @@ def cmake_compiler_defines() -> Optional[List[str]]: return lines -def project_name_get() -> Optional[str]: +def project_name_get() -> str | None: return cmake_cache_var("CMAKE_PROJECT_NAME") diff --git a/build_files/cmake/project_source_info.py b/build_files/cmake/project_source_info.py index 5faab99eb4f..79ef7eb916a 100644 --- a/build_files/cmake/project_source_info.py +++ b/build_files/cmake/project_source_info.py @@ -22,14 +22,12 @@ import subprocess from typing import ( Any, - Callable, Generator, IO, - List, - Optional, +) +from collections.abc import ( + Callable, Sequence, - Tuple, - Union, ) import shlex @@ -58,7 +56,7 @@ def is_c_any(filename: str) -> bool: CMAKE_DIR = "." -def cmake_cache_var_iter() -> Generator[Tuple[str, str, str], None, None]: +def cmake_cache_var_iter() -> Generator[tuple[str, str, str], None, None]: import re re_cache = re.compile(r'([A-Za-z0-9_\-]+)?:?([A-Za-z0-9_\-]+)?=(.*)$') with open(join(CMAKE_DIR, "CMakeCache.txt"), 'r', encoding='utf-8') as cache_file: @@ -69,7 +67,7 @@ def cmake_cache_var_iter() -> Generator[Tuple[str, str, str], None, None]: yield (var, type_ or "", val) -def cmake_cache_var(var: str) -> Optional[str]: +def cmake_cache_var(var: str) -> str | None: for var_iter, type_iter, value_iter in cmake_cache_var_iter(): if var == var_iter: return value_iter @@ -84,7 +82,7 @@ def cmake_cache_var_or_exit(var: str) -> str: return value -def do_ignore(filepath: str, ignore_prefix_list: Optional[Sequence[str]]) -> bool: +def do_ignore(filepath: str, ignore_prefix_list: Sequence[str] | None) -> bool: if ignore_prefix_list is None: return False @@ -92,7 +90,7 @@ def do_ignore(filepath: str, ignore_prefix_list: Optional[Sequence[str]]) -> boo return any([relpath.startswith(prefix) for prefix in ignore_prefix_list]) -def makefile_log() -> List[str]: +def makefile_log() -> list[str]: import subprocess import time @@ -132,8 +130,8 @@ def makefile_log() -> List[str]: def build_info( use_c: bool = True, use_cxx: bool = True, - ignore_prefix_list: Optional[List[str]] = None, -) -> List[Tuple[str, List[str], List[str]]]: + ignore_prefix_list: list[str] | None = None, +) -> list[tuple[str, list[str], list[str]]]: makelog = makefile_log() source = [] @@ -151,7 +149,7 @@ def build_info( print("parsing make log ...") for line in makelog: - args_orig: Union[str, List[str]] = line.split() + args_orig: str | list[str] = line.split() args = [fake_compiler if c in compilers else c for c in args_orig] if args == args_orig: # No compilers in the command, skip. @@ -218,7 +216,7 @@ def build_defines_as_source() -> str: return stdout.read().strip().decode('ascii') -def build_defines_as_args() -> List[str]: +def build_defines_as_args() -> list[str]: return [ ("-D" + "=".join(l.split(maxsplit=2)[1:])) for l in build_defines_as_source().split("\n") @@ -240,11 +238,11 @@ def process_make_non_blocking(proc: subprocess.Popen[Any]) -> subprocess.Popen[A # could be moved elsewhere!, this just happens to be used by scripts that also # use this module. def queue_processes( - process_funcs: Sequence[Tuple[Callable[..., subprocess.Popen[Any]], Tuple[Any, ...]]], + process_funcs: Sequence[tuple[Callable[..., subprocess.Popen[Any]], tuple[Any, ...]]], *, job_total: int = -1, sleep: float = 0.1, - process_finalize: Optional[Callable[[subprocess.Popen[Any], bytes, bytes], Optional[int]]] = None, + process_finalize: Callable[[subprocess.Popen[Any], bytes, bytes], int | None] | None = None, ) -> None: """ Takes a list of function arg pairs, each function must return a process """ @@ -269,9 +267,9 @@ def queue_processes( if process_finalize is not None: def poll_and_finalize( p: subprocess.Popen[Any], - stdout: List[bytes], - stderr: List[bytes], - ) -> Optional[int]: + stdout: list[bytes], + stderr: list[bytes], + ) -> int | None: assert p.stdout is not None if data := p.stdout.read(): stdout.append(data) @@ -290,12 +288,12 @@ def queue_processes( else: def poll_and_finalize( p: subprocess.Popen[Any], - stdout: List[bytes], - stderr: List[bytes], - ) -> Optional[int]: + stdout: list[bytes], + stderr: list[bytes], + ) -> int | None: return p.poll() - processes: List[Tuple[subprocess.Popen[Any], List[bytes], List[bytes]]] = [] + processes: list[tuple[subprocess.Popen[Any], list[bytes], list[bytes]]] = [] for func, args in process_funcs: # wait until a thread is free while 1: diff --git a/build_files/utils/make_bpy_wheel.py b/build_files/utils/make_bpy_wheel.py index 616b52d2e06..24bdc311fdd 100755 --- a/build_files/utils/make_bpy_wheel.py +++ b/build_files/utils/make_bpy_wheel.py @@ -31,10 +31,9 @@ import sys from typing import ( Generator, - List, - Optional, +) +from collections.abc import ( Sequence, - Tuple, ) # ------------------------------------------------------------------------------ @@ -90,7 +89,7 @@ def find_dominating_file( # ------------------------------------------------------------------------------ # CMake Cache Access -def cmake_cache_var_iter(filepath_cmake_cache: str) -> Generator[Tuple[str, str, str], None, None]: +def cmake_cache_var_iter(filepath_cmake_cache: str) -> Generator[tuple[str, str, str], None, None]: re_cache = re.compile(r"([A-Za-z0-9_\-]+)?:?([A-Za-z0-9_\-]+)?=(.*)$") with open(filepath_cmake_cache, "r", encoding="utf-8") as cache_file: for l in cache_file: @@ -100,7 +99,7 @@ def cmake_cache_var_iter(filepath_cmake_cache: str) -> Generator[Tuple[str, str, yield (var, type_ or "", val) -def cmake_cache_var(filepath_cmake_cache: str, var: str) -> Optional[str]: +def cmake_cache_var(filepath_cmake_cache: str, var: str) -> str | None: for var_iter, type_iter, value_iter in cmake_cache_var_iter(filepath_cmake_cache): if var == var_iter: return value_iter @@ -209,7 +208,7 @@ def main() -> None: os.chdir(install_dir) # Include all files recursively. - def package_files(root_dir: str) -> List[str]: + def package_files(root_dir: str) -> list[str]: paths = [] for path, dirs, files in os.walk(root_dir): paths += [os.path.join("..", path, f) for f in files] diff --git a/build_files/utils/make_source_archive.py b/build_files/utils/make_source_archive.py index c811a45988f..8c0450b9ebd 100755 --- a/build_files/utils/make_source_archive.py +++ b/build_files/utils/make_source_archive.py @@ -9,7 +9,14 @@ import os import subprocess import sys from pathlib import Path -from typing import Iterable, TextIO, Optional, Any, Union + +from typing import ( + TextIO, + Any, +) +from collections.abc import ( + Iterable, +) # This script can run from any location, # output is created in the $CWD @@ -88,7 +95,7 @@ def manifest_path(tarball: Path) -> Path: return without_suffix.with_name(f"{name}-manifest.txt") -def packages_path(current_directory: Path, cli_args: Any) -> Optional[Path]: +def packages_path(current_directory: Path, cli_args: Any) -> Path | None: if not cli_args.include_packages: return None @@ -109,7 +116,7 @@ def create_manifest( version: make_utils.BlenderVersion, outpath: Path, blender_srcdir: Path, - packages_dir: Optional[Path], + packages_dir: Path | None, ) -> None: print(f'Building manifest of files: "{outpath}"...', end="", flush=True) with outpath.open("w", encoding="utf-8") as outfile: @@ -157,7 +164,7 @@ def create_tarball( tarball: Path, manifest: Path, blender_srcdir: Path, - packages_dir: Optional[Path], + packages_dir: Path | None, ) -> None: print(f'Creating archive: "{tarball}" ...', end="", flush=True) @@ -231,7 +238,7 @@ def git_ls_files(directory: Path = Path(".")) -> Iterable[Path]: yield path -def git_command(*cli_args: Union[bytes, str, Path]) -> Iterable[str]: +def git_command(*cli_args: bytes | str | Path) -> Iterable[str]: """Generator, yields lines of output from a Git command.""" command = ("git", *cli_args) diff --git a/build_files/utils/make_update.py b/build_files/utils/make_update.py index 21e1c07b342..de45439ec73 100755 --- a/build_files/utils/make_update.py +++ b/build_files/utils/make_update.py @@ -22,11 +22,6 @@ from pathlib import Path from make_utils import call, check_output from urllib.parse import urljoin, urlsplit -from typing import ( - Optional, - Tuple, -) - def print_stage(text: str) -> None: print("") @@ -96,7 +91,7 @@ def get_effective_architecture(args: argparse.Namespace) -> str: NOTE: When cross-compiling the architecture is coming from the command line argument. """ - architecture: Optional[str] = args.architecture + architecture: str | None = args.architecture if architecture: assert isinstance(architecture, str) elif "ARM64" in platform.version(): @@ -117,7 +112,7 @@ def get_effective_architecture(args: argparse.Namespace) -> str: return architecture -def get_submodule_directories(args: argparse.Namespace) -> Tuple[Path, ...]: +def get_submodule_directories(args: argparse.Namespace) -> tuple[Path, ...]: """ Get list of all configured submodule directories. """ @@ -341,7 +336,7 @@ def floating_checkout_initialize_if_needed( args: argparse.Namespace, repo_name: str, directory: Path, - old_submodules_dir: Optional[Path] = None, + old_submodules_dir: Path | None = None, ) -> None: """Initialize checkout of an external repository""" @@ -437,8 +432,8 @@ def floating_checkout_update( args: argparse.Namespace, repo_name: str, directory: Path, - branch: Optional[str], - old_submodules_dir: Optional[Path] = None, + branch: str | None, + old_submodules_dir: Path | None = None, only_update: bool = False, ) -> str: """Update a single external checkout with the given name in the scripts folder""" @@ -521,7 +516,7 @@ def external_scripts_update( args: argparse.Namespace, repo_name: str, directory_name: str, - branch: Optional[str], + branch: str | None, ) -> str: return floating_checkout_update( args, @@ -532,7 +527,7 @@ def external_scripts_update( ) -def floating_libraries_update(args: argparse.Namespace, branch: Optional[str]) -> str: +def floating_libraries_update(args: argparse.Namespace, branch: str | None) -> str: """Update libraries checkouts which are floating (not attached as Git submodules)""" msg = "" @@ -585,7 +580,7 @@ def add_submodule_push_url(args: argparse.Namespace) -> None: make_utils.git_set_config(args.git_command, "remote.origin.pushURL", push_url, str(config)) -def submodules_lib_update(args: argparse.Namespace, branch: Optional[str]) -> str: +def submodules_lib_update(args: argparse.Namespace, branch: str | None) -> str: print_stage("Updating Libraries") msg = "" diff --git a/build_files/utils/make_utils.py b/build_files/utils/make_utils.py index c1b98f02b76..7a9bb038b3e 100755 --- a/build_files/utils/make_utils.py +++ b/build_files/utils/make_utils.py @@ -15,10 +15,8 @@ import subprocess import sys from pathlib import Path -from typing import ( - Dict, +from collections.abc import ( Sequence, - Optional, ) @@ -26,7 +24,7 @@ def call( cmd: Sequence[str], exit_on_error: bool = True, silent: bool = False, - env: Optional[Dict[str, str]] = None, + env: dict[str, str] | None = None, ) -> int: if not silent: cmd_str = "" @@ -124,14 +122,14 @@ def git_branch(git_command: str) -> str: return branch.strip().decode('utf8') -def git_get_config(git_command: str, key: str, file: Optional[str] = None) -> str: +def git_get_config(git_command: str, key: str, file: str | None = None) -> str: if file: return check_output([git_command, "config", "--file", file, "--get", key]) return check_output([git_command, "config", "--get", key]) -def git_set_config(git_command: str, key: str, value: str, file: Optional[str] = None) -> str: +def git_set_config(git_command: str, key: str, value: str, file: str | None = None) -> str: if file: return check_output([git_command, "config", "--file", file, key, value])