Cleanup: Correction to type annotation and smaller fixes/optimizations
This commit contains changes done to these scripts in the main branch.
This commit is contained in:
@@ -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.
|
||||
|
||||
@@ -22,7 +22,10 @@ from pathlib import Path
|
||||
from make_utils import call, check_output
|
||||
from urllib.parse import urljoin, urlsplit
|
||||
|
||||
from typing import Optional
|
||||
from typing import (
|
||||
Optional,
|
||||
Tuple,
|
||||
)
|
||||
|
||||
|
||||
def print_stage(text: str) -> None:
|
||||
@@ -91,7 +94,7 @@ def get_effective_architecture(args: argparse.Namespace) -> str:
|
||||
NOTE: When cross-compiling the architecture is coming from the command line
|
||||
argument.
|
||||
"""
|
||||
architecture = args.architecture
|
||||
architecture: Optional[str] = args.architecture
|
||||
if architecture:
|
||||
assert isinstance(architecture, str)
|
||||
elif "ARM64" in platform.version():
|
||||
@@ -101,15 +104,16 @@ def get_effective_architecture(args: argparse.Namespace) -> str:
|
||||
architecture = platform.machine().lower()
|
||||
|
||||
# Normalize the architecture name.
|
||||
if architecture in ("x86_64", "amd64"):
|
||||
if architecture in {"x86_64", "amd64"}:
|
||||
architecture = "x64"
|
||||
|
||||
assert (architecture in ("x64", "arm64"))
|
||||
assert (architecture in {"x64", "arm64"})
|
||||
|
||||
assert isinstance(architecture, str)
|
||||
return architecture
|
||||
|
||||
|
||||
def get_submodule_directories(args: argparse.Namespace):
|
||||
def get_submodule_directories(args: argparse.Namespace) -> Tuple[Path, ...]:
|
||||
"""
|
||||
Get list of all configured submodule directories.
|
||||
"""
|
||||
@@ -121,8 +125,8 @@ def get_submodule_directories(args: argparse.Namespace):
|
||||
return ()
|
||||
|
||||
submodule_directories_output = check_output(
|
||||
[args.git_command, "config", "--file", dot_modules, "--get-regexp", "path"])
|
||||
return [Path(line.split(' ', 1)[1]) for line in submodule_directories_output.strip().splitlines()]
|
||||
[args.git_command, "config", "--file", str(dot_modules), "--get-regexp", "path"])
|
||||
return tuple([Path(line.split(' ', 1)[1]) for line in submodule_directories_output.strip().splitlines()])
|
||||
|
||||
|
||||
def ensure_git_lfs(args: argparse.Namespace) -> None:
|
||||
@@ -281,7 +285,8 @@ def resolve_external_url(blender_url: str, repo_name: str) -> str:
|
||||
def external_script_copy_old_submodule_over(
|
||||
args: argparse.Namespace,
|
||||
directory: Path,
|
||||
old_submodules_dir: Path) -> None:
|
||||
old_submodules_dir: Path,
|
||||
) -> None:
|
||||
blender_git_root = get_blender_git_root()
|
||||
external_dir = blender_git_root / directory
|
||||
|
||||
@@ -301,10 +306,12 @@ def external_script_copy_old_submodule_over(
|
||||
call((args.git_command, "config", "--file", str(git_config), "--unset", "core.worktree"))
|
||||
|
||||
|
||||
def floating_checkout_initialize_if_needed(args: argparse.Namespace,
|
||||
repo_name: str,
|
||||
directory: Path,
|
||||
old_submodules_dir: Path = None) -> None:
|
||||
def floating_checkout_initialize_if_needed(
|
||||
args: argparse.Namespace,
|
||||
repo_name: str,
|
||||
directory: Path,
|
||||
old_submodules_dir: Optional[Path] = None,
|
||||
) -> None:
|
||||
"""Initialize checkout of an external repository"""
|
||||
|
||||
blender_git_root = get_blender_git_root()
|
||||
@@ -334,9 +341,11 @@ def floating_checkout_initialize_if_needed(args: argparse.Namespace,
|
||||
call((args.git_command, "clone", "--origin", origin_name, external_url, str(external_dir)))
|
||||
|
||||
|
||||
def floating_checkout_add_origin_if_needed(args: argparse.Namespace,
|
||||
repo_name: str,
|
||||
directory: Path) -> None:
|
||||
def floating_checkout_add_origin_if_needed(
|
||||
args: argparse.Namespace,
|
||||
repo_name: str,
|
||||
directory: Path,
|
||||
) -> None:
|
||||
"""
|
||||
Add remote called 'origin' if there is a fork of the external repository available
|
||||
|
||||
@@ -393,12 +402,14 @@ def floating_checkout_add_origin_if_needed(args: argparse.Namespace,
|
||||
return
|
||||
|
||||
|
||||
def floating_checkout_update(args: argparse.Namespace,
|
||||
repo_name: str,
|
||||
directory: Path,
|
||||
branch: Optional[str],
|
||||
old_submodules_dir: Path = None,
|
||||
only_update=False) -> str:
|
||||
def floating_checkout_update(
|
||||
args: argparse.Namespace,
|
||||
repo_name: str,
|
||||
directory: Path,
|
||||
branch: Optional[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()
|
||||
@@ -475,31 +486,37 @@ def floating_checkout_update(args: argparse.Namespace,
|
||||
return skip_msg
|
||||
|
||||
|
||||
def external_scripts_update(args: argparse.Namespace,
|
||||
repo_name: str,
|
||||
directory_name: str,
|
||||
branch: Optional[str]) -> str:
|
||||
return floating_checkout_update(args,
|
||||
repo_name,
|
||||
Path("scripts") / directory_name,
|
||||
branch,
|
||||
old_submodules_dir=Path("release") / "scripts" / directory_name)
|
||||
def external_scripts_update(
|
||||
args: argparse.Namespace,
|
||||
repo_name: str,
|
||||
directory_name: str,
|
||||
branch: Optional[str],
|
||||
) -> str:
|
||||
return floating_checkout_update(
|
||||
args,
|
||||
repo_name,
|
||||
Path("scripts") / directory_name,
|
||||
branch,
|
||||
old_submodules_dir=Path("release") / "scripts" / directory_name,
|
||||
)
|
||||
|
||||
|
||||
def floating_libraries_update(args: argparse.Namespace, branch: Optional[str]) -> str:
|
||||
"""Update libraries checkouts which are floating (not attached as Git submodules)"""
|
||||
msg = ""
|
||||
|
||||
msg += floating_checkout_update(args,
|
||||
"benchmarks",
|
||||
Path("tests") / "benchmarks",
|
||||
branch,
|
||||
only_update=True)
|
||||
msg += floating_checkout_update(
|
||||
args,
|
||||
"benchmarks",
|
||||
Path("tests") / "benchmarks",
|
||||
branch,
|
||||
only_update=True,
|
||||
)
|
||||
|
||||
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.
|
||||
"""
|
||||
|
||||
@@ -15,12 +15,18 @@ import sys
|
||||
from pathlib import Path
|
||||
|
||||
from typing import (
|
||||
Dict,
|
||||
Sequence,
|
||||
Optional,
|
||||
)
|
||||
|
||||
|
||||
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 +141,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 +164,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 +206,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
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user