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)
|
sys.exit(1)
|
||||||
|
|
||||||
# Ensure the test data files sub-module is configured and present.
|
# 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)
|
make_utils.git_update_submodule(args.git_command, lib_tests_dirpath)
|
||||||
|
|
||||||
# Run cmake again to detect tests files.
|
# Run cmake again to detect tests files.
|
||||||
|
|||||||
@@ -22,7 +22,10 @@ from pathlib import Path
|
|||||||
from make_utils import call, check_output
|
from make_utils import call, check_output
|
||||||
from urllib.parse import urljoin, urlsplit
|
from urllib.parse import urljoin, urlsplit
|
||||||
|
|
||||||
from typing import Optional
|
from typing import (
|
||||||
|
Optional,
|
||||||
|
Tuple,
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
def print_stage(text: str) -> None:
|
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
|
NOTE: When cross-compiling the architecture is coming from the command line
|
||||||
argument.
|
argument.
|
||||||
"""
|
"""
|
||||||
architecture = args.architecture
|
architecture: Optional[str] = args.architecture
|
||||||
if architecture:
|
if architecture:
|
||||||
assert isinstance(architecture, str)
|
assert isinstance(architecture, str)
|
||||||
elif "ARM64" in platform.version():
|
elif "ARM64" in platform.version():
|
||||||
@@ -101,15 +104,16 @@ def get_effective_architecture(args: argparse.Namespace) -> str:
|
|||||||
architecture = platform.machine().lower()
|
architecture = platform.machine().lower()
|
||||||
|
|
||||||
# Normalize the architecture name.
|
# Normalize the architecture name.
|
||||||
if architecture in ("x86_64", "amd64"):
|
if architecture in {"x86_64", "amd64"}:
|
||||||
architecture = "x64"
|
architecture = "x64"
|
||||||
|
|
||||||
assert (architecture in ("x64", "arm64"))
|
assert (architecture in {"x64", "arm64"})
|
||||||
|
|
||||||
|
assert isinstance(architecture, str)
|
||||||
return architecture
|
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.
|
Get list of all configured submodule directories.
|
||||||
"""
|
"""
|
||||||
@@ -121,8 +125,8 @@ def get_submodule_directories(args: argparse.Namespace):
|
|||||||
return ()
|
return ()
|
||||||
|
|
||||||
submodule_directories_output = check_output(
|
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()]
|
return tuple([Path(line.split(' ', 1)[1]) for line in submodule_directories_output.strip().splitlines()])
|
||||||
|
|
||||||
|
|
||||||
def ensure_git_lfs(args: argparse.Namespace) -> None:
|
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(
|
def external_script_copy_old_submodule_over(
|
||||||
args: argparse.Namespace,
|
args: argparse.Namespace,
|
||||||
directory: Path,
|
directory: Path,
|
||||||
old_submodules_dir: Path) -> None:
|
old_submodules_dir: Path,
|
||||||
|
) -> None:
|
||||||
blender_git_root = get_blender_git_root()
|
blender_git_root = get_blender_git_root()
|
||||||
external_dir = blender_git_root / directory
|
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"))
|
call((args.git_command, "config", "--file", str(git_config), "--unset", "core.worktree"))
|
||||||
|
|
||||||
|
|
||||||
def floating_checkout_initialize_if_needed(args: argparse.Namespace,
|
def floating_checkout_initialize_if_needed(
|
||||||
repo_name: str,
|
args: argparse.Namespace,
|
||||||
directory: Path,
|
repo_name: str,
|
||||||
old_submodules_dir: Path = None) -> None:
|
directory: Path,
|
||||||
|
old_submodules_dir: Optional[Path] = None,
|
||||||
|
) -> None:
|
||||||
"""Initialize checkout of an external repository"""
|
"""Initialize checkout of an external repository"""
|
||||||
|
|
||||||
blender_git_root = get_blender_git_root()
|
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)))
|
call((args.git_command, "clone", "--origin", origin_name, external_url, str(external_dir)))
|
||||||
|
|
||||||
|
|
||||||
def floating_checkout_add_origin_if_needed(args: argparse.Namespace,
|
def floating_checkout_add_origin_if_needed(
|
||||||
repo_name: str,
|
args: argparse.Namespace,
|
||||||
directory: Path) -> None:
|
repo_name: str,
|
||||||
|
directory: Path,
|
||||||
|
) -> None:
|
||||||
"""
|
"""
|
||||||
Add remote called 'origin' if there is a fork of the external repository available
|
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
|
return
|
||||||
|
|
||||||
|
|
||||||
def floating_checkout_update(args: argparse.Namespace,
|
def floating_checkout_update(
|
||||||
repo_name: str,
|
args: argparse.Namespace,
|
||||||
directory: Path,
|
repo_name: str,
|
||||||
branch: Optional[str],
|
directory: Path,
|
||||||
old_submodules_dir: Path = None,
|
branch: Optional[str],
|
||||||
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"""
|
"""Update a single external checkout with the given name in the scripts folder"""
|
||||||
|
|
||||||
blender_git_root = get_blender_git_root()
|
blender_git_root = get_blender_git_root()
|
||||||
@@ -475,31 +486,37 @@ def floating_checkout_update(args: argparse.Namespace,
|
|||||||
return skip_msg
|
return skip_msg
|
||||||
|
|
||||||
|
|
||||||
def external_scripts_update(args: argparse.Namespace,
|
def external_scripts_update(
|
||||||
repo_name: str,
|
args: argparse.Namespace,
|
||||||
directory_name: str,
|
repo_name: str,
|
||||||
branch: Optional[str]) -> str:
|
directory_name: str,
|
||||||
return floating_checkout_update(args,
|
branch: Optional[str],
|
||||||
repo_name,
|
) -> str:
|
||||||
Path("scripts") / directory_name,
|
return floating_checkout_update(
|
||||||
branch,
|
args,
|
||||||
old_submodules_dir=Path("release") / "scripts" / directory_name)
|
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:
|
def floating_libraries_update(args: argparse.Namespace, branch: Optional[str]) -> str:
|
||||||
"""Update libraries checkouts which are floating (not attached as Git submodules)"""
|
"""Update libraries checkouts which are floating (not attached as Git submodules)"""
|
||||||
msg = ""
|
msg = ""
|
||||||
|
|
||||||
msg += floating_checkout_update(args,
|
msg += floating_checkout_update(
|
||||||
"benchmarks",
|
args,
|
||||||
Path("tests") / "benchmarks",
|
"benchmarks",
|
||||||
branch,
|
Path("tests") / "benchmarks",
|
||||||
only_update=True)
|
branch,
|
||||||
|
only_update=True,
|
||||||
|
)
|
||||||
|
|
||||||
return msg
|
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.
|
Add pushURL configuration for all locally activated submodules, pointing to SSH protocol.
|
||||||
"""
|
"""
|
||||||
|
|||||||
@@ -15,12 +15,18 @@ import sys
|
|||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
|
|
||||||
from typing import (
|
from typing import (
|
||||||
|
Dict,
|
||||||
Sequence,
|
Sequence,
|
||||||
Optional,
|
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:
|
if not silent:
|
||||||
cmd_str = ""
|
cmd_str = ""
|
||||||
if env:
|
if env:
|
||||||
@@ -135,7 +141,7 @@ def _git_submodule_config_key(submodule_dir: Path, key: str) -> str:
|
|||||||
return f"submodule.{submodule_dir_str}.{key}"
|
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"""
|
"""Check whether submodule denoted by its directory within the repository is enabled"""
|
||||||
|
|
||||||
git_root = Path(check_output([git_command, "rev-parse", "--show-toplevel"]))
|
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"
|
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"""
|
"""Enable submodule denoted by its directory within the repository"""
|
||||||
|
|
||||||
command = (git_command,
|
command = (git_command,
|
||||||
@@ -200,11 +206,11 @@ def git_update_submodule(git_command: str, submodule_dir: Path) -> bool:
|
|||||||
|
|
||||||
env = {"GIT_LFS_SKIP_SMUDGE": "1"}
|
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:
|
exit_on_error=False, env=env) != 0:
|
||||||
return False
|
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
|
exit_on_error=False) == 0
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user