Skip to content

Commit

Permalink
fix: make marisa-trie and platformdirs really optional
Browse files Browse the repository at this point in the history
  • Loading branch information
juanjoDiaz committed Aug 8, 2024
1 parent 67f6e00 commit 62d96f7
Showing 1 changed file with 11 additions and 2 deletions.
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

0 comments on commit 62d96f7

Please sign in to comment.