Skip to content

Commit 19ebf44

Browse files
authored
refactor: remove deprecated stuff (jxmorris12#188)
1 parent 23310ac commit 19ebf44

4 files changed

Lines changed: 2 additions & 504 deletions

File tree

language_tool_python/download_lt.py

Lines changed: 1 addition & 154 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
import requests
2424
import tqdm
2525

26-
from ._compat import deprecated, toml_loads
26+
from ._compat import toml_loads
2727
from .exceptions import JavaError, PathError
2828
from .safe_zip import SafeZipExtractor
2929
from .utils import (
@@ -308,159 +308,6 @@ def confirm_java_compatibility(
308308
raise SystemError(err)
309309

310310

311-
@deprecated(
312-
"This function is no longer used internally and will be removed in 4.0.",
313-
stacklevel=2,
314-
)
315-
def get_common_prefix(z: zipfile.ZipFile) -> str | None:
316-
"""Determine the common prefix of all file names in a zip archive.
317-
318-
:param z: A ZipFile object representing the zip archive.
319-
:type z: zipfile.ZipFile
320-
:return: The common prefix of all file names in the zip archive, or None if there
321-
is no common prefix.
322-
:rtype: str | None
323-
324-
.. deprecated:: 3.3.0
325-
This function is no longer used internally and will be removed in 4.0.
326-
"""
327-
name_list = z.namelist()
328-
if name_list and all(n.startswith(name_list[0]) for n in name_list[1:]):
329-
return name_list[0]
330-
return None
331-
332-
333-
@deprecated(
334-
"This function is no longer used internally and will be removed in 4.0.",
335-
stacklevel=2,
336-
)
337-
def http_get(
338-
url: str,
339-
out_file: IO[bytes],
340-
proxies: dict[str, str] | None = None,
341-
) -> None:
342-
""".. deprecated:: 3.3.0.
343-
344-
This function is no longer used internally and will be removed in 4.0.
345-
346-
:raises TimeoutError: If the download request times out.
347-
:raises PathError: If the download fails or checksum validation fails.
348-
"""
349-
version_match = re.search(r"LanguageTool-(.+)\.zip", url)
350-
if version_match:
351-
version_start, version_end = version_match.span(1)
352-
version_name = url[version_start:version_end]
353-
else:
354-
version_name = LTP_DOWNLOAD_VERSION
355-
356-
# Normalize snapshot-style version names (e.g. "6.8-SNAPSHOT", "latest-snapshot")
357-
if version_name.lower().endswith("-snapshot"):
358-
version_name = version_name[: -len("-snapshot")]
359-
try:
360-
local_lt = LocalLanguageTool.from_version_name(version_name)
361-
except ValueError:
362-
# Fallback to default behavior if the extracted version is not supported
363-
local_lt = LocalLanguageTool.from_version_name(LTP_DOWNLOAD_VERSION)
364-
365-
with local_lt._get_remote_zip(out_file, proxies=proxies): # noqa: SLF001 # Accessing protected member temporarily for backward compatibility with the deprecated http_get function
366-
pass
367-
368-
369-
@deprecated(
370-
"This function is no longer used internally and will be removed in 4.0.",
371-
stacklevel=2,
372-
)
373-
def unzip_file(temp_file_name: str, directory_to_extract_to: Path) -> None:
374-
"""Unzips a zip file to a specified directory.
375-
376-
:param temp_file_name: Path to the zip file to be extracted.
377-
:type temp_file_name: str
378-
:param directory_to_extract_to: The directory where the contents of the zip file
379-
will be extracted.
380-
:type directory_to_extract_to: Path
381-
:raises PathError: If the ZIP archive or extraction destination is unsafe.
382-
383-
.. deprecated:: 3.3.0
384-
This function is no longer used internally and will be removed in 4.0.
385-
"""
386-
logger.info("Unzipping %s to %s", temp_file_name, directory_to_extract_to)
387-
with (
388-
tempfile.TemporaryDirectory(dir=directory_to_extract_to.parent) as temp_dir,
389-
zipfile.ZipFile(temp_file_name, "r") as zip_ref,
390-
):
391-
_SAFE_ZIP_EXTRACTOR.extractall(
392-
zip_ref,
393-
directory_to_extract_to,
394-
work_dir=Path(temp_dir),
395-
)
396-
397-
398-
@deprecated(
399-
"This function is no longer used internally and will be removed in 4.0.",
400-
stacklevel=2,
401-
)
402-
def download_zip(url: str, directory: Path) -> None:
403-
"""Download a ZIP file from the given URL and extract it to the specified directory.
404-
405-
:param url: The URL of the ZIP file to download.
406-
:type url: str
407-
:param directory: The directory where the ZIP file should be extracted.
408-
:type directory: Path
409-
:raises TimeoutError: If the download request times out.
410-
:raises PathError: If the download fails or the ZIP extraction is unsafe.
411-
412-
.. deprecated:: 3.3.0
413-
This function is no longer used internally and will be removed in 4.0.
414-
"""
415-
logger.info("Downloading from %s to %s", url, directory)
416-
# Download file using a context manager.
417-
with tempfile.NamedTemporaryFile(suffix=".zip", delete=False) as downloaded_file:
418-
http_get(url, downloaded_file)
419-
temp_name = downloaded_file.name
420-
# Extract zip file to path.
421-
unzip_file(temp_name, directory)
422-
# Remove the temporary file.
423-
Path(temp_name).unlink(missing_ok=True)
424-
425-
426-
@deprecated(
427-
(
428-
"This function is no longer used internally and will be removed in 4.0.\n"
429-
"Use instead language_tool_python.download_lt.LocalLanguageTool.download."
430-
),
431-
stacklevel=2,
432-
)
433-
def download_lt(language_tool_version: str = LTP_DOWNLOAD_VERSION) -> None:
434-
"""Download and extract the specified version of LanguageTool.
435-
436-
This function checks for Java compatibility, and downloads the specified version of
437-
LanguageTool if it is not already present.
438-
439-
:param language_tool_version: The version of LanguageTool to download. If not
440-
specified, the default version defined by
441-
LTP_DOWNLOAD_VERSION is used.
442-
:type language_tool_version: str
443-
:raises ValueError: If the specified version format is invalid.
444-
:raises ModuleNotFoundError: If no Java installation is detected.
445-
:raises SystemError: If the detected Java version is incompatible.
446-
:raises TimeoutError: If the download request times out.
447-
:raises PathError: If the version is unsupported, the download fails, checksum
448-
validation fails, or ZIP extraction is unsafe.
449-
450-
.. deprecated:: 3.3.0
451-
This function is no longer used internally and will be removed in 4.0.
452-
"""
453-
# Use the env var to the jar directory if it is defined
454-
# otherwise look in the download directory
455-
if os.environ.get(LTP_JAR_DIR_PATH_ENV_VAR):
456-
return
457-
458-
local_lt = LocalLanguageTool.from_version_name(language_tool_version)
459-
460-
if local_lt not in local_lt.get_installed_versions():
461-
local_lt.download()
462-
463-
464311
@total_ordering
465312
class LocalLanguageTool(ABC):
466313
"""Abstract base class for managing local LanguageTool installations.

language_tool_python/match.py

Lines changed: 0 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,6 @@
99
from functools import total_ordering
1010
from typing import TYPE_CHECKING
1111

12-
from ._compat import deprecated
13-
from .utils import SupportsFloat, SupportsInt
14-
1512
if TYPE_CHECKING:
1613
from collections.abc import Iterator
1714

@@ -61,28 +58,6 @@ def get_match_ordered_dict() -> OrderedDictType[str, type]:
6158
)
6259

6360

64-
@deprecated(
65-
"This function is no longer used internally and will be removed in 4.0.",
66-
stacklevel=2,
67-
)
68-
def auto_type(obj: SupportsInt | SupportsFloat | object) -> int | float | object:
69-
"""Attempt to automatically convert the input object to an integer or float.
70-
71-
If the conversion to an integer fails, it tries to convert to a float. If both
72-
conversions fail, it returns the original object.
73-
74-
:param obj: The object to be converted.
75-
:type obj: SupportsInt | SupportsFloat | object
76-
:return: The converted object as an integer, float, or the original object.
77-
:rtype: int | float | object
78-
"""
79-
if isinstance(obj, SupportsInt):
80-
return int(obj)
81-
if isinstance(obj, SupportsFloat):
82-
return float(obj)
83-
return obj
84-
85-
8661
def four_byte_char_positions(text: str) -> list[int]:
8762
"""Identify positions of 4-byte encoded characters in a UTF-8 string.
8863

0 commit comments

Comments
 (0)