Skip to content

Commit 8aec2bf

Browse files
committed
Avoid possible PATHEXT issue
1 parent 9fdea77 commit 8aec2bf

2 files changed

Lines changed: 17 additions & 9 deletions

File tree

‎.travis.yml‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ install:
1919
script:
2020
- if [ "$TRAVIS_PYTHON_VERSION" != "2.7" ]; then python test.py; fi
2121

22-
- if [ "$TRAVIS_PYTHON_VERSION" != "2.7" ]; then ./run_doctest.py -v README.rst; fi
22+
- if [ "$TRAVIS_PYTHON_VERSION" != "2.7" ]; then ./run_doctest.py -v README.rst download_lt.py; fi
2323

2424
# Prevent Python 2.7 from using the non-3to2 converted code.
2525
- cd language_check; ../test.bash

‎download_lt.py‎

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,8 @@
3636
BASE_URL = 'https://www.languagetool.org/download/'
3737
FILENAME = 'LanguageTool-{version}.zip'
3838
PACKAGE_PATH = 'language_check'
39+
JAVA_6_COMPATIBLE_VERSION = '2.2'
40+
LATEST_VERSION = '2.7'
3941

4042

4143
if NormalizedVersion:
@@ -57,14 +59,20 @@ class Version(LooseVersion):
5759
pass
5860

5961

60-
class InstallationError(Exception):
61-
pass
62+
def get_newest_possible_languagetool_version():
63+
"""Return newest compatible version.
6264
65+
>>> version = get_newest_possible_languagetool_version()
66+
>>> version in [JAVA_6_COMPATIBLE_VERSION, LATEST_VERSION]
67+
True
6368
64-
def get_newest_possible_languagetool_version():
69+
"""
6570
java_path = find_executable('java')
6671
if not java_path:
67-
raise InstallationError('Could not find Java.')
72+
# Just ignore this and assume an old version of Java. It might not be
73+
# found because of a PATHEXT-related issue
74+
# (https://bugs.python.org/issue2200).
75+
return JAVA_6_COMPATIBLE_VERSION
6876

6977
output = subprocess.check_output([java_path, '-version'],
7078
stderr=subprocess.STDOUT,
@@ -75,18 +83,18 @@ def get_newest_possible_languagetool_version():
7583
output,
7684
re.MULTILINE)
7785
if not match:
78-
raise InstallationError(
86+
raise SystemExit(
7987
'Could not parse Java version from """{}""".'.format(output))
8088

8189
java_version = (int(match.group('major1')), int(match.group('major2')))
8290
if java_version >= (1, 7):
83-
return '2.7'
91+
return LATEST_VERSION
8492
elif java_version >= (1, 6):
8593
warn('language-check would be able to use a newer version of '
8694
'LanguageTool if you had Java 7 or newer installed')
87-
return '2.2'
95+
return JAVA_6_COMPATIBLE_VERSION
8896
else:
89-
raise InstallationError(
97+
raise SystemExit(
9098
'You need at least Java 6 to use language-check')
9199

92100

0 commit comments

Comments
 (0)