Skip to content

Commit

Permalink
Revert: Stop using shutil.which on Windows as it still seems to have …
Browse files Browse the repository at this point in the history
…issues as of Python 3.8.1
  • Loading branch information
timothy-shields committed Sep 24, 2020
1 parent 23edea9 commit fc1c9a6
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 10 deletions.
17 changes: 8 additions & 9 deletions src/nxv/_graphviz.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,22 +76,21 @@ def get_graphviz_bins(graphviz_bin: Optional[str], algorithm: str) -> List[str]:
f"by the GRAPHVIZ_BIN environment variable: {graphviz_bin}"
)
return [graphviz_bin]


# Otherwise, use directory containing the result of `which {algorithm}`
graphviz_bin = shutil.which(algorithm)
if graphviz_bin:
graphviz_bin = os.path.dirname(graphviz_bin)
return [graphviz_bin]

# Otherwise, on Windows, look for the standard install locations
if is_windows():
# Otherwise, on Windows, look for the standard install locations
graphviz_bins = get_windows_graphviz_bins()
if not graphviz_bins:
raise GraphVizInstallationNotFoundError(
"No GraphViz installation was found at any of the standard Windows locations."
)
return graphviz_bins
else:
# Otherwise, on non-Windows, use directory containing the result of `which {algorithm}`
# shutil.which seems to be broken on Windows as of Python 3.8.1
graphviz_bin = shutil.which(algorithm)
if graphviz_bin:
graphviz_bin = os.path.dirname(graphviz_bin)
return [graphviz_bin]

raise GraphVizInstallationNotFoundError(
"No GraphViz installation was specified. "
Expand Down
7 changes: 6 additions & 1 deletion src/nxv/_rendering.py
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ def render(
graph: Union[nx.Graph, nx.DiGraph, nx.MultiGraph, nx.MultiDiGraph],
style: Optional[Style] = None,
*,
algorithm: str = "dot",
algorithm: Optional[str] = None,
format: Optional[str] = None,
graphviz_bin: Optional[str] = None,
subgraph_func=None,
Expand Down Expand Up @@ -201,6 +201,11 @@ def render(
:raises GraphVizAlgorithmNotFoundError: If nxv cannot find the specified algorithm in a `GraphViz`_ installation.
:raises GraphVizError: If `GraphViz`_ failed to run on the given inputs.
"""
if algorithm is None:
algorithm = "dot"
if not algorithm or not isinstance(algorithm, str):
raise ValueError("The algorithm parameter must be the str name of a valid GraphViz algorithm.")

if format is None:
if _ipython.is_execution_context():
format = "ipython/svg"
Expand Down

0 comments on commit fc1c9a6

Please sign in to comment.