| 105 | def decorator(func): |
| 106 | @functools.wraps(func) |
| 107 | def wrapper(context): |
| 108 | nonlocal working_dir |
| 109 | |
| 110 | if callable(working_dir): |
| 111 | working_dir = working_dir(context) |
| 112 | separator() |
| 113 | log("📁", os.fsdecode(working_dir)) |
| 114 | if ( |
| 115 | clean_ok |
| 116 | and getattr(context, "clean", False) |
| 117 | and working_dir.exists() |
| 118 | ): |
| 119 | log("🚮", "Deleting directory (--clean)...") |
| 120 | shutil.rmtree(working_dir) |
| 121 | |
| 122 | working_dir.mkdir(parents=True, exist_ok=True) |
| 123 | |
| 124 | with contextlib.chdir(working_dir): |
| 125 | return func(context, working_dir) |
| 126 | |
| 127 | return wrapper |
| 128 | |