Skip to content

Commit

Permalink
It is now possible to suppress output in view() (#1566)
Browse files Browse the repository at this point in the history
Beside making it possible to suppress the output of `sdfv.view`, this
commit also changed the default behaviour of `SDFG.view()` by no longer
outputting in which file it was saved.
  • Loading branch information
philip-paul-mueller committed May 6, 2024
1 parent 9e1cb4a commit 91f3f1f
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 5 deletions.
9 changes: 6 additions & 3 deletions dace/cli/sdfv.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ class NewCls(cls):
return NewCls


def view(sdfg: dace.SDFG, filename: Optional[Union[str, int]] = None):
def view(sdfg: dace.SDFG, filename: Optional[Union[str, int]] = None, verbose: bool = True):
"""
View an sdfg in the system's HTML viewer
Expand All @@ -33,6 +33,7 @@ def view(sdfg: dace.SDFG, filename: Optional[Union[str, int]] = None):
the generated HTML and related sources will be
served using a basic web server on that port,
blocking the current thread.
:param verbose: Be verbose.
"""
# If vscode is open, try to open it inside vscode
if filename is None:
Expand Down Expand Up @@ -71,7 +72,8 @@ def view(sdfg: dace.SDFG, filename: Optional[Union[str, int]] = None):
with open(html_filename, "w") as f:
f.write(html)

print("File saved at %s" % html_filename)
if(verbose):
print("File saved at %s" % html_filename)

if fd is not None:
os.close(fd)
Expand All @@ -83,7 +85,8 @@ def view(sdfg: dace.SDFG, filename: Optional[Union[str, int]] = None):
# start the web server
handler = partialclass(http.server.SimpleHTTPRequestHandler, directory=dirname)
httpd = http.server.HTTPServer(('localhost', filename), handler)
print(f"Serving at localhost:{filename}, press enter to stop...")
if(verbose):
print(f"Serving at localhost:{filename}, press enter to stop...")

# start the server in a different thread
def serve():
Expand Down
5 changes: 3 additions & 2 deletions dace/sdfg/sdfg.py
Original file line number Diff line number Diff line change
Expand Up @@ -1547,14 +1547,15 @@ def save(self, filename: str, use_pickle=False, hash=None, exception=None, compr

return None

def view(self, filename=None):
def view(self, filename=None, verbose=False):
"""
View this sdfg in the system's HTML viewer
:param filename: the filename to write the HTML to. If `None`, a temporary file will be created.
:param verbose: Be verbose, `False` by default.
"""
from dace.cli.sdfv import view
view(self, filename=filename)
view(self, filename=filename, verbose=verbose)

@staticmethod
def _from_file(fp: BinaryIO) -> 'SDFG':
Expand Down

0 comments on commit 91f3f1f

Please sign in to comment.