|
18 | 18 | _PATH_HERE = os.path.dirname(__file__) |
19 | 19 | _PATH_ROOT = os.path.dirname(_PATH_HERE) |
20 | 20 | PATH_REQ_DEFAULT = os.path.join(_PATH_ROOT, "requirements", "default.txt") |
| 21 | +PATH_SCRIPT_RENDER = os.path.join(_PATH_HERE, "_ipynb-render.sh") |
| 22 | +PATH_SCRIPT_TEST = os.path.join(_PATH_HERE, "_ipynb-test.sh") |
21 | 23 | REPO_NAME = "lightning-tutorials" |
22 | 24 | COLAB_REPO_LINK = "https://colab.research.google.com/github/PytorchLightning" |
23 | 25 | BRANCH_DEFAULT = "main" |
@@ -293,11 +295,12 @@ def _bash_download_data(folder: str) -> List[str]: |
293 | 295 | return cmd |
294 | 296 |
|
295 | 297 | @staticmethod |
296 | | - def bash_render(folder: str) -> str: |
| 298 | + def bash_render(folder: str, output_file: str = PATH_SCRIPT_RENDER) -> Optional[str]: |
297 | 299 | """Prepare bash script for running rendering of a particular notebook. |
298 | 300 |
|
299 | 301 | Args: |
300 | 302 | folder: name/path to a folder with notebook files |
| 303 | + output_file: if defined, stream the commands to the file |
301 | 304 |
|
302 | 305 | Returns: |
303 | 306 | string with nash script content |
@@ -332,14 +335,18 @@ def bash_render(folder: str) -> str: |
332 | 335 | cmd += [f"cp {thumb_file} {pub_thumb}", f"git add {pub_thumb}"] |
333 | 336 | # add the generated notebook to version |
334 | 337 | cmd.append(f"git add {pub_ipynb}") |
335 | | - return os.linesep.join(cmd) |
| 338 | + if not output_file: |
| 339 | + return os.linesep.join(cmd) |
| 340 | + with open(output_file, "w") as fp: |
| 341 | + fp.write(os.linesep.join(cmd)) |
336 | 342 |
|
337 | 343 | @staticmethod |
338 | | - def bash_test(folder: str) -> str: |
| 344 | + def bash_test(folder: str, output_file: str = PATH_SCRIPT_TEST) -> Optional[str]: |
339 | 345 | """Prepare bash script for running tests of a particular notebook. |
340 | 346 |
|
341 | 347 | Args: |
342 | 348 | folder: name/path to a folder with notebook files |
| 349 | + output_file: if defined, stream the commands to the file |
343 | 350 |
|
344 | 351 | Returns: |
345 | 352 | string with nash script content |
@@ -369,7 +376,10 @@ def bash_test(folder: str) -> str: |
369 | 376 | warn("Invalid notebook's accelerator for this device. So no tests will be run!!!", RuntimeWarning) |
370 | 377 | # deactivate and clean local environment |
371 | 378 | cmd += ["deactivate", f"rm -rf {os.path.join(folder, 'venv')}"] |
372 | | - return os.linesep.join(cmd) |
| 379 | + if not output_file: |
| 380 | + return os.linesep.join(cmd) |
| 381 | + with open(output_file, "w") as fp: |
| 382 | + fp.write(os.linesep.join(cmd)) |
373 | 383 |
|
374 | 384 | @staticmethod |
375 | 385 | def convert_ipynb(folder: str) -> None: |
|
0 commit comments