Improve music activity reporting and preserve Comfy host fixes
This commit is contained in:
@@ -0,0 +1,46 @@
|
||||
"""Hide VideoHelperSuite's background command windows without changing its media commands."""
|
||||
import ast
|
||||
import pathlib
|
||||
import shutil
|
||||
import sys
|
||||
|
||||
def patch(source):
|
||||
lines = source.splitlines(keepends=True)
|
||||
offsets = [0]
|
||||
for line in lines:
|
||||
offsets.append(offsets[-1] + len(line.encode('utf-8')))
|
||||
raw = source.encode('utf-8')
|
||||
calls = []
|
||||
for node in ast.walk(ast.parse(source)):
|
||||
if not isinstance(node, ast.Call) or not isinstance(node.func, ast.Attribute):
|
||||
continue
|
||||
if not isinstance(node.func.value, ast.Name) or node.func.value.id != 'subprocess' or node.func.attr not in ('Popen', 'run', 'check_output', 'check_call', 'call'):
|
||||
continue
|
||||
if any(k.arg == 'creationflags' for k in node.keywords):
|
||||
continue
|
||||
calls.append(node)
|
||||
for node in sorted(calls, key=lambda n: (n.end_lineno, n.end_col_offset), reverse=True):
|
||||
end = offsets[node.end_lineno - 1] + node.end_col_offset - 1
|
||||
prefix = b'' if raw[:end].rstrip().endswith(b',') else b','
|
||||
raw = raw[:end] + prefix + b" creationflags=getattr(subprocess, 'CREATE_NO_WINDOW', 0)" + raw[end:]
|
||||
result = raw.decode('utf-8')
|
||||
ast.parse(result)
|
||||
return result
|
||||
|
||||
if __name__ == '__main__':
|
||||
root = pathlib.Path(sys.argv[1]).resolve(strict=True)
|
||||
plans = []
|
||||
for name in ('nodes.py', 'utils.py', 'load_video_nodes.py'):
|
||||
path = root / 'videohelpersuite' / name
|
||||
source = path.read_text(encoding='utf-8')
|
||||
plans.append((path, source, patch(source)))
|
||||
for path, source, result in plans:
|
||||
if source == result:
|
||||
print(f'Already patched: {path.name}')
|
||||
continue
|
||||
backup = path.with_suffix('.py.before-aigen-hidden')
|
||||
if backup.exists():
|
||||
raise RuntimeError(f'Backup already exists: {backup}')
|
||||
shutil.copy2(path, backup)
|
||||
path.write_text(result, encoding='utf-8')
|
||||
print(f'Patched {path.name}; original backed up.')
|
||||
@@ -0,0 +1,37 @@
|
||||
"""Make YuE's HF token samplers honor Comfy's cancel flag. Run with the node directory."""
|
||||
import ast
|
||||
import pathlib
|
||||
import shutil
|
||||
import sys
|
||||
|
||||
CHECK = ' from comfy.model_management import throw_exception_if_processing_interrupted\n throw_exception_if_processing_interrupted()\n'
|
||||
|
||||
def patch(source):
|
||||
tree = ast.parse(source)
|
||||
cls = next(n for n in tree.body if isinstance(n, ast.ClassDef) and n.name == 'BlockTokenRangeProcessor')
|
||||
method = next(n for n in cls.body if isinstance(n, ast.FunctionDef) and n.name == '__call__')
|
||||
if 'throw_exception_if_processing_interrupted' in ast.get_source_segment(source, method):
|
||||
return source
|
||||
lines = source.splitlines(keepends=True)
|
||||
lines.insert(method.body[0].lineno - 1, CHECK)
|
||||
result = ''.join(lines)
|
||||
ast.parse(result)
|
||||
return result
|
||||
|
||||
if __name__ == '__main__':
|
||||
root = pathlib.Path(sys.argv[1]).resolve(strict=True)
|
||||
plans = []
|
||||
for name in ('infer.py', 'common.py'):
|
||||
path = root / 'inference' / name
|
||||
source = path.read_text(encoding='utf-8')
|
||||
plans.append((path, source, patch(source)))
|
||||
for path, source, result in plans:
|
||||
if source == result:
|
||||
print(f'Already patched: {path.name}')
|
||||
continue
|
||||
backup = path.with_suffix('.py.before-aigen-cancel')
|
||||
if backup.exists():
|
||||
raise RuntimeError(f'Backup already exists: {backup}')
|
||||
shutil.copy2(path, backup)
|
||||
path.write_text(result, encoding='utf-8')
|
||||
print(f'Patched {path.name}; original backed up.')
|
||||
Reference in New Issue
Block a user