Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: make marisa-trie and platformdirs really optional #143

Closed
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 11 additions & 2 deletions simplemma/strategies/dictionaries/trie_directory_factory.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,14 @@
from pathlib import Path
from typing import List, Mapping, Optional

from marisa_trie import BytesTrie, HUGE_CACHE # type: ignore[import-not-found]
from platformdirs import user_cache_dir
try:
from marisa_trie import BytesTrie, HUGE_CACHE # type: ignore[import-not-found]
from platformdirs import user_cache_dir
_dependencies_installed = True
except ImportError:
type BytesTrie = type
_dependencies_installed = False


from simplemma import __version__ as SIMPLEMMA_VERSION
from simplemma.strategies.dictionaries.dictionary_factory import (
Expand Down Expand Up @@ -69,6 +75,9 @@ def __init__(
specific subdirectory of the user's cache directory.
"""

if not _dependencies_installed:
raise ImportError("trie_dictionary dependencies must be installed before using TrieDictionaryFactory")

if disk_cache_dir:
self._cache_dir = Path(disk_cache_dir)
else:
Expand Down
Loading