Cleanup: declare __all__ for Python scripts

Declare all to make public public API's explicit and
help detect unused code.
This commit is contained in:
Campbell Barton
2025-01-06 16:45:36 +11:00
parent 6ac52551d3
commit 4f1817cc18
31 changed files with 285 additions and 140 deletions

View File

@@ -5,6 +5,10 @@
# macOS utility to remove all `rpaths` and add a new one. # macOS utility to remove all `rpaths` and add a new one.
__all__ = (
"main",
)
import os import os
import pathlib import pathlib
import re import re

View File

@@ -3,6 +3,10 @@
# #
# SPDX-License-Identifier: GPL-2.0-or-later # SPDX-License-Identifier: GPL-2.0-or-later
__all__ = (
"main",
)
import logging import logging
import os import os
import re import re

View File

@@ -2,18 +2,20 @@
# #
# SPDX-License-Identifier: Apache-2.0 # SPDX-License-Identifier: Apache-2.0
# Simple utility that prints all WITH_* options in a CMakeLists.txt # Simple utility that prints all `WITH_*` options in a `CMakeLists.txt`.
# Called by 'make help_features' # Called by `make help_features`.
__all__ = (
"main",
)
import re import re
import sys import sys
from typing import ( from typing import (
Union, Optional,
) )
cmakelists_file = sys.argv[-1]
def count_backslashes_before_pos(file_data: str, pos: int) -> int: def count_backslashes_before_pos(file_data: str, pos: int) -> int:
slash_count = 0 slash_count = 0
@@ -26,7 +28,7 @@ def count_backslashes_before_pos(file_data: str, pos: int) -> int:
return slash_count return slash_count
def extract_cmake_string_at_pos(file_data: str, pos_beg: int) -> Union[str, None]: def extract_cmake_string_at_pos(file_data: str, pos_beg: int) -> Optional[str]:
assert file_data[pos_beg - 1] == '"' assert file_data[pos_beg - 1] == '"'
pos = pos_beg pos = pos_beg
@@ -73,10 +75,13 @@ def extract_cmake_string_at_pos(file_data: str, pos_beg: int) -> Union[str, None
return text return text
def main() -> None: def main() -> int:
cmakelists_file = sys.argv[-1]
options = [] options = []
with open(cmakelists_file, 'r', encoding="utf-8") as fh: with open(cmakelists_file, 'r', encoding="utf-8") as fh:
file_data = fh.read() file_data = fh.read()
for m in re.finditer(r"^\s*option\s*\(\s*(WITH_[a-zA-Z0-9_]+)\s+(\")", file_data, re.MULTILINE): for m in re.finditer(r"^\s*option\s*\(\s*(WITH_[a-zA-Z0-9_]+)\s+(\")", file_data, re.MULTILINE):
option_name = m.group(1) option_name = m.group(1)
option_descr = extract_cmake_string_at_pos(file_data, m.span(2)[1]) option_descr = extract_cmake_string_at_pos(file_data, m.span(2)[1])
@@ -86,6 +91,7 @@ def main() -> None:
options.append("{:s}: {:s}".format(option_name, option_descr)) options.append("{:s}: {:s}".format(option_name, option_descr))
print('\n'.join(options)) print('\n'.join(options))
return 0
if __name__ == "__main__": if __name__ == "__main__":

View File

@@ -3,6 +3,10 @@
# #
# SPDX-License-Identifier: GPL-2.0-or-later # SPDX-License-Identifier: GPL-2.0-or-later
__all__ = (
"main",
)
import os import os
import shutil import shutil
import subprocess import subprocess

View File

@@ -27,6 +27,9 @@ NOTE:
Some type annotations are quoted to avoid errors in Python 3.9. Some type annotations are quoted to avoid errors in Python 3.9.
These can be unquoted eventually. These can be unquoted eventually.
""" """
__all__ = (
"main",
)
import argparse import argparse
import make_utils import make_utils

View File

@@ -7,6 +7,10 @@
"make test" for all platforms, running automated tests. "make test" for all platforms, running automated tests.
""" """
__all__ = (
"main",
)
import argparse import argparse
import os import os
import sys import sys

View File

@@ -53,6 +53,9 @@ API dump format:
] ]
""" """
__all__ = (
"main",
)
import json import json
import os import os

