Save this script to the specified destination. Args: dest (file-like): A file-like object that defines ``write()``, ``flush()``, ``isatty``, and has a ``name`` attribute.
(self, dest)
| 437 | return script |
| 438 | |
| 439 | def save(self, dest): |
| 440 | """ |
| 441 | Save this script to the specified destination. |
| 442 | |
| 443 | Args: |
| 444 | dest (file-like): |
| 445 | A file-like object that defines ``write()``, ``flush()``, ``isatty``, and has a ``name`` attribute. |
| 446 | """ |
| 447 | path = dest.name |
| 448 | # Somehow, piping fools isatty, e.g. `polygraphy run --gen-script - | cat` |
| 449 | is_file = not dest.isatty() and path not in ["<stdout>", "<stderr>"] |
| 450 | |
| 451 | dest.write(str(self)) |
| 452 | dest.flush() |
| 453 | |
| 454 | if is_file: |
| 455 | G_LOGGER.info(f"Writing script to: {path}") |
| 456 | # Make file executable |
| 457 | os.chmod(path, os.stat(path).st_mode | 0o111) |