Skip to content

Commit dc5a992

Browse files
committed
stop support for LT < 4.9 and Java < 8
1 parent b57d33f commit dc5a992

4 files changed

Lines changed: 15 additions & 35 deletions

File tree

‎README.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ From the interpreter:
3535

3636
import language_tool_python
3737
tool = language_tool_python.LanguageTool('en-US')
38-
text = u'A sentence with a error in the Hitchhiker’s Guide tot he Galaxy'
38+
text = 'A sentence with a error in the Hitchhiker’s Guide tot he Galaxy'
3939
matches = tool.check(text)
4040
len(matches)
4141
2

‎language_tool_python/__init__.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
migration URL: https://languagetool.org/http-api/migration.php
44
"""
55

6-
__version__ = '2.0.4'
6+
__version__ = '2.0.5'
77

88
from .language_tag import LanguageTag
99
from .match import Match

‎language_tool_python/download_lt.py‎

Lines changed: 10 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,6 @@
2929
BASE_URL = ALT_BASE_URL or 'https://www.languagetool.org/download/'
3030
FILENAME = 'LanguageTool-{version}.zip'
3131
PACKAGE_PATH = os.path.dirname(os.path.realpath(__file__))
32-
JAVA_6_COMPATIBLE_VERSION = '2.2'
33-
JAVA_7_COMPATIBLE_VERSION = '3.1'
3432
LATEST_VERSION = '4.9'
3533

3634
JAVA_VERSION_REGEX = re.compile(
@@ -64,45 +62,26 @@ def parse_java_version(version_text):
6462
if not match:
6563
raise SystemExit(
6664
'Could not parse Java version from """{}""".'.format(version_text))
67-
6865
return (int(match.group('major1')), int(match.group('major2')))
6966

70-
71-
def get_newest_possible_languagetool_version():
72-
"""Return newest compatible version.
73-
74-
>>> version = get_newest_possible_languagetool_version()
75-
>>> version in [JAVA_6_COMPATIBLE_VERSION,
76-
... JAVA_7_COMPATIBLE_VERSION,
77-
... LATEST_VERSION]
78-
True
79-
80-
"""
67+
def confirm_java_compatibility():
68+
""" Confirms Java major version >= 8. """
8169
java_path = find_executable('java')
8270
if not java_path:
8371
# Just ignore this and assume an old version of Java. It might not be
8472
# found because of a PATHEXT-related issue
8573
# (https://bugs.python.org/issue2200).
86-
return JAVA_6_COMPATIBLE_VERSION
74+
raise ModuleNotFoundError('No java install detected. Please install java to use language-tool-python.')
8775

8876
output = subprocess.check_output([java_path, '-version'],
8977
stderr=subprocess.STDOUT,
9078
universal_newlines=True)
9179

92-
java_version = parse_java_version(output)
93-
94-
if java_version >= (1, 8):
95-
return LATEST_VERSION
96-
elif java_version >= (1, 7):
97-
return JAVA_7_COMPATIBLE_VERSION
98-
elif java_version >= (1, 6):
99-
warn('language_tool_python would be able to use a newer version of '
100-
'LanguageTool if you had Java 7 or newer installed')
101-
return JAVA_6_COMPATIBLE_VERSION
102-
else:
103-
raise SystemExit(
104-
'You need at least Java 6 to use language_tool_python')
105-
80+
major_version, minor_version = parse_java_version(output)
81+
if major_version < 8:
82+
raise SystemError(f'Detected java {major_version}.{minor_version}. LanguageTool requires Java >= 8.')
83+
84+
return True
10685

10786
def get_common_prefix(z):
10887
"""Get common directory in a zip file if any."""
@@ -123,7 +102,8 @@ def download_lt(update=False):
123102
if old_path_list and not update:
124103
return
125104

126-
version = get_newest_possible_languagetool_version()
105+
confirm_java_compatibility()
106+
version = LATEST_VERSION
127107
filename = FILENAME.format(version=version)
128108
url = urljoin(BASE_URL, filename)
129109
dirname = os.path.splitext(filename)[0]

‎language_tool_python/server.py‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -177,9 +177,6 @@ def _get_root(cls, url, data=None, num_tries=2):
177177

178178
@classmethod
179179
def _start_server_on_free_port(cls):
180-
# Download language tool if needed.
181-
download_lt()
182-
183180
while True:
184181
cls._url = 'http://{}:{}/v2/'.format(cls._HOST, cls._port)
185182
try:
@@ -193,6 +190,9 @@ def _start_server_on_free_port(cls):
193190

194191
@classmethod
195192
def _start_local_server(cls):
193+
# Before starting local server, download language tool if needed.
194+
download_lt()
195+
196196
err = None
197197
try:
198198
server_cmd = get_server_cmd(cls._port)

0 commit comments

Comments
 (0)