-
Notifications
You must be signed in to change notification settings - Fork 0
/
documentation.py
89 lines (70 loc) · 2.79 KB
/
documentation.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
import pathlib
MAINDIR = pathlib.Path( __file__ ).parent
from .nodes import get_all_nodes
from .nodes.utils import EssentialsNode
CAT_DATA = EssentialsNode.get_category_data( )
def get_all_pipeline_nodes( ) -> list[object]:
import importlib, sys
result = []
pipeline_nodes_path = pathlib.Path( __file__ ).parent.joinpath( 'PipelineNodes' )
if not str( pipeline_nodes_path ) in sys.path:
sys.path.append( str( pipeline_nodes_path ))
pipeline_nodes = [ x.stem for x in pipeline_nodes_path.glob( '*.py' ) if not x.name == '__init__.py' ]
for node_module_name in pipeline_nodes:
m = importlib.import_module( node_module_name )
if hasattr( m, 'NODE' ):
result.append( m.NODE )
return result
class LibraryItem( object ):
node_clss = None
def __init__( self, node_clss ):
self.node_clss = node_clss
@property
def label( self ):
return getattr( self.node_clss, 'bl_label', self.node_clss.__name__ )
@property
def idname( self ):
return getattr( self.node_clss, 'bl_idname', self.node_clss.__name__ )
@property
def tooltip( self ):
return getattr( self.node_clss, 'tooltip', '' )
@property
def path( self ):
return '/'.join( self.node_clss.__module__.split( '.' )[-2:]) + '.py'
def format_tooltip( self ):
formatted_tooltip = self.tooltip
while formatted_tooltip[0] in [ '\n', '\t', ' ' ]:
formatted_tooltip = formatted_tooltip[1:]
while formatted_tooltip[-1] in [ '\n', '\t', ' ' ]:
formatted_tooltip = formatted_tooltip[:-1]
formatted_tooltip = formatted_tooltip.replace( '\n', '\n\t' )
return formatted_tooltip
@property
def formatted( self ):
f = f'- {self.label} / {self.idname} : [{self.path}]\n'
if self.valid_tooltip( ):
f += '\t'
f += self.format_tooltip( )
f += '\n'
return f
def valid_tooltip( self ):
t = self.tooltip
return not t == '' and not all( x in [ ' ', '\n', '\t' ] for x in t )
def generate_library( ):
nodes = get_all_nodes( )
library = { key : [] for key in CAT_DATA.keys( )}
for n in nodes:
library[ n.menu_category ].append( LibraryItem( n ))
for n in get_all_pipeline_nodes( ):
library[ 'OTHER' ].append( LibraryItem( n ))
text = '# Shader Nodes\n\n'
for key, items in library.items( ):
if not items:
continue
text += f'**{CAT_DATA[ key ][ 0 ]}:**\n'
for i in items:
text += i.formatted
text += '\n'
with open( MAINDIR.joinpath( 'LIBRARY.md' ), 'w' ) as open_file:
open_file.write( text )
return library