Skip to content

Commit 6521b64

Browse files
author
spirit
committed
Fix get_version() with v1.8.
1 parent 2368b8f commit 6521b64

1 file changed

Lines changed: 17 additions & 18 deletions

File tree

‎language_tool/__init__.py‎

Lines changed: 17 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -364,25 +364,24 @@ def get_version():
364364
try:
365365
return cache["version"]
366366
except KeyError:
367-
try:
368-
# LanguageTool 1.9+
369-
p = subprocess.Popen(
370-
get_version_cmd(),
371-
stdin=subprocess.PIPE,
372-
stdout=subprocess.PIPE,
373-
stderr=subprocess.PIPE,
374-
universal_newlines=True,
375-
startupinfo=startupinfo
376-
)
377-
try:
378-
s = p.communicate(timeout=15)[0]
379-
except TypeError:
380-
s = p.communicate()[0]
381-
except subprocess.CalledProcessError:
382-
s = get_language_tool_dir()
383-
match = re.search(r"LanguageTool-?.*?(\S+)$", s)
367+
version_re = re.compile(r"LanguageTool-?.*?(\S+)$")
368+
369+
# LanguageTool 1.9+
370+
proc = subprocess.Popen(
371+
get_version_cmd(),
372+
stdin=subprocess.PIPE,
373+
stdout=subprocess.PIPE,
374+
stderr=subprocess.PIPE,
375+
universal_newlines=True,
376+
startupinfo=startupinfo
377+
)
378+
out = proc.communicate()[0]
379+
match = version_re.search(out)
380+
384381
if not match:
385-
raise Error("unexpected version output: {!r}".format(s))
382+
match = version_re.search(get_language_tool_dir())
383+
if not match:
384+
raise Error("unexpected version output: {!r}".format(out))
386385
version = match.group(1)
387386
cache["version"] = version
388387
return version

0 commit comments

Comments
 (0)