From a19d722ee9d18a9a791274686727e18092a4091c Mon Sep 17 00:00:00 2001
From: Matthias Diener <matthias.diener@gmail.com>
Date: Tue, 27 Dec 2022 03:06:05 +0100
Subject: [PATCH] remove show_dot from pymbolic (#115)

* remove show_dot from pymbolic

Moved to pytools.dot

* change required version

* update to graphviz.py

* Bump pytools requirement to a version containing the moved code

* Add deadline to show_dot deprecation

Co-authored-by: Andreas Kloeckner <inform@tiker.net>
---
 doc/utilities.rst            |  2 -
 pymbolic/imperative/utils.py | 74 +++---------------------------------
 setup.py                     |  2 +-
 3 files changed, 7 insertions(+), 71 deletions(-)

diff --git a/doc/utilities.rst b/doc/utilities.rst
index dffc8d9..466795b 100644
--- a/doc/utilities.rst
+++ b/doc/utilities.rst
@@ -54,5 +54,3 @@ Visualizing Expressions
 =======================
 
 .. autofunction:: pymbolic.imperative.utils.get_dot_dependency_graph
-
-.. autofunction:: pymbolic.imperative.utils.show_dot
diff --git a/pymbolic/imperative/utils.py b/pymbolic/imperative/utils.py
index 7479e47..ecd1e0e 100644
--- a/pymbolic/imperative/utils.py
+++ b/pymbolic/imperative/utils.py
@@ -139,75 +139,13 @@ def get_dot_dependency_graph(
 # {{{ graphviz / dot interactive show
 
 def show_dot(dot_code, output_to=None):
-    """
-    Visualize the graph represented by *dot_code*.
-    Can be called on the result of :func:`get_dot_dependency_graph`.
-
-    :arg dot_code: An instance of :class:`str` in the `dot <http://graphviz.org/>`__
-        language to visualize.
-    :arg output_to: An instance of :class:`str` that can be one of:
-
-        - ``"xwindow"`` to visualize the graph as an
-          `X window <https://en.wikipedia.org/wiki/X_Window_System>`_.
-        - ``"browser"`` to visualize the graph as an SVG file in the
-          system's default web-browser.
-        - ``"svg"`` to store the dot code as an SVG file on the file system.
-          Returns the path to the generated svg file.
-
-        Defaults to ``"xwindow"`` if X11 support is present, otherwise defaults
-        to ``"browser"``.
-
-    :returns: Depends on *output_to*.
-    """
-
-    from tempfile import mkdtemp
-    import subprocess
-    temp_dir = mkdtemp(prefix="tmp_dagrt_dot")
-
-    dot_file_name = "code.dot"
-
-    from os.path import join
-    with open(join(temp_dir, dot_file_name), "w") as dotf:
-        dotf.write(dot_code)
-
-    # {{{ preprocess 'output_to'
-
-    if output_to is None:
-        with subprocess.Popen(["dot", "-T?"],
-                              stdout=subprocess.PIPE,
-                              stderr=subprocess.PIPE
-                              ) as proc:
-            supported_formats = proc.stderr.read().decode()
-
-            if " x11 " in supported_formats:
-                output_to = "xwindow"
-            else:
-                output_to = "browser"
-
-    # }}}
-
-    if output_to == "xwindow":
-        subprocess.check_call(["dot", "-Tx11", dot_file_name], cwd=temp_dir)
-    elif output_to in ["browser", "svg"]:
-        svg_file_name = "code.svg"
-        subprocess.check_call(["dot", "-Tsvg", "-o", svg_file_name, dot_file_name],
-                              cwd=temp_dir)
-
-        full_svg_file_name = join(temp_dir, svg_file_name)
-        logger.info("show_dot_dependency_graph: svg written to '%s'",
-                full_svg_file_name)
-
-        if output_to == "svg":
-            return full_svg_file_name
-        else:
-            assert output_to == "browser"
-
-            from webbrowser import open as browser_open
-            browser_open("file://" + full_svg_file_name)
-    else:
-        raise ValueError("`output_to` can be one of 'xwindow' or 'browser',"
-                         f" got '{output_to}'")
+    from warnings import warn
+    warn("pymbolic.imperative.utils.show_dot is deprecated. "
+         "It will stop working in July 2023. "
+         "Please use pytools.graphviz.show_dot instead.", DeprecationWarning)
 
+    from pytools.graphviz import show_dot
+    return show_dot(dot_code, output_to)
 # }}}
 
 # vim: fdm=marker
diff --git a/setup.py b/setup.py
index bb45918..e0d5f35 100644
--- a/setup.py
+++ b/setup.py
@@ -37,7 +37,7 @@ setup(name="pymbolic",
       packages=find_packages(),
       python_requires="~=3.8",
       install_requires=[
-          "pytools>=2",
+          "pytools>=2022.1.14",
           ],
       extras_require={
           "test": ["pytest>=2.3"],
-- 
GitLab