View File

@@ -3,50 +3,60 @@
# #
# SPDX-License-Identifier: GPL-2.0-or-later # SPDX-License-Identifier: GPL-2.0-or-later
__all__ = (
"__all__",
)
import sys import sys
argv = sys.argv[:]
strip_byte = False def main():
if "--strip-byte" in argv: argv = sys.argv[:]
strip_byte = False
if "--strip-byte" in argv:
argv.remove("--strip-byte") argv.remove("--strip-byte")
strip_byte = True strip_byte = True
if len(argv) < 2: if len(argv) < 2:
sys.stdout.write("Usage: ctodata <c_file> [--strip-byte]\n") sys.stdout.write("Usage: ctodata <c_file> [--strip-byte]\n")
sys.exit(1) sys.exit(1)
filename = argv[1] filename = argv[1]
try: try:
fpin = open(filename, "r") fpin = open(filename, "r")
except: except:
sys.stdout.write("Unable to open input {:s}\n".format(argv[1])) sys.stdout.write("Unable to open input {:s}\n".format(argv[1]))
sys.exit(1) sys.exit(1)
data_as_str = fpin.read().rsplit("{")[-1].split("}")[0] data_as_str = fpin.read().rsplit("{")[-1].split("}")[0]
data_as_str = data_as_str.replace(",", " ") data_as_str = data_as_str.replace(",", " ")
data_as_list = [int(v) for v in data_as_str.split()] data_as_list = [int(v) for v in data_as_str.split()]
del data_as_str del data_as_str
if strip_byte: if strip_byte:
# String data gets trailing byte. # String data gets trailing byte.
last = data_as_list.pop() last = data_as_list.pop()
assert last == 0 assert last == 0
data = bytes(data_as_list) data = bytes(data_as_list)
del data_as_list del data_as_list
dname = filename + ".ctodata" dname = filename + ".ctodata"
sys.stdout.write("Making DATA file <{:s}>\n".format(dname)) sys.stdout.write("Making DATA file <{:s}>\n".format(dname))
try: try:
fpout = open(dname, "wb") fpout = open(dname, "wb")
except: except:
sys.stdout.write("Unable to open output {:s}\n".format(dname)) sys.stdout.write("Unable to open output {:s}\n".format(dname))
sys.exit(1) sys.exit(1)
size = fpout.write(data) size = fpout.write(data)
sys.stdout.write("{:d}\n".format(size)) sys.stdout.write("{:d}\n".format(size))
if __name__ == "__main__":
sys.exit(main())

View File

