|
| 1 | +"""VSE strip.use_linear_modifiers removal — a runnable example. |
| 2 | +
|
| 3 | +Witnesses the 5.2 removal of ``Sequence.use_linear_modifiers``. Access is a |
| 4 | +bool on 4.5 LTS and 5.1; the same getattr/setattr raises AttributeError on |
| 5 | +5.2. Version-guarded code (``hasattr`` then read) does not raise on any of |
| 6 | +the three. Pathology: no geometry, no gallery still. |
| 7 | +
|
| 8 | +The default path asserts the behavior that is correct for *this* Blender — |
| 9 | +present-and-bool below 5.2, AttributeError on 5.2+ — and still exits 0 on |
| 10 | +all three. ``--assume-present`` is the naive script: read the attribute |
| 11 | +unconditionally. That is red only on 5.2, where the attribute is gone. |
| 12 | +
|
| 13 | + blender --background --python vse_linear_modifiers.py -- |
| 14 | + blender --background --python vse_linear_modifiers.py -- --assume-present |
| 15 | +""" |
| 16 | +import argparse |
| 17 | +import sys |
| 18 | + |
| 19 | +import bpy |
| 20 | + |
| 21 | +ATTR = "use_linear_modifiers" |
| 22 | +REMOVED_AT = (5, 2, 0) |
| 23 | + |
| 24 | + |
| 25 | +def fail(msg, code): |
| 26 | + print(f"ERROR: {msg}", file=sys.stderr) |
| 27 | + return code |
| 28 | + |
| 29 | + |
| 30 | +def strips_coll(se): |
| 31 | + return se.strips if hasattr(se, "strips") else se.sequences |
| 32 | + |
| 33 | + |
| 34 | +def new_color(coll, name, channel, start, length): |
| 35 | + """COLOR strip covering [start, start+length) — version-correct end kwarg.""" |
| 36 | + if bpy.app.version >= (5, 0, 0): |
| 37 | + return coll.new_effect( |
| 38 | + name=name, type="COLOR", channel=channel, |
| 39 | + frame_start=start, length=length, |
| 40 | + ) |
| 41 | + return coll.new_effect( |
| 42 | + name=name, type="COLOR", channel=channel, |
| 43 | + frame_start=start, frame_end=start + length, |
| 44 | + ) |
| 45 | + |
| 46 | + |
| 47 | +def guarded_read(strip): |
| 48 | + """Version-safe reader: never raises. None means the RNA is gone.""" |
| 49 | + if hasattr(strip, ATTR): |
| 50 | + return getattr(strip, ATTR) |
| 51 | + return None |
| 52 | + |
| 53 | + |
| 54 | +def check(strip, assume_present=False): |
| 55 | + ver = bpy.app.version |
| 56 | + legacy = ver < REMOVED_AT |
| 57 | + require_present = assume_present or legacy |
| 58 | + print( |
| 59 | + f"blender={ver} assume_present={assume_present} " |
| 60 | + f"legacy={legacy} require_present={require_present}" |
| 61 | + ) |
| 62 | + |
| 63 | + present = hasattr(strip, ATTR) |
| 64 | + print(f"hasattr_{ATTR}={present}") |
| 65 | + |
| 66 | + if require_present: |
| 67 | + if not present: |
| 68 | + return fail( |
| 69 | + f"{ATTR} missing on {ver} — naive/legacy path requires it", |
| 70 | + 4, |
| 71 | + ) |
| 72 | + try: |
| 73 | + val = getattr(strip, ATTR) |
| 74 | + except AttributeError as exc: |
| 75 | + return fail(f"{ATTR} getattr raised on {ver}: {exc}", 4) |
| 76 | + if type(val) is not bool: |
| 77 | + return fail(f"{ATTR} is {type(val).__name__}={val!r}, not bool", 4) |
| 78 | + flipped = not val |
| 79 | + setattr(strip, ATTR, flipped) |
| 80 | + if getattr(strip, ATTR) is not flipped: |
| 81 | + return fail(f"{ATTR} setattr did not round-trip", 6) |
| 82 | + setattr(strip, ATTR, val) |
| 83 | + print(f"{ATTR}={val} round_trip_ok") |
| 84 | + else: |
| 85 | + if present: |
| 86 | + return fail( |
| 87 | + f"{ATTR} still present on {ver}; 5.2+ must have removed it", |
| 88 | + 5, |
| 89 | + ) |
| 90 | + try: |
| 91 | + getattr(strip, ATTR) |
| 92 | + return fail(f"{ATTR} getattr returned instead of AttributeError", 5) |
| 93 | + except AttributeError as exc: |
| 94 | + print(f"getattr AttributeError={exc}") |
| 95 | + |
| 96 | + try: |
| 97 | + guarded = guarded_read(strip) |
| 98 | + except AttributeError as exc: |
| 99 | + return fail(f"hasattr-guarded read still raised: {exc}", 7) |
| 100 | + print(f"guarded_read={guarded!r}") |
| 101 | + if require_present and guarded is None: |
| 102 | + return fail("guarded read returned None while the attribute exists", 7) |
| 103 | + if not require_present and guarded is not None: |
| 104 | + return fail("guarded read returned a value on 5.2+", 7) |
| 105 | + return 0 |
| 106 | + |
| 107 | + |
| 108 | +def build(): |
| 109 | + bpy.ops.wm.read_factory_settings(use_empty=True) |
| 110 | + scene = bpy.context.scene |
| 111 | + se = scene.sequence_editor_create() |
| 112 | + coll = strips_coll(se) |
| 113 | + strip = new_color(coll, "ProbeColor", channel=1, start=1, length=24) |
| 114 | + return strip |
| 115 | + |
| 116 | + |
| 117 | +def main(): |
| 118 | + argv = sys.argv[sys.argv.index("--") + 1:] if "--" in sys.argv else [] |
| 119 | + p = argparse.ArgumentParser() |
| 120 | + p.add_argument( |
| 121 | + "--assume-present", |
| 122 | + action="store_true", |
| 123 | + help="falsification: read use_linear_modifiers as if it still exists", |
| 124 | + ) |
| 125 | + args = p.parse_args(argv) |
| 126 | + |
| 127 | + strip = build() |
| 128 | + if strip is None or strip.bl_rna.identifier != "ColorStrip": |
| 129 | + return fail("COLOR strip was not created", 3) |
| 130 | + |
| 131 | + code = check(strip, assume_present=args.assume_present) |
| 132 | + if code: |
| 133 | + return code |
| 134 | + print("vse-linear-modifiers OK") |
| 135 | + return 0 |
| 136 | + |
| 137 | + |
| 138 | +if __name__ == "__main__": |
| 139 | + try: |
| 140 | + sys.exit(main()) |
| 141 | + except Exception as e: |
| 142 | + import traceback |
| 143 | + traceback.print_exc() |
| 144 | + print(f"FATAL: {e}", file=sys.stderr) |
| 145 | + sys.exit(1) |
0 commit comments