Skip to content
This repository was archived by the owner on Nov 19, 2018. It is now read-only.

Commit 9fee210

Browse files
committed
Support Graphviz installed from Conda
Graphviz installed using Conda is using .bat scripts to correctly setup running it on Windows.
1 parent 197ea7d commit 9fee210

File tree

2 files changed

+38
-28
lines changed

2 files changed

+38
-28
lines changed

pydot_ng/__init__.py

+23-18
Original file line numberDiff line numberDiff line change
@@ -398,6 +398,10 @@ def graph_from_incidence_matrix(matrix, node_prefix='', directed=False):
398398
return graph
399399

400400

401+
def is_qouted(path):
402+
return path.startswith('"') and path.endswith('"')
403+
404+
401405
def __find_executables(path):
402406
"""Used by find_graphviz
403407
@@ -409,7 +413,8 @@ def __find_executables(path):
409413
Otherwise returns None
410414
"""
411415

412-
success = False
416+
any_found = False
417+
413418
progs = {
414419
"dot": "",
415420
"twopi": "",
@@ -419,35 +424,35 @@ def __find_executables(path):
419424
"sfdp": "",
420425
}
421426

422-
was_quoted = False
423427
path = path.strip()
424-
if path.startswith('"') and path.endswith('"'):
428+
path_template = "{}"
429+
430+
if is_qouted(path):
425431
path = path[1:-1]
426-
was_quoted = True
432+
path_template = "\"{}\""
427433

428434
if not os.path.isdir(path):
429435
return None
430436

437+
extensions_priority = (
438+
"", # "unix"
439+
".bat",
440+
".exe",
441+
)
442+
431443
for prg in progs:
432444
if progs[prg]:
433445
continue
434446

435-
prg_path = os.path.join(path, prg)
436-
prg_exe_path = prg_path + ".exe"
447+
for ext in extensions_priority:
448+
prg_path = os.path.join(path, prg + ext)
437449

438-
if os.path.exists(prg_path):
439-
if was_quoted:
440-
prg_path = "\"{}\"".format(prg_path)
441-
progs[prg] = prg_path
442-
success = True
443-
444-
elif os.path.exists(prg_exe_path):
445-
if was_quoted:
446-
prg_exe_path = "\"{}\"".format(prg_exe_path)
447-
progs[prg] = prg_exe_path
448-
success = True
450+
if os.path.exists(prg_path):
451+
any_found = True
452+
progs[prg] = path_template.format(prg_path)
453+
break
449454

450-
if success:
455+
if any_found:
451456
return progs
452457

453458
return None

test/test_pydot.py

+15-10
Original file line numberDiff line numberDiff line change
@@ -303,20 +303,25 @@ def test_find_executables_path_needs_strip(tmpdir):
303303
) == sorted(progs)
304304

305305

306-
def test_find_executables_unix_and_exe_exists(tmpdir):
306+
@pytest.mark.parametrize(
307+
"more_important,less_important",
308+
(("", ".exe"), (".bat", ".exe"), ("", ".bat")),
309+
ids=["unix-over-exe", "bar-over-exe", "unix-over-bat"],
310+
)
311+
def test_find_executables_priority(more_important, less_important, tmpdir):
307312
path = str(tmpdir)
308-
prog_unix_path = str(tmpdir.join("dot"))
309-
prog_exe_path = str(tmpdir.join("dot.exe"))
313+
prog_more_imp = str(tmpdir.join("dot" + more_important))
314+
prog_less_imp = str(tmpdir.join("dot" + less_important))
310315

311-
with open(prog_unix_path, "w"):
312-
with open(prog_exe_path, "w"):
316+
with open(prog_more_imp, "w"):
317+
with open(prog_less_imp, "w"):
313318
progs = pydot.__find_executables(path)
314-
assert progs["dot"] == prog_unix_path
315-
assert progs["dot"] != prog_exe_path
319+
assert progs["dot"] == prog_more_imp
320+
assert progs["dot"] != prog_less_imp
316321

317322

318323
@pytest.mark.parametrize("quoted", (True, False), ids=("quoted", "unqoted"))
319-
@pytest.mark.parametrize("extension", ("", ".exe"))
324+
@pytest.mark.parametrize("extension", ("", ".exe", ".bat"))
320325
@pytest.mark.parametrize(
321326
"program", ("dot", "twopi", "neato", "circo", "fdp", "sfdp")
322327
)
@@ -326,8 +331,8 @@ def test_find_executables(tmpdir, program, extension, quoted):
326331

327332
with open(prog_path, "w"):
328333
if quoted:
329-
path = "\"{}\"".format(path)
330-
prog_path = "\"{}\"".format(prog_path)
334+
path = '"{}"'.format(path)
335+
prog_path = '"{}"'.format(prog_path)
331336

332337
progs = pydot.__find_executables(str(path))
333338
assert progs[program] == prog_path

0 commit comments

Comments
 (0)