Skip to content
This repository has been archived by the owner on Jan 13, 2024. It is now read-only.

Commit

Permalink
look into %PATH% for graphviz, pandoc, latex
Browse files Browse the repository at this point in the history
  • Loading branch information
sdpython committed Dec 6, 2014
1 parent 35a2048 commit 3740803
Showing 1 changed file with 39 additions and 3 deletions.
42 changes: 39 additions & 3 deletions src/pyquickhelper/helpgen/utils_sphinx_doc_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -778,6 +778,23 @@ def remove_some_indent(s):
return "\n".join(keep)
else :
return s

def find_in_PATH(prog):
"""
look into every path mentioned in ``%PATH%`` a specific file,
it raises an exception if not Found
@param prog program to look for
@return path
.. versionadded:: 0.9
"""
path = os.environ["PATH"]
for p in path.split(";"):
f = os.path.join(p, prog)
if os.path.exists(f):
return p
return None

def find_graphviz_dot():
"""
Expand All @@ -786,26 +803,39 @@ def find_graphviz_dot():
assuming it was installed in a standard folder: ``C:\Program Files\MiKTeX 2.9\miktex\bin\x64``
@return path to dot
:raises FileNotFoundError: if graphviz not found
.. versionadded:: 0.9
"""
if sys.platform.startswith("win"):
version = range(34,45)
for v in version:
graphviz_dot = r"C:\Program Files (x86)\Graphviz2.{0}\bin\dot.exe".format(v)
if os.path.exists(graphviz_dot):
return graphviz_dot

raise FileNotFoundError("unable to find graphviz, look into paths such as: " + graphviz_dot)
p = find_in_PATH("dot.exe")
if p is None:
raise FileNotFoundError("unable to find graphviz, look into paths such as: " + graphviz_dot)
else:
return p
else:
# linux
return "dot"

def find_latex_path():
"""
@return ``C:\Program Files\MiKTeX 2.9\miktex\bin\x64``
:raises FileNotFoundError: if latex not found
.. versionadded:: 0.9
"""
if sys.platform.startswith("win"):
latex = r"C:\Program Files\MiKTeX 2.9\miktex\bin\x64"
if not os.path.exists(latex):
latex = find_in_PATH("latex.exe")
if latex is None or not os.path.exists(latex):
raise FileNotFoundError("unable to find latex (miktex), look into paths such as: " + latex)
else:
# linux
Expand All @@ -816,6 +846,8 @@ def find_pandoc_path():
determines pandoc location
@return path to pandoc
.. versionadded:: 0.9
"""
if sys.platform.startswith("win"):
path = os.environ["USERPROFILE"]
Expand All @@ -832,7 +864,11 @@ def find_pandoc_path():
if os.path.exists(pandoc) :
return pandoc
tries.append(pandoc)
raise FileNotFoundError("unable to find pandoc, look into paths such as:\n" + "\n".join(tries))
pandoc = find_in_PATH("pandoc.exe")
if pandoc is None:
raise FileNotFoundError("unable to find pandoc, look into paths such as:\n" + "\n".join(tries))
else:
return pandoc
else :
return pandoc
else:
Expand Down

0 comments on commit 3740803

Please sign in to comment.