sayeed105236 commited on
Commit
694d214
·
1 Parent(s): 55549d3

Fix: patch only problematic submodule imports (speech2video, animate)

Browse files
Files changed (1) hide show
  1. patch_wan_init.py +25 -10
patch_wan_init.py CHANGED
@@ -4,19 +4,34 @@ p = '/app/Wan2.2/wan/__init__.py'
4
  with open(p) as f:
5
  content = f.read()
6
 
7
- # Build a patched version: wrap every 'from .X import' in try/except
8
  lines = content.split('\n')
9
- new = []
 
 
 
 
10
  for line in lines:
11
- if line.strip().startswith('from .') and 'import' in line:
12
- indent = line[:len(line) - len(line.lstrip())]
13
- new.append(f'{indent}try:')
14
- new.append(f'{line}')
15
- new.append(f'{indent}except ImportError:')
16
- new.append(f'{indent} pass')
 
 
 
 
 
 
 
 
 
 
 
 
17
  else:
18
- new.append(line)
19
 
20
  with open(p, 'w') as f:
21
- f.write('\n'.join(new))
22
  print('Patched wan/__init__.py')
 
4
  with open(p) as f:
5
  content = f.read()
6
 
 
7
  lines = content.split('\n')
8
+ result = []
9
+
10
+ # Only wrap imports known to fail with missing optional deps
11
+ problematic = {'speech2video', 'animate', 'video2audio'}
12
+
13
  for line in lines:
14
+ stripped = line.strip()
15
+ if stripped.startswith('from .') and 'import' in stripped:
16
+ # Check if this import references a problematic submodule
17
+ parts = stripped.split()
18
+ module_ref = parts[1] # e.g. ".speech2video" or ".modules" or "."
19
+ module_name = module_ref.lstrip('.')
20
+
21
+ # Determine if this might be problematic
22
+ is_problematic = any(mod in module_name for mod in problematic)
23
+
24
+ if is_problematic:
25
+ indent = line[:len(line) - len(line.lstrip())]
26
+ result.append(f'{indent}try:')
27
+ result.append(f'{indent} {stripped}')
28
+ result.append(f'{indent}except ImportError:')
29
+ result.append(f'{indent} pass')
30
+ else:
31
+ result.append(line)
32
  else:
33
+ result.append(line)
34
 
35
  with open(p, 'w') as f:
36
+ f.write('\n'.join(result))
37
  print('Patched wan/__init__.py')