@@ -3,34 +3,42 @@
# #
# SPDX-License-Identifier: GPL-2.0-or-later # SPDX-License-Identifier: GPL-2.0-or-later
"""
This python script is used to generate the release notes and
download URLs which we can copy-paste directly into the CMS of
www.blender.org and stores.
"""
__all__ = (
"main",
)
import argparse import argparse
import sys
import lts_issue import lts_issue
import lts_download import lts_download
DESCRIPTION = ("This python script is used to generate the release notes and "
"download URLs which we can copy-paste directly into the CMS of "
"www.blender.org and stores.")
# Parse arguments def main() -> int:
parser = argparse.ArgumentParser(description=DESCRIPTION) # Parse arguments
parser.add_argument( parser = argparse.ArgumentParser(description=__doc__)
parser.add_argument(
"--version", "--version",
required=True, required=True,
help="Version string in the form of {major}.{minor}.{patch} (e.g. 3.3.2)") help="Version string in the form of {major}.{minor}.{patch} (e.g. 3.3.2)")
parser.add_argument( parser.add_argument(
"--issue", "--issue",
help="Task that contains the release notes information (e.g. #77348)") help="Task that contains the release notes information (e.g. #77348)")
parser.add_argument( parser.add_argument(
"--format", "--format",
help="Format the result in `text`, `steam`, `markdown` or `html`", help="Format the result in `text`, `steam`, `markdown` or `html`",
default="text") default="text")
args = parser.parse_args() args = parser.parse_args()
# Determine issue number # Determine issue number
version = args.version version = args.version
issue = args.issue issue = args.issue
if not issue: if not issue:
if version.startswith("2.83."): if version.startswith("2.83."):
issue = "#77348" issue = "#77348"
elif version.startswith("2.93."): elif version.startswith("2.93."):
@@ -44,9 +52,13 @@ if not issue:
else: else:
raise ValueError("Specify --issue or update script to include issue number for this version") raise ValueError("Specify --issue or update script to include issue number for this version")
# Print # Print
if args.format == "html": if args.format == "html":
lts_download.print_urls(version=version) lts_download.print_urls(version=version)
print("") print("")
lts_issue.print_notes(version=version, format=args.format, issue=issue) lts_issue.print_notes(version=version, format=args.format, issue=issue)
if __name__ == "__main__":
sys.exit(main())

View File

@@ -2,6 +2,9 @@
# SPDX-FileCopyrightText: 2020-2023 Blender Authors # SPDX-FileCopyrightText: 2020-2023 Blender Authors
# #
# SPDX-License-Identifier: GPL-2.0-or-later # SPDX-License-Identifier: GPL-2.0-or-later
__all__ = (
"print_urls",
)
import datetime import datetime

View File

@@ -2,6 +2,9 @@
# SPDX-FileCopyrightText: 2023 Blender Authors # SPDX-FileCopyrightText: 2023 Blender Authors
# #
# SPDX-License-Identifier: GPL-2.0-or-later # SPDX-License-Identifier: GPL-2.0-or-later
__all__ = (
"print_notes",
)
import requests import requests

View File

@@ -3,6 +3,10 @@
# #
# SPDX-License-Identifier: GPL-2.0-or-later # SPDX-License-Identifier: GPL-2.0-or-later
__all__ = (
"main",
)
import argparse import argparse
import glob import glob
import pathlib import pathlib
@@ -12,28 +16,30 @@ import tempfile
import urllib.request import urllib.request
import zipfile import zipfile
parser = argparse.ArgumentParser(description="Check and upload bpy module to PyPI")
parser.add_argument( def main():
parser = argparse.ArgumentParser(description="Check and upload bpy module to PyPI")
parser.add_argument(
"--version", "--version",
required=True, required=True,
help="Version string in the form of {major}.{minor}.{patch} (e.g. 3.6.0)") help="Version string in the form of {major}.{minor}.{patch} (e.g. 3.6.0)")
parser.add_argument( parser.add_argument(
"--git-hash", "--git-hash",
required=True, required=True,
help="Git hash matching the version") help="Git hash matching the version")
parser.add_argument( parser.add_argument(
"--check", "--check",
action="store_true", action="store_true",
help="Only check wheels for errors, don't upload") help="Only check wheels for errors, don't upload")
args = parser.parse_args() args = parser.parse_args()
platforms = [ platforms = [
"darwin.x86_64", "darwin.x86_64",
"darwin.arm64", "darwin.arm64",
"linux.x86_64", "linux.x86_64",
"windows.amd64"] "windows.amd64"]
with tempfile.TemporaryDirectory() as tmp_dir: with tempfile.TemporaryDirectory() as tmp_dir:
tmp_dir = pathlib.Path(tmp_dir) tmp_dir = pathlib.Path(tmp_dir)
print("Download:") print("Download:")
@@ -68,3 +74,7 @@ with tempfile.TemporaryDirectory() as tmp_dir:
subprocess.run(["twine", "check"] + wheels, check=True) subprocess.run(["twine", "check"] + wheels, check=True)
if not args.check: if not args.check:
subprocess.run(["twine", "upload", "--repository", "bpy", "--verbose"] + wheels, check=True) subprocess.run(["twine", "upload", "--repository", "bpy", "--verbose"] + wheels, check=True)
if __name__ == "__main__":
sys.exit(main())

