Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ tests = [
"pytest-mock",
"pytest-sphinx",
]
rtd = ["sphinx>=5.1.0,<6", "pygments", "pydot", "pydot2", "pydot-ng"]
rtd = ["sphinx>=5.1.0,<6", "pygments", "pydot"]
jax = ["jax", "jaxlib"]
numba = ["numba>=0.57", "llvmlite"]

Expand Down
48 changes: 12 additions & 36 deletions pytensor/printing.py
Original file line number Diff line number Diff line change
Expand Up @@ -1188,45 +1188,21 @@


def _try_pydot_import():
pydot_imported = False
pydot_imported_msg = ""
try:
# pydot-ng is a fork of pydot that is better maintained
import pydot_ng as pd
import pydot as pd

if pd.find_graphviz():
pydot_imported = True
else:
pydot_imported_msg = "pydot-ng can't find graphviz. Install graphviz."
pd.Dot.create(pd.Dot())
return pd

Check warning on line 1195 in pytensor/printing.py

View check run for this annotation

Codecov / codecov/patch

pytensor/printing.py#L1194-L1195

Added lines #L1194 - L1195 were not covered by tests
except ImportError:
try:
# fall back on pydot if necessary
import pydot as pd

if hasattr(pd, "find_graphviz"):
if pd.find_graphviz():
pydot_imported = True
else:
pydot_imported_msg = "pydot can't find graphviz"
else:
pd.Dot.create(pd.Dot())
pydot_imported = True
except ImportError:
# tests should not fail on optional dependency
pydot_imported_msg = (
"Install the python package pydot or pydot-ng. Install graphviz."
)
except Exception as e:
pydot_imported_msg = "An error happened while importing/trying pydot: "
pydot_imported_msg += str(e.args)

if not pydot_imported:
raise ImportError(
"Failed to import pydot. You must install graphviz "
"and either pydot or pydot-ng for "
f"`pydotprint` to work:\n {pydot_imported_msg}",
)
return pd
# tests should not fail on optional dependency
extra_msg = ""
except Exception as e:
extra_msg = f"\nAn error happened while importing/trying pydot: {e!r}"

Check warning on line 1200 in pytensor/printing.py

View check run for this annotation

Codecov / codecov/patch

pytensor/printing.py#L1199-L1200

Added lines #L1199 - L1200 were not covered by tests

raise ImportError(
"Failed to import pydot. You must install graphviz and pydot for "
f"`pydotprint` to work.{extra_msg}",
)


def pydotprint(
Expand Down
Loading