From 6216e8574c685a3b2bdedc01ddd2ebb54bfde8e5 Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Sat, 4 Jan 2025 20:33:53 +1100 Subject: [PATCH] Cleanup: declare __all__ for doc-generation & icon updating utils --- doc/python_api/sphinx_doc_gen.py | 3 + release/datafiles/blender_icons_geom.py | 3 + .../datafiles/blender_icons_geom_update.py | 120 +++++++++--------- scripts/modules/rna_info.py | 9 ++ 4 files changed, 78 insertions(+), 57 deletions(-) diff --git a/doc/python_api/sphinx_doc_gen.py b/doc/python_api/sphinx_doc_gen.py index 9a607ce5565..147a4a1a76a 100644 --- a/doc/python_api/sphinx_doc_gen.py +++ b/doc/python_api/sphinx_doc_gen.py @@ -36,6 +36,9 @@ Sphinx: PDF generation cd doc/python_api/sphinx-out make """ +__all__ = ( + "main", +) import os import sys diff --git a/release/datafiles/blender_icons_geom.py b/release/datafiles/blender_icons_geom.py index f43d790478e..b3d790bcf4a 100644 --- a/release/datafiles/blender_icons_geom.py +++ b/release/datafiles/blender_icons_geom.py @@ -41,6 +41,9 @@ All coordinates are written, then all colors. Since this is a binary format which isn't intended for general use the ``.dat`` file extension should be used. """ +__all__ = ( + "main", +) # This script writes out geometry-icons. import bpy diff --git a/release/datafiles/blender_icons_geom_update.py b/release/datafiles/blender_icons_geom_update.py index ee223041be2..569c66b1a03 100755 --- a/release/datafiles/blender_icons_geom_update.py +++ b/release/datafiles/blender_icons_geom_update.py @@ -4,6 +4,10 @@ # SPDX-License-Identifier: GPL-2.0-or-later # This script updates icons from the BLEND file +__all__ = ( + "main", +) + import os import subprocess import sys @@ -13,6 +17,9 @@ from collections.abc import ( Sequence, ) +BASEDIR = os.path.abspath(os.path.dirname(__file__)) +ROOTDIR = os.path.normpath(os.path.join(BASEDIR, "..", "..")) + def run(cmd: Sequence[str], *, env: dict[str, str] | None = None) -> None: print(" ", " ".join(cmd)) @@ -40,68 +47,67 @@ def edit_text_file(filename: str, marker_begin: str, marker_end: str, content: s f.write(data_update) -BASEDIR = os.path.abspath(os.path.dirname(__file__)) -ROOTDIR = os.path.normpath(os.path.join(BASEDIR, "..", "..")) +def main() -> int: + blender_bin = os.environ.get("BLENDER_BIN", "blender") + if not os.path.exists(blender_bin): + blender_bin = os.path.join(ROOTDIR, "blender.bin") -blender_bin = os.environ.get("BLENDER_BIN", "blender") -if not os.path.exists(blender_bin): - blender_bin = os.path.join(ROOTDIR, "blender.bin") + if not os.path.exists(blender_bin): + if sys.platform == 'darwin': + blender_app_path = '/Applications/Blender.app/Contents/MacOS/Blender' + if os.path.exists(blender_app_path): + blender_bin = blender_app_path -if not os.path.exists(blender_bin): - if sys.platform == 'darwin': - blender_app_path = '/Applications/Blender.app/Contents/MacOS/Blender' - if os.path.exists(blender_app_path): - blender_bin = blender_app_path - -icons_blend = ( - os.path.join(ROOTDIR, "release", "datafiles", "assets", "icons", "toolbar.blend"), -) - - -def names_and_time_from_path(path: str) -> Iterator[tuple[str, float]]: - for entry in os.scandir(path): - name = entry.name - if name.endswith(".dat"): - yield (name, entry.stat().st_mtime) - - -# Collect icons files and update CMake. -icon_files = [] - -# create .dat geometry (which are stored in git) -for blend in icons_blend: - output_dir = os.path.join(BASEDIR, "icons") - files_old = set(names_and_time_from_path(output_dir)) - cmd = ( - blender_bin, "--background", "--factory-startup", - blend, - "--python", os.path.join(BASEDIR, "blender_icons_geom.py"), - "--", - "--group", "Export", - "--output-dir", output_dir, + icons_blend = ( + os.path.join(ROOTDIR, "release", "datafiles", "assets", "icons", "toolbar.blend"), ) - env = {} - # Developers may have ASAN enabled, avoid non-zero exit codes. - env["ASAN_OPTIONS"] = "exitcode=0:" + os.environ.get("ASAN_OPTIONS", "") - # These NEED to be set on windows for python to initialize properly. - if sys.platform[:3] == "win": - env["PATHEXT"] = os.environ.get("PATHEXT", "") - env["SystemDrive"] = os.environ.get("SystemDrive", "") - env["SystemRoot"] = os.environ.get("SystemRoot", "") + def names_and_time_from_path(path: str) -> Iterator[tuple[str, float]]: + for entry in os.scandir(path): + name = entry.name + if name.endswith(".dat"): + yield (name, entry.stat().st_mtime) - run(cmd, env=env) - files_new = set(names_and_time_from_path(output_dir)) + # Collect icons files and update CMake. + icon_files = [] - icon_files.extend([ - name[:-4] # no .dat - for (name, _) in sorted((files_new - files_old)) - ]) + # create .dat geometry (which are stored in git) + for blend in icons_blend: + output_dir = os.path.join(BASEDIR, "icons") + files_old = set(names_and_time_from_path(output_dir)) + cmd = ( + blender_bin, "--background", "--factory-startup", + blend, + "--python", os.path.join(BASEDIR, "blender_icons_geom.py"), + "--", + "--group", "Export", + "--output-dir", output_dir, + ) + + env = {} + # Developers may have ASAN enabled, avoid non-zero exit codes. + env["ASAN_OPTIONS"] = "exitcode=0:" + os.environ.get("ASAN_OPTIONS", "") + # These NEED to be set on windows for python to initialize properly. + if sys.platform[:3] == "win": + env["PATHEXT"] = os.environ.get("PATHEXT", "") + env["SystemDrive"] = os.environ.get("SystemDrive", "") + env["SystemRoot"] = os.environ.get("SystemRoot", "") + + run(cmd, env=env) + files_new = set(names_and_time_from_path(output_dir)) + + icon_files.extend([ + name[:-4] # no .dat + for (name, _) in sorted((files_new - files_old)) + ]) + + edit_text_file( + os.path.join(ROOTDIR, "source", "blender", "editors", "datafiles", "CMakeLists.txt"), + "# BEGIN ICON_GEOM_NAMES", + "# END ICON_GEOM_NAMES", + " " + "\n ".join(icon_files) + "\n", + ) -edit_text_file( - os.path.join(ROOTDIR, "source", "blender", "editors", "datafiles", "CMakeLists.txt"), - "# BEGIN ICON_GEOM_NAMES", - "# END ICON_GEOM_NAMES", - " " + "\n ".join(icon_files) + "\n", -) +if __name__ == "__main__": + sys.exit(main()) diff --git a/scripts/modules/rna_info.py b/scripts/modules/rna_info.py index 7b379c2f5c1..65d906df6c7 100644 --- a/scripts/modules/rna_info.py +++ b/scripts/modules/rna_info.py @@ -4,6 +4,15 @@ # classes for extracting info from blenders internal classes +__all__ = ( + "BuildRNAInfo", + "InfoFunctionRNA", + "InfoOperatorRNA", + "InfoPropertyRNA", + "InfoStructRNA", + "rna_id_ignore", +) + import bpy # use to strip python paths