Cleanup: Address mypy errors and warnings

Pull Request: https://projects.blender.org/blender/blender/pulls/118844
This commit is contained in:
Sergey Sharybin 2024-02-28 11:25:44 +01:00 committed by Sergey Sharybin
parent 503de16353
commit 4bc1ba3c2d
3 changed files with 15 additions and 14 deletions

View File

@ -54,7 +54,7 @@ if not (lib_tests_dirpath / ".git").exists():
sys.exit(1)
# Ensure the test data files sub-module is configured and present.
make_utils.git_enable_submodule(git_command, "tests/data")
make_utils.git_enable_submodule(git_command, Path("tests") / "data")
make_utils.git_update_submodule(args.git_command, lib_tests_dirpath)
# Run cmake again to detect tests files.

View File

@ -106,10 +106,10 @@ def get_effective_architecture(args: argparse.Namespace) -> str:
assert (architecture in ("x64", "arm64"))
return architecture
return str(architecture)
def get_submodule_directories(args: argparse.Namespace):
def get_submodule_directories(args: argparse.Namespace) -> list[Path]:
"""
Get list of all configured submodule directories.
"""
@ -118,10 +118,10 @@ def get_submodule_directories(args: argparse.Namespace):
dot_modules = blender_git_root / ".gitmodules"
if not dot_modules.exists():
return ()
return []
submodule_directories_output = check_output(
[args.git_command, "config", "--file", dot_modules, "--get-regexp", "path"])
[args.git_command, "config", "--file", str(dot_modules), "--get-regexp", "path"])
return [Path(line.split(' ', 1)[1]) for line in submodule_directories_output.strip().splitlines()]
@ -304,7 +304,7 @@ def external_script_copy_old_submodule_over(
def floating_checkout_initialize_if_needed(args: argparse.Namespace,
repo_name: str,
directory: Path,
old_submodules_dir: Path = None) -> None:
old_submodules_dir: Optional[Path] = None) -> None:
"""Initialize checkout of an external repository"""
blender_git_root = get_blender_git_root()
@ -397,8 +397,8 @@ def floating_checkout_update(args: argparse.Namespace,
repo_name: str,
directory: Path,
branch: Optional[str],
old_submodules_dir: Path = None,
only_update=False) -> str:
old_submodules_dir: Optional[Path] = None,
only_update: bool = False) -> str:
"""Update a single external checkout with the given name in the scripts folder"""
blender_git_root = get_blender_git_root()
@ -499,7 +499,7 @@ def floating_libraries_update(args: argparse.Namespace, branch: Optional[str]) -
return msg
def add_submodule_push_url(args: argparse.Namespace):
def add_submodule_push_url(args: argparse.Namespace) -> None:
"""
Add pushURL configuration for all locally activated submodules, pointing to SSH protocol.
"""

View File

@ -20,7 +20,8 @@ from typing import (
)
def call(cmd: Sequence[str], exit_on_error: bool = True, silent: bool = False, env=None) -> int:
def call(cmd: Sequence[str], exit_on_error: bool = True,
silent: bool = False, env: Optional[dict[str, str]] = None) -> int:
if not silent:
cmd_str = ""
if env:
@ -135,7 +136,7 @@ def _git_submodule_config_key(submodule_dir: Path, key: str) -> str:
return f"submodule.{submodule_dir_str}.{key}"
def is_git_submodule_enabled(git_command: str, submodule_dir: Path):
def is_git_submodule_enabled(git_command: str, submodule_dir: Path) -> bool:
"""Check whether submodule denoted by its directory within the repository is enabled"""
git_root = Path(check_output([git_command, "rev-parse", "--show-toplevel"]))
@ -158,7 +159,7 @@ def is_git_submodule_enabled(git_command: str, submodule_dir: Path):
return update.lower() != "none"
def git_enable_submodule(git_command: str, submodule_dir: Path):
def git_enable_submodule(git_command: str, submodule_dir: Path) -> None:
"""Enable submodule denoted by its directory within the repository"""
command = (git_command,
@ -200,11 +201,11 @@ def git_update_submodule(git_command: str, submodule_dir: Path) -> bool:
env = {"GIT_LFS_SKIP_SMUDGE": "1"}
if call((git_command, "submodule", "update", "--init", "--progress", submodule_dir),
if call((git_command, "submodule", "update", "--init", "--progress", str(submodule_dir)),
exit_on_error=False, env=env) != 0:
return False
return call((git_command, "-C", submodule_dir, "lfs", "pull"),
return call((git_command, "-C", str(submodule_dir), "lfs", "pull"),
exit_on_error=False) == 0