diff options
author | Campbell Barton <campbell@blender.org> | 2022-09-16 03:49:49 +0300 |
---|---|---|
committer | Campbell Barton <campbell@blender.org> | 2022-09-16 03:52:20 +0300 |
commit | 8342564796346b297c40a1fc1f57e6b8e10798c0 (patch) | |
tree | 139fb2f2d9c7237b8b50413b46edb2c341851fc6 | |
parent | d5df23d7581230da7ab5cfd5764a46f7f7941759 (diff) |
Cleanup: suppress type warnings for make_bpy_wheel & make_utils
'make check_mypy' now runs without warnings.
-rwxr-xr-x | build_files/utils/make_bpy_wheel.py | 16 | ||||
-rwxr-xr-x | build_files/utils/make_utils.py | 37 |
2 files changed, 32 insertions, 21 deletions
diff --git a/build_files/utils/make_bpy_wheel.py b/build_files/utils/make_bpy_wheel.py index e98e8570212..f695bdae68a 100755 --- a/build_files/utils/make_bpy_wheel.py +++ b/build_files/utils/make_bpy_wheel.py @@ -7,15 +7,15 @@ import os import re import platform import string -import setuptools +import setuptools # type: ignore import sys from typing import ( Generator, - Tuple, List, Optional, Sequence, + Tuple, ) @@ -108,8 +108,12 @@ def main() -> None: elif sys.platform == "win32": platform_tag = "win_%s" % (platform.machine().lower()) elif sys.platform == "linux": - glibc = os.confstr("CS_GNU_LIBC_VERSION").split()[1].split(".") - platform_tag = "manylinux_%s_%s_%s" % (glibc[0], glibc[1], platform.machine().lower()) + glibc = os.confstr("CS_GNU_LIBC_VERSION") + if glibc is None: + print("Unable to find \"CS_GNU_LIBC_VERSION\", aborting!") + sys.exit(1) + glibc = "%s_%s" % tuple(glibc.split()[1].split(".")[:2]) + platform_tag = "manylinux_%s_%s" % (glibc, platform.machine().lower()) else: print("Unsupported platform %s" % (sys.platform)) sys.exit(1) @@ -124,8 +128,8 @@ def main() -> None: return paths # Ensure this wheel is marked platform specific. - class BinaryDistribution(setuptools.dist.Distribution): - def has_ext_modules(foo): + class BinaryDistribution(setuptools.dist.Distribution): # type: ignore + def has_ext_modules(self) -> bool: return True # Build wheel. diff --git a/build_files/utils/make_utils.py b/build_files/utils/make_utils.py index 53d462331dd..564930617ff 100755 --- a/build_files/utils/make_utils.py +++ b/build_files/utils/make_utils.py @@ -11,8 +11,13 @@ import subprocess import sys from pathlib import Path +from typing import ( + Sequence, + Optional, +) -def call(cmd, exit_on_error=True, silent=False): + +def call(cmd: Sequence[str], exit_on_error: bool = True, silent: bool = False) -> int: if not silent: print(" ".join(cmd)) @@ -30,7 +35,7 @@ def call(cmd, exit_on_error=True, silent=False): return retcode -def check_output(cmd, exit_on_error=True): +def check_output(cmd: Sequence[str], exit_on_error: bool = True) -> str: # Flush to ensure correct order output on Windows. sys.stdout.flush() sys.stderr.flush() @@ -47,14 +52,14 @@ def check_output(cmd, exit_on_error=True): return output.strip() -def git_branch_exists(git_command, branch): +def git_branch_exists(git_command: str, branch: str) -> bool: return ( call([git_command, "rev-parse", "--verify", branch], exit_on_error=False, silent=True) == 0 or call([git_command, "rev-parse", "--verify", "remotes/origin/" + branch], exit_on_error=False, silent=True) == 0 ) -def git_branch(git_command): +def git_branch(git_command: str) -> str: # Get current branch name. try: branch = subprocess.check_output([git_command, "rev-parse", "--abbrev-ref", "HEAD"]) @@ -65,7 +70,7 @@ def git_branch(git_command): return branch.strip().decode('utf8') -def git_tag(git_command): +def git_tag(git_command: str) -> Optional[str]: # Get current tag name. try: tag = subprocess.check_output([git_command, "describe", "--exact-match"], stderr=subprocess.STDOUT) @@ -75,18 +80,19 @@ def git_tag(git_command): return tag.strip().decode('utf8') -def git_branch_release_version(branch, tag): - release_version = re.search("^blender-v(.*)-release$", branch) - if release_version: - release_version = release_version.group(1) +def git_branch_release_version(branch: str, tag: str) -> Optional[str]: + re_match = re.search("^blender-v(.*)-release$", branch) + release_version = None + if re_match: + release_version = re_match.group(1) elif tag: - release_version = re.search(r"^v([0-9]*\.[0-9]*).*", tag) - if release_version: - release_version = release_version.group(1) + re_match = re.search(r"^v([0-9]*\.[0-9]*).*", tag) + if re_match: + release_version = re_match.group(1) return release_version -def svn_libraries_base_url(release_version, branch=None): +def svn_libraries_base_url(release_version: Optional[str], branch: Optional[str] = None) -> str: if release_version: svn_branch = "tags/blender-" + release_version + "-release" elif branch: @@ -96,7 +102,7 @@ def svn_libraries_base_url(release_version, branch=None): return "https://svn.blender.org/svnroot/bf-blender/" + svn_branch + "/lib/" -def command_missing(command): +def command_missing(command: str) -> bool: # Support running with Python 2 for macOS if sys.version_info >= (3, 0): return shutil.which(command) is None @@ -105,7 +111,7 @@ def command_missing(command): class BlenderVersion: - def __init__(self, version, patch, cycle): + def __init__(self, version: int, patch: int, cycle: str): # 293 for 2.93.1 self.version = version # 1 for 2.93.1 @@ -131,6 +137,7 @@ class BlenderVersion: return as_string return f"{as_string}-{self.cycle}" + def parse_blender_version() -> BlenderVersion: blender_srcdir = Path(__file__).absolute().parent.parent.parent version_path = blender_srcdir / "source/blender/blenkernel/BKE_blender_version.h" |