[ci] auto-format

This commit is contained in:
BroBordd 2025-08-10 13:02:22 +00:00 committed by github-actions[bot]
parent bba1a27837
commit 99611b9ae6
8 changed files with 1960 additions and 1387 deletions

View file

@ -69,47 +69,54 @@ from ast import (
Name
)
class PlugTools(TAB):
KEY = 'PT_BY'
def __init__(s):
s.bys = META()
s.bad = []
s.logs = 'No errors'
s.mem = {_:MT(_) for _ in s.bys}
s.mem = {_: MT(_) for _ in s.bys}
s.eye = look()
s.e = False
s.spy()
def spy(s):
b = 0
for _ in s.bys.copy():
if not exists(PAT(_)):
s.bys.remove(_)
push(f'Plugin {_} suddenly disappeared!\nAnd so, was removed from list.',color=(1,1,0))
push(f'Plugin {_} suddenly disappeared!\nAnd so, was removed from list.', color=(1, 1, 0))
gs('block').play()
s.eye = look()
if s.hl() == _: s.hl(None)
if s.hl() == _:
s.hl(None)
b = 1
sp = app.plugins.plugin_specs.get(_,0)
if not sp: continue
sp = app.plugins.plugin_specs.get(_, 0)
if not sp:
continue
p = app.plugins
if getattr(sp,'enabled',False):
if getattr(sp, 'enabled', False):
o = s.sp.plugin
if o in p.active_plugins:
p.active_plugins.remove(o)
if o in p.plugin_specs:
p.plugin_specs.pop(o)
del s.sp.plugin,o
del s.sp.plugin, o
collect()
try: reload(modules[NAM(_,0)])
except: pass
try:
reload(modules[NAM(_, 0)])
except:
pass
continue
if MT(_) != s.mem[_] and _ not in s.bad:
s.bad.append(_)
push(f'Plugin {_} was modified!\nSee if you want to take action.',color=(1,1,0))
push(f'Plugin {_} was modified!\nSee if you want to take action.', color=(1, 1, 0))
gs('dingSmall').play()
b = 1
if hasattr(s,'sp'):
e = getattr(s.sp,'enabled',False)
if hasattr(s, 'sp'):
e = getattr(s.sp, 'enabled', False)
if e != s.e:
s.e = e
b = 1
@ -120,7 +127,8 @@ class PlugTools(TAB):
nu = []
if df:
for dd in df:
try: _ = kang(dd)
try:
_ = kang(dd)
except:
eye.remove(dd)
continue
@ -132,12 +140,16 @@ class PlugTools(TAB):
b = 1
if nu:
l = len(nu)
push(f"Found {l} new plugin{['s',''][l==1]}:\n{', '.join(nu)}\nSee what to do with {['it','them'][l!=1]}",color=(1,1,0))
push(f"Found {l} new plugin{['s', ''][l == 1]}:\n{', '.join(nu)}\nSee what to do with {['it', 'them'][l != 1]}", color=(
1, 1, 0))
gs('dingSmallHigh').play()
if b:
try: s.request_refresh()
except RuntimeError: pass
teck(0.1,s.spy)
try:
s.request_refresh()
except RuntimeError:
pass
teck(0.1, s.spy)
@override
def refresh(s):
# Preload
@ -146,14 +158,14 @@ class PlugTools(TAB):
by = None
s.hl(None)
s.by = by
s.sp = app.plugins.plugin_specs.get(by,0) if by else 0
s.i = getattr(s,'i',0 if by is None else s.bys.index(by)//10)
s.sp = app.plugins.plugin_specs.get(by, 0) if by else 0
s.i = getattr(s, 'i', 0 if by is None else s.bys.index(by)//10)
# UI
w = s.width
x = -w/2
z = x+w
# Bools
e = s.e = getattr(s.sp,'enabled',False)
e = s.e = getattr(s.sp, 'enabled', False)
m = by in s.bad
d = by is None
# Buttons
@ -162,23 +174,23 @@ class PlugTools(TAB):
z -= sx
s.button(
'Metadata',
pos=(z,50),
size=(mx,43),
pos=(z, 50),
size=(mx, 43),
call=s.metadata,
disabled=d
)
s.button(
['Load','Reload'][e],
pos=(z,5),
size=(mx,43),
['Load', 'Reload'][e],
pos=(z, 5),
size=(mx, 43),
call=s._load,
disabled=d
)
# Separator
s.button(
'',
pos=(z-(w*0.006),5),
size=(2,90)
pos=(z-(w*0.006), 5),
size=(2, 90)
)
# Plugin info
sx = w*0.1
@ -189,28 +201,28 @@ class PlugTools(TAB):
mx = sx*0.9
s.text(
t,
pos=(az,80),
scale=1 if tw<mx else mx/tw,
pos=(az, 80),
scale=1 if tw < mx else mx/tw,
)
t = 'State' if d else ['Disabled','Enabled'][e]
t = 'State' if d else ['Disabled', 'Enabled'][e]
tw = GSW(t)
s.text(
t,
pos=(az,50),
scale=1 if tw<mx else mx/tw,
pos=(az, 50),
scale=1 if tw < mx else mx/tw,
)
t = 'Purity' if d else ['Original','Modified'][m]
t = 'Purity' if d else ['Original', 'Modified'][m]
tw = GSW(t)
s.text(
t,
pos=(az,20),
scale=1 if tw<mx else mx/tw,
pos=(az, 20),
scale=1 if tw < mx else mx/tw,
)
# Separator
s.button(
'',
pos=(z-(w*0.0075),5),
size=(2,90)
pos=(z-(w*0.0075), 5),
size=(2, 90)
)
# Next
sx = w*0.03
@ -218,8 +230,8 @@ class PlugTools(TAB):
z -= sx
s.button(
cs(sc.RIGHT_ARROW),
pos=(z,5),
size=(mx,90),
pos=(z, 5),
size=(mx, 90),
call=s.next,
disabled=(s.i+1)*10 > len(s.bys)
)
@ -231,16 +243,17 @@ class PlugTools(TAB):
for i in range(5):
for j in range(2):
k = j*5+i+s.i*10
if k >= len(s.bys): break
if k >= len(s.bys):
break
t = s.bys[k]
tw = GSW(t)
s.button(
t,
size=(mx,43),
pos=(z+sx*i,50-45*j),
label_scale=1 if tw<zx else zx/tw,
call=Call(s.hl,t),
style=[['blue','blue_bright'],['purple','purple_bright']][t in s.bad][t==by]
size=(mx, 43),
pos=(z+sx*i, 50-45*j),
label_scale=1 if tw < zx else zx/tw,
call=Call(s.hl, t),
style=[['blue', 'blue_bright'], ['purple', 'purple_bright']][t in s.bad][t == by]
)
# Prev
sx = w*0.03
@ -248,32 +261,35 @@ class PlugTools(TAB):
z -= sx*0.7
s.button(
cs(sc.LEFT_ARROW),
pos=(z,5),
size=(mx,90),
pos=(z, 5),
size=(mx, 90),
call=s.prev,
disabled=s.i==0
disabled=s.i == 0
)
if s.height <= 100: return
if s.height <= 100:
return
# Expanded logs
t = s.logs
h = 25
pos = (x+10,s.height)
pos = (x+10, s.height)
z = len(t)
p = list(pos)
m = max(t.replace('\\n','') or [''],key=GSW)
m = max(t.replace('\\n', '') or [''], key=GSW)
l = GSW(str(m))/1.2
ln = t.split('\\n')
mm = max(ln,key=GSW)
mm = max(ln, key=GSW)
sk = 0.8
ml = (s.height-100) * 0.04
ww = (l*sk)*len(mm)
sk = sk if ww<s.width else (s.width*0.98/ww)*sk
sk = sk if ww < s.width else (s.width*0.98/ww)*sk
zz = len(ln)
sk = sk if zz<=ml else (ml/zz)*sk
sk = sk if zz <= ml else (ml/zz)*sk
xf = 0
for i in range(z):
p[0] += [l*sk,0][i==0]
if xf: xf = 0; continue
p[0] += [l*sk, 0][i == 0]
if xf:
xf = 0
continue
j = t[i]
k = t[i+1] if (i+1) < z else j
if j == '\\' and k == 'n':
@ -288,31 +304,36 @@ class PlugTools(TAB):
v_align='top',
scale=sk
)
def hl(s,i=None):
def hl(s, i=None):
i and deek()
c = app.config
if i is None: return c.get(s.KEY,None)
if i is None:
return c.get(s.KEY, None)
c[s.KEY] = i
c.commit()
s.request_refresh()
def _load(s):
h = ['load','reload'][s.e]
ex,er = s.load()
h = ['load', 'reload'][s.e]
ex, er = s.load()
if ex:
k = f': {ex}' if str(ex).strip() else ''
j = f'Error {h}ing {s.by}'
push(f'{j}{k}\nExpand dev console to see more.\nTraceback dumped to terminal too.',color=(1,0,0))
push(f'{j}{k}\nExpand dev console to see more.\nTraceback dumped to terminal too.', color=(1, 0, 0))
gs('error').play()
m = j+':\n'+er
print('[PlugTools] '+m)
s.logs = m.replace('\n','\\n')
s.logs = m.replace('\n', '\\n')
s.request_refresh()
return
s.logs = 'No errors'
if ex is False: return
push(h.title()+'ed '+s.by,color=(0,1,0))
if ex is False:
return
push(h.title()+'ed '+s.by, color=(0, 1, 0))
gs('gunCocking').play()
s.request_refresh()
def load(s):
_ = s.by
if _ in s.bad:
@ -320,31 +341,41 @@ class PlugTools(TAB):
s.mem[_] = MT(_)
p = app.plugins
if s.e:
if hasattr(s.sp,'plugin'):
if hasattr(s.sp, 'plugin'):
o = s.sp.plugin
if o in p.active_plugins:
p.active_plugins.remove(o)
del s.sp.plugin
collect()
try: m = reload(modules[NAM(_,0)])
try:
m = reload(modules[NAM(_, 0)])
except KeyError:
gs('block').play()
push(f"{s.by} is malformed!\nAre you sure there's no errors?",color=(1,1,0))
return (False,0)
except Exception as ex: return (ex,ERR())
else: m = __import__(NAM(_,0))
try: cls = getattr(m,_.split('.',1)[1])
except Exception as ex: return (ex,ERR())
try: ins = cls()
except Exception as ex: return (ex,ERR())
try: ins.on_app_running()
except Exception as ex: return (ex,ERR())
s.sp = PluginSpec(class_path=_,loadable=True)
push(f"{s.by} is malformed!\nAre you sure there's no errors?", color=(1, 1, 0))
return (False, 0)
except Exception as ex:
return (ex, ERR())
else:
m = __import__(NAM(_, 0))
try:
cls = getattr(m, _.split('.', 1)[1])
except Exception as ex:
return (ex, ERR())
try:
ins = cls()
except Exception as ex:
return (ex, ERR())
try:
ins.on_app_running()
except Exception as ex:
return (ex, ERR())
s.sp = PluginSpec(class_path=_, loadable=True)
s.sp.enabled = True
s.sp.plugin = ins
p.plugin_specs[_] = s.sp
p.active_plugins.append(ins)
return (0,0)
return (0, 0)
def metadata(s):
f = PAT(s.sp.class_path)
info = []
@ -355,7 +386,7 @@ class PlugTools(TAB):
try:
with open(f, 'r', encoding='utf-8', errors='ignore') as file:
lines = file.readlines()
content = "".join(lines) # Read entire content for AST parsing and char count
content = "".join(lines) # Read entire content for AST parsing and char count
line_count = len(lines)
char_count = len(content)
@ -370,13 +401,13 @@ class PlugTools(TAB):
blank_lines = 0
try:
tree = parse(content) # Use parse directly
for node in walk(tree): # Use walk directly
if isinstance(node, FunctionDef): # Use FunctionDef directly
tree = parse(content) # Use parse directly
for node in walk(tree): # Use walk directly
if isinstance(node, FunctionDef): # Use FunctionDef directly
function_count += 1
elif isinstance(node, ClassDef): # Use ClassDef directly
elif isinstance(node, ClassDef): # Use ClassDef directly
class_count += 1
elif isinstance(node, (Import, ImportFrom)): # Use Import, ImportFrom directly
elif isinstance(node, (Import, ImportFrom)): # Use Import, ImportFrom directly
import_statement_count += 1
# Iterate through physical lines for comments and blank lines
for line in lines:
@ -409,21 +440,30 @@ class PlugTools(TAB):
info.append("File Exists: No")
push('\n'.join(info))
gs('powerup01').play()
def next(s):
deek()
s.i += 1
s.request_refresh()
def prev(s):
deek()
s.i -= 1
s.request_refresh()
MT = lambda _: stat(PAT(_))
GSW = lambda s: sw(s,suppress_warning=True)
NAM = lambda _,py=1: _.split('.',1)[0]+['','.py'][py]
PAT = lambda _: join(ROOT,NAM(_))
def MT(_): return stat(PAT(_))
def GSW(s): return sw(s, suppress_warning=True)
def NAM(_, py=1): return _.split('.', 1)[0]+['', '.py'][py]
def PAT(_): return join(ROOT, NAM(_))
ROOT = env()['python_directory_user']
META = lambda: app.meta.scanresults.exports_by_name('babase.Plugin')
def META(): return app.meta.scanresults.exports_by_name('babase.Plugin')
def look():
python_files = []
try:
@ -437,6 +477,8 @@ def look():
except PermissionError:
pass
return python_files
def kang(file_path):
with open(file_path, 'r', encoding='utf-8') as f:
source_code = f.read()
@ -460,16 +502,20 @@ def kang(file_path):
(isinstance(base, Attribute) and base.attr == 'Plugin' and isinstance(base.value, Name) and base.value.id == 'babase'):
return f"{filename_without_ext}.{node.name}"
return None
deek = lambda: gs('deek').play()
def deek(): return gs('deek').play()
# brobord collide grass
# ba_meta require api 9
# ba_meta export babase.Plugin
class byBordd(Plugin):
def __init__(s):
C = PlugTools
N = C.__name__
E = ENT(N,C)
E = ENT(N, C)
I = app.devconsole
I.tabs = [_ for _ in I.tabs if _.name != N]+[E]
I._tab_instances[N] = E.factory()