View File

@@ -8,6 +8,9 @@ rna values in fcurves and drivers.
Currently unused, but might become useful later again. Currently unused, but might become useful later again.
""" """
__all__ = (
"update_data_paths",
)
import sys import sys
import bpy import bpy

View File

@@ -7,6 +7,11 @@
# When the version is `(0, 0, 0)`, the key-map being loaded didn't contain any versioning information. # When the version is `(0, 0, 0)`, the key-map being loaded didn't contain any versioning information.
# This will older than `(2, 92, 0)`. # This will older than `(2, 92, 0)`.
__all__ = (
"keyconfig_update",
)
def keyconfig_update(keyconfig_data, keyconfig_version): def keyconfig_update(keyconfig_data, keyconfig_version):
from bpy.app import version_file as blender_version from bpy.app import version_file as blender_version
if keyconfig_version >= blender_version: if keyconfig_version >= blender_version:

View File

@@ -3,6 +3,10 @@
# #
# SPDX-License-Identifier: GPL-2.0-or-later # SPDX-License-Identifier: GPL-2.0-or-later
__all__ = (
"main",
)
import argparse import argparse
import os import os
import shutil import shutil

View File

@@ -2,16 +2,19 @@
# #
# SPDX-License-Identifier: GPL-2.0-or-later # SPDX-License-Identifier: GPL-2.0-or-later
"""
blender -b --factory-startup --python tests/python/bl_animation_drivers.py -- --testdir /path/to/tests/data/animation
"""
__all__ = (
"main",
)
import unittest import unittest
import bpy import bpy
import pathlib import pathlib
import sys import sys
from rna_prop_ui import rna_idprop_quote_path from rna_prop_ui import rna_idprop_quote_path
"""
blender -b --factory-startup --python tests/python/bl_animation_drivers.py -- --testdir /path/to/tests/data/animation
"""
class AbstractEmptyDriverTest: class AbstractEmptyDriverTest:
def setUp(self): def setUp(self):

View File

