WIP: Blender Kitsu: Convention Checker #124

Closed
Nick Alberelli wants to merge 8 commits from (deleted):feature/convention-checker-draft into main

When changing the target branch, be careful to rebase the branch in your fork to match. See documentation.
5 changed files with 135 additions and 0 deletions

View File

@ -28,6 +28,7 @@ from blender_kitsu import (
bkglobals, bkglobals,
types, types,
cache, cache,
checker,
models, models,
playblast, playblast,
propsdata, propsdata,
@ -78,6 +79,7 @@ if _need_reload:
ui = importlib.reload(ui) ui = importlib.reload(ui)
sqe.reload() sqe.reload()
util = importlib.reload(util) util = importlib.reload(util)
checker = importlib.reload(checker)
generic.reload() generic.reload()
auth.reload() auth.reload()
context.reload() context.reload()
@ -89,6 +91,7 @@ def register():
lookdev.register() lookdev.register()
prefs.register() prefs.register()
cache.register() cache.register()
checker.register()
props.register() props.register()
sqe.register() sqe.register()
generic.register() generic.register()
@ -111,6 +114,7 @@ def unregister():
generic.unregister() generic.unregister()
sqe.unregister() sqe.unregister()
props.unregister() props.unregister()
checker.unregister()
cache.unregister() cache.unregister()
prefs.unregister() prefs.unregister()
lookdev.unregister() lookdev.unregister()

View File

@ -0,0 +1,19 @@
import importlib
from blender_kitsu.checker import ops
# ---------REGISTER ----------.
def reload():
global ops
ops = importlib.reload(ops)
def register():
ops.register()
def unregister():
ops.unregister()

View File

@ -0,0 +1,93 @@
import bpy
import json
from bpy.ops import op_as_string
from pathlib import Path
class KITSU_PT_convention_checker_temp_ui(bpy.types.Panel):
# TODO: Remove this UI, for Testing only
bl_category = "Checker Test"
bl_label = "Convention Chekcer Test UI"
bl_space_type = "VIEW_3D"
bl_region_type = "UI"
def draw(self, context: bpy.types.Context) -> None:
layout = self.layout
layout.operator('kitsu.convention_checker')
class KITSU_OT_test_op(bpy.types.Operator):
bl_idname = "kitsu.test_op"
bl_label = 'test'
text: bpy.props.StringProperty(name='test', default='test')
def execute(self, context):
if self.text != "test":
self.report({'ERROR'}, "Failure")
return {'CANCELLED'}
self.report({'INFO'}, "Success")
return {'FINISHED'}
def get_config():
addon_prefs = bpy.context.preferences.addons["blender_kitsu"].preferences
config_file = addon_prefs.convention_config
return Path(config_file).joinpath('convention_checker.json')
class KITSU_OT_convention_checker(bpy.types.Operator):
bl_idname = "kitsu.convention_checker"
bl_label = 'Convention Checker'
@classmethod
def poll(cls, context: bpy.types.Context) -> bool:
config_file = get_config()
if not config_file.exists():
cls.poll_message_set(
"Convention Checker config file not found. Check add-on preferences"
)
return config_file.exists()
def execute(self, context):
# TODO check operator exists before execution
# INFO python3 -m json.tool file.json to 'pretty print' json
config_file = get_config()
with open(config_file, "r") as f:
data = json.load(f)
print(data)
check_ops = []
for item in data:
if item == 'anim': # TODO use current task type
for op in data[item]:
check_ops.append(op)
for op in check_ops:
try:
exec(op)
except RuntimeError as ex:
args = ex.args[0].split(':')
self.report({args[0].upper()}, f"{op}:{args[1]}")
else:
self.report({'INFO'}, f"{op}: SUCCESS")
return {'FINISHED'}
classes = [
KITSU_OT_test_op,
KITSU_OT_convention_checker,
KITSU_PT_convention_checker_temp_ui,
]
def register():
for cls in classes:
bpy.utils.register_class(cls)
def unregister():
for cls in reversed(classes):
bpy.utils.unregister_class(cls)

View File

@ -0,0 +1,5 @@
{
"anim": [
"bpy.ops.kitsu.test_op()"
]
}

View File

@ -331,6 +331,13 @@ class KITSU_addon_preferences(bpy.types.AddonPreferences):
default="", default="",
) )
convention_config: bpy.props.StringProperty( # type: ignore
name="Convention Checker Config Directory",
options={"HIDDEN", "SKIP_SAVE"},
description="Path to convention checker configuration file.",
subtype="DIR_PATH",
)
session: Session = Session() session: Session = Session()
tasks: bpy.props.CollectionProperty(type=KITSU_task) tasks: bpy.props.CollectionProperty(type=KITSU_task)
@ -425,6 +432,13 @@ class KITSU_addon_preferences(bpy.types.AddonPreferences):
box.row().prop(self, "shot_builder_action_prefix") box.row().prop(self, "shot_builder_action_prefix")
box.row().prop(self, "user_exec_code") box.row().prop(self, "user_exec_code")
# Convention Checker
box = layout.box()
box.label(
text="Convention Checker",
)
box.row().prop(self, "convention_config")
# Misc settings. # Misc settings.
box = layout.box() box = layout.box()
box.label(text="Miscellaneous", icon="MODIFIER") box.label(text="Miscellaneous", icon="MODIFIER")