Skip to content

Commit 085dd77

Browse files
committed
Add a way to get the path to pandoc
This might be usefull for users of pypandoc which want to use the included pandoc directly.
1 parent 7cbb8fb commit 085dd77

File tree

2 files changed

+25
-1
lines changed

2 files changed

+25
-1
lines changed

‎pypandoc/__init__.py‎

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
__author__ = u'Juho Vepsäläinen'
1313
__version__ = '1.1.0'
1414
__license__ = 'MIT'
15-
__all__ = ['convert', 'get_pandoc_formats', 'get_pandoc_version']
15+
__all__ = ['convert', 'get_pandoc_formats', 'get_pandoc_version', 'get_pandoc_path']
1616

1717

1818
def convert(source, to, format=None, extra_args=(), encoding='utf-8',
@@ -253,6 +253,26 @@ def get_pandoc_version():
253253
return __version
254254

255255

256+
def get_pandoc_path():
257+
"""Gets the Pandoc path if Pandoc is installed.
258+
259+
It will return a path to pandoc which is used by pypandoc.
260+
261+
This might be a full path or, if pandoc is on PATH, simple `pandoc`. It's garanteed
262+
to be callable (i.e. we could get version information from `pandoc --version`).
263+
If `PYPANDOC_PANDOC` is set and valid, it will return that value. If the environment
264+
variable is not set, either the full path to the included pandoc or the pandoc in
265+
`PATH` (whatever is the higher version) will be returned.
266+
267+
If a cached path is found, it will return the cached path and stop probing Pandoc
268+
(unless :func:`clean_pandocpath_cache()` is called).
269+
270+
:raises OSError: if pandoc is not found
271+
"""
272+
_ensure_pandoc_path()
273+
return __pandoc_path
274+
275+
256276
def _ensure_pandoc_path():
257277
global __pandoc_path
258278

‎tests.py‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -260,6 +260,10 @@ def test_pdf_conversion(self):
260260
finally:
261261
os.remove(name)
262262

263+
def test_get_pandoc_path(self):
264+
result = pypandoc.get_pandoc_path()
265+
assert "pandoc" in result
266+
263267
def assertEqualExceptForNewlineEnd(self, expected, received):
264268
# output written to a file does not seem to have os.linesep
265269
# handle everything here by replacing the os linesep by a simple \n

0 commit comments

Comments
 (0)