##// END OF EJS Templates
pandoc version is now checked at each call to pandoc.pandoc(...). Version is tested with IPython.utils.version.version_check
Daniel B. Vasquez -
Show More
@@ -21,6 +21,8 b' from io import TextIOWrapper, BytesIO'
21 21
22 22 # IPython imports
23 23 from IPython.utils.py3compat import cast_bytes
24 from IPython.utils.version import check_version
25
24 26
25 27 from .exceptions import ConversionException
26 28
@@ -85,11 +87,12 b' def pandoc_available(failmode="return", warn=False, alt=None):'
85 87
86 88
87 89 minimal_version = "1.12.1"
90 minimal_version_ok = False
88 91
89 92 def pandoc(source, fmt, to, extra_args=None, encoding='utf-8'):
90 93 """Convert an input string in format `from` to format `to` via pandoc.
91 94
92 This function will raise an error if pandoc is not installed.
95 This function will raise PandocMissing if pandoc is not installed.
93 96 Any error messages generated by pandoc are printed to stderr.
94 97
95 98 Parameters
@@ -112,6 +115,7 b" def pandoc(source, fmt, to, extra_args=None, encoding='utf-8'):"
112 115
113 116 # if pandoc is missing let the exception bubble us out of here
114 117 pandoc_available(failmode="raise", alt=cmd)
118 check_pandoc_version()
115 119
116 120 # we can safely continue
117 121 p = subprocess.Popen(cmd, stdin=subprocess.PIPE, stdout=subprocess.PIPE)
@@ -121,22 +125,34 b" def pandoc(source, fmt, to, extra_args=None, encoding='utf-8'):"
121 125
122 126
123 127 def get_pandoc_version():
124 """Gets the Pandoc version if Pandoc is installed."""
128 """Gets the Pandoc version if Pandoc is installed.
129 PandocMissing will be raised if pandoc is unavailable.
130 """
125 131 try:
132 if not minimal_version_ok:
133 raise AttributeError()
134 else:
126 135 return pandoc.version
127 136 except AttributeError:
128 out = pandoc("None", "None", "None", ["-v"])
137 cmd = ["pandoc", "-v"]
138 try:
139 out = subprocess.check_output(cmd, universal_newlines=True)
140 except OSError as e:
141 raise PandocMissing(cmd, e)
129 142 pv_re = re.compile(r'(\d{0,3}\.\d{0,3}\.\d{0,3})')
130 143 pandoc.version = pv_re.search(out).group(0)
131 144 return pandoc.version
132 145
133 146 def check_pandoc_version():
134 """Returns True if minimal pandoc version is met"""
135 return get_pandoc_version() >= minimal_version
136
137 if pandoc_available(warn=True)[0]:
138 if(not check_pandoc_version()):
147 """Returns True if minimal pandoc version is met.
148 PandocMissing will be raised if pandoc is unavailable.
149 """
150 global minimal_version_ok
151 if not minimal_version_ok:
152 minimal_version_ok = check_version( get_pandoc_version(), minimal_version )
153 if not minimal_version_ok:
139 154 warnings.warn( "You are using an old version of pandoc (%s)\n" % pandoc.version +
140 155 "Recommended version is %s.\nTry updating." % minimal_version +
141 156 "http://johnmacfarlane.net/pandoc/installing.html.\nContinuing with doubts...",
142 157 RuntimeWarning, stacklevel=2)
158 return minimal_version_ok
General Comments 0
You need to be logged in to leave comments. Login now