Skip to content

Commit 3d083b9

Browse files
committed
fix: patching a wrong type annotation
1 parent 86307be commit 3d083b9

File tree

1 file changed

+13
-13
lines changed

1 file changed

+13
-13
lines changed

language_tool_python/download_lt.py

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
import subprocess
88
import tempfile
99
import tqdm
10+
import json
1011
from typing import IO, Dict, Optional, Tuple
1112
import zipfile
1213
from datetime import datetime
@@ -34,6 +35,7 @@
3435

3536
LTP_DOWNLOAD_VERSION = 'latest'
3637
LT_SNAPSHOT_CURRENT_VERSION = '6.7-SNAPSHOT'
38+
SNAPSHOT_MAP_FILE = "snapshots.json"
3739

3840
JAVA_VERSION_REGEX = re.compile(
3941
r'^(?:java|openjdk) version "(?P<major1>\d+)(|\.(?P<major2>\d+)\.[^"]+)"',
@@ -155,18 +157,18 @@ def http_get(url: str, out_file: IO[bytes], proxies: Optional[Dict[str, str]] =
155157
progress.close()
156158

157159

158-
def unzip_file(temp_file: str, directory_to_extract_to: str) -> None:
160+
def unzip_file(temp_file_name: str, directory_to_extract_to: str) -> None:
159161
"""
160162
Unzips a zip file to a specified directory.
161163
162-
:param temp_file: A temporary file object representing the zip file to be extracted.
163-
:type temp_file: str
164+
:param temp_file_name: A temporary file object representing the zip file to be extracted.
165+
:type temp_file_name: str
164166
:param directory_to_extract_to: The directory where the contents of the zip file will be extracted.
165167
:type directory_to_extract_to: str
166168
"""
167169

168-
logger.info(f'Unzipping {temp_file.name} to {directory_to_extract_to}.')
169-
with zipfile.ZipFile(temp_file.name, 'r') as zip_ref:
170+
logger.info(f'Unzipping {temp_file_name} to {directory_to_extract_to}.')
171+
with zipfile.ZipFile(temp_file_name, 'r') as zip_ref:
170172
zip_ref.extractall(directory_to_extract_to)
171173

172174

@@ -185,7 +187,7 @@ def download_zip(url: str, directory: str) -> None:
185187
# Close the file so we can extract it.
186188
downloaded_file.close()
187189
# Extract zip file to path.
188-
unzip_file(downloaded_file, directory)
190+
unzip_file(downloaded_file.name, directory)
189191
# Remove the temporary file.
190192
os.remove(downloaded_file.name)
191193
# Tell the user the download path.
@@ -226,14 +228,12 @@ def download_lt(language_tool_version: Optional[str] = LTP_DOWNLOAD_VERSION) ->
226228
if re.match(r'^\d+\.\d+$', version):
227229
filename = FILENAME_RELEASE.format(version=version)
228230
language_tool_download_url = urljoin(BASE_URL_RELEASE, filename)
229-
else:
231+
dirname, _ = os.path.splitext(filename)
232+
extract_path = os.path.join(download_folder, dirname)
233+
if extract_path in old_path_list:
234+
return
235+
elif version == 'latest':
230236
filename = FILENAME_SNAPSHOT.format(version=version)
231-
language_tool_download_url = urljoin(BASE_URL_SNAPSHOT, filename)
232-
dirname, _ = os.path.splitext(filename)
233-
if version == "latest":
234237
dirname = f"LanguageTool-{LT_SNAPSHOT_CURRENT_VERSION}"
235-
extract_path = os.path.join(download_folder, dirname)
236238

237-
if extract_path in old_path_list:
238-
return
239239
download_zip(language_tool_download_url, download_folder)

0 commit comments

Comments
 (0)