Skip to content

Commit

Permalink
Merge pull request #132 from kmike/fix-dict-discovery
Browse files Browse the repository at this point in the history
Fix dict discovery for the cases pymorphy2 is installed within a notebook. Fixes GH-131
  • Loading branch information
kmike committed Sep 26, 2020
2 parents c29a17c + 2ca7473 commit 7034bfe
Showing 1 changed file with 17 additions and 2 deletions.
19 changes: 17 additions & 2 deletions pymorphy2/analyzer.py
Expand Up @@ -101,13 +101,28 @@ def apply_to_tags(self, word, word_lower, tags):
)


def _lang_dict_paths():
def _iter_entry_points(*args, **kwargs):
""" Like pkg_resources.iter_entry_points, but uses a WorkingSet which
is not populated at startup. This ensures that all entry points
are picked up, even if a package which provides them is installed
after the current process is started.
The main use case is to make ``!pip install pymorphy2`` work
within a Jupyter or Google Colab notebook.
See https://github.com/kmike/pymorphy2/issues/131
"""
import pkg_resources
ws = pkg_resources.WorkingSet()
return ws.iter_entry_points(*args, **kwargs)


def _lang_dict_paths():
paths = dict(
(pkg.name, pkg.load().get_path())
for pkg in pkg_resources.iter_entry_points('pymorphy2_dicts')
for pkg in _iter_entry_points('pymorphy2_dicts')
)

# discovery of pymorphy2 v0.8 dicts
try:
import pymorphy2_dicts
paths['ru-old'] = pymorphy2_dicts.get_path()
Expand Down

0 comments on commit 7034bfe

Please sign in to comment.