diff --git a/CHANGELOG.md b/CHANGELOG.md index 13ab19974..be8185a25 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -21,6 +21,7 @@ and adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). - Added `z3` option to `one-iteration-checker` to only check for feasible code blocks based on edge z3 constraints - Added reporting for errors raised by custom transforms (`Z3Visitor`, `CFGVisitor`) - Ensured `SnapshotTracer` does not include the `_trace_func` stack frame +- Enabled `SnapshotTracer` to create its `output_directory` argument if it doesn't already exist ### 💫 New checkers diff --git a/python_ta/debug/snapshot_tracer.py b/python_ta/debug/snapshot_tracer.py index 6b3c31e65..0d1d95413 100644 --- a/python_ta/debug/snapshot_tracer.py +++ b/python_ta/debug/snapshot_tracer.py @@ -9,6 +9,7 @@ import sys import types import webbrowser +from pathlib import Path from typing import Any, Optional from bs4 import BeautifulSoup @@ -45,6 +46,7 @@ def __init__( Args: output_directory: The directory to save the snapshots, defaulting to the current directory. **Note**: Use this argument instead of the `--output` flag in `memory_viz_args` to specify the output directory. + The directory will be created if it does not exist. webstepper: Opens a MemoryViz Webstepper webpage to interactively visualize the resulting memory diagrams. **kwargs: All other keyword arguments are passed to `python.debug.snapshot`. Refer to the `snapshot` function for more details. """ @@ -60,6 +62,8 @@ def __init__( self._snapshot_args["exclude_frames"] = copy.deepcopy(kwargs.get("exclude_frames", [])) self._snapshot_args["exclude_frames"].append("_trace_func") self.output_directory = os.path.abspath(output_directory if output_directory else ".") + Path(self.output_directory).mkdir(parents=True, exist_ok=True) + self.webstepper = webstepper self._first_line = float("inf")