3636BASE_URL = 'https://www.languagetool.org/download/'
3737FILENAME = 'LanguageTool-{version}.zip'
3838PACKAGE_PATH = 'language_check'
39+ JAVA_6_COMPATIBLE_VERSION = '2.2'
40+ LATEST_VERSION = '2.7'
3941
4042
4143if 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