@@ -2,7 +2,13 @@
# #
# SPDX-License-Identifier: Apache-2.0 # SPDX-License-Identifier: Apache-2.0
# ./blender.bin --background --python tests/python/bl_blendfile_liblink.py """
./blender.bin --background --python tests/python/bl_blendfile_liblink.py
"""
__all__ = (
"main",
)
import bpy import bpy
import os import os
import sys import sys

View File

@@ -9,6 +9,10 @@
# #
# This needs to be investigated! # This needs to be investigated!
__all__ = (
"main",
)
import os import os
import platform import platform
import sys import sys

View File

@@ -2,6 +2,10 @@
# #
# SPDX-License-Identifier: GPL-2.0-or-later # SPDX-License-Identifier: GPL-2.0-or-later
__all__ = (
"main",
)
import os import os
import pathlib import pathlib
import sys import sys

View File

@@ -3,6 +3,10 @@
# #
# SPDX-License-Identifier: Apache-2.0 # SPDX-License-Identifier: Apache-2.0
__all__ = (
"main",
)
import argparse import argparse
import os import os
import sys import sys

View File

@@ -7,6 +7,9 @@
""" """
./blender.bin --background --factory-startup --python tests/python/bl_load_addons.py ./blender.bin --background --factory-startup --python tests/python/bl_load_addons.py
""" """
__all__ = (
"main",
)
import bpy import bpy
import addon_utils import addon_utils

View File

@@ -5,6 +5,10 @@
# Simple script to check mash validate code. # Simple script to check mash validate code.
# XXX Should be extended with many more "wrong cases"! # XXX Should be extended with many more "wrong cases"!
__all__ = (
"main",
)
import bpy import bpy
import random import random

View File

@@ -3,6 +3,11 @@
# SPDX-License-Identifier: Apache-2.0 # SPDX-License-Identifier: Apache-2.0
# ./blender.bin --background --python tests/python/bl_pyapi_bpy_utils_units.py -- --verbose # ./blender.bin --background --python tests/python/bl_pyapi_bpy_utils_units.py -- --verbose
__all__ = (
"main",
)
import unittest import unittest
from bpy.utils import units from bpy.utils import units
@@ -93,7 +98,11 @@ class UnitsTesting(unittest.TestCase):
) )
if __name__ == '__main__': def main():
import sys import sys
sys.argv = [__file__] + (sys.argv[sys.argv.index("--") + 1:] if "--" in sys.argv else []) sys.argv = [__file__] + (sys.argv[sys.argv.index("--") + 1:] if "--" in sys.argv else [])
unittest.main() unittest.main()
if __name__ == '__main__':
main()

View File

@@ -2,6 +2,10 @@
# #
# SPDX-License-Identifier: GPL-2.0-or-later # SPDX-License-Identifier: GPL-2.0-or-later
__all__ = (
"AbstractImBufTest",
)
import os import os
import pathlib import pathlib
import shutil import shutil

View File

@@ -2,6 +2,10 @@
# #
# SPDX-License-Identifier: GPL-2.0-or-later # SPDX-License-Identifier: GPL-2.0-or-later
__all__ = (
"main",
)
r""" r"""
Example usage: Example usage:

View File

@@ -7,6 +7,10 @@
# #
# only error checked for here is a segfault. # only error checked for here is a segfault.
__all__ = (
"main",
)
import bpy import bpy
import sys import sys

View File

@@ -82,7 +82,9 @@ or the context for executing the actions is not properly set (the case for timer
This utility executes actions as if the user initiated them from a key shortcut. This utility executes actions as if the user initiated them from a key shortcut.
""" """
__all__ = (
"main",
)
import os import os
import sys import sys

View File

@@ -39,6 +39,10 @@ WAYLAND Environment Variables:
Currently only WAYLAND is supported, other systems could be added. Currently only WAYLAND is supported, other systems could be added.
""" """
__all__ = (
"main",
)
import subprocess import subprocess
import sys import sys
import signal import signal

View File

@@ -5,6 +5,10 @@
# generate svn rev-sha1 mapping # generate svn rev-sha1 mapping
__all__ = (
"main",
)
import os import os
import sys import sys

View File

@@ -2,6 +2,10 @@
# #
# SPDX-License-Identifier: GPL-2.0-or-later # SPDX-License-Identifier: GPL-2.0-or-later
__all__ = (
"data",
)
data = { data = {
2: "12315f4d0e0ae993805f141f64cb8c73c5297311", 2: "12315f4d0e0ae993805f141f64cb8c73c5297311",
16: "599dc60f6dc97d3ef8efdd294ca2e89fbf498f54", 16: "599dc60f6dc97d3ef8efdd294ca2e89fbf498f54",

View File

@@ -2,6 +2,10 @@
# #
# SPDX-License-Identifier: GPL-2.0-or-later # SPDX-License-Identifier: GPL-2.0-or-later
__all__ = (
"data",
)
data = { data = {
"12315f4d0e0ae993805f141f64cb8c73c5297311": 2, "12315f4d0e0ae993805f141f64cb8c73c5297311": 2,
"599dc60f6dc97d3ef8efdd294ca2e89fbf498f54": 16, "599dc60f6dc97d3ef8efdd294ca2e89fbf498f54": 16,