Cleanup: declare __all__ for doc-generation & icon updating utils

This commit is contained in:
Campbell Barton
2025-01-04 20:33:53 +11:00
parent 5fe261c89d
commit 6216e8574c
4 changed files with 78 additions and 57 deletions

View File

@@ -36,6 +36,9 @@ Sphinx: PDF generation
cd doc/python_api/sphinx-out
make
"""
__all__ = (
"main",
)
import os
import sys

View File

@@ -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

View File

@@ -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())

View File

@@ -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