Skip to content

Commit

Permalink
Fix DeprecationWarning: pkg_resources is deprecated as an API (#19)
Browse files Browse the repository at this point in the history
  • Loading branch information
valentino-sm authored Nov 16, 2023
1 parent e812f34 commit 08318e5
Showing 1 changed file with 14 additions and 7 deletions.
21 changes: 14 additions & 7 deletions pymorphy2/analyzer.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,18 +102,25 @@ def apply_to_tags(self, word, word_lower, tags):


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
"""
Finds entry points of installed packages, including ones installed
after the current process is started.
The main use case is to make ``!pip install pymorphy2`` work
The main use case is to make ``!pip install pymorphy2-fork`` 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)
from importlib.metadata import entry_points, EntryPoint
ep = entry_points()
result: set[EntryPoint] = set()
if not hasattr(ep, 'select'):
# Python < 3.10 old entry_points API
for group in args:
result.update(ep.get(group, ()))
else:
for group in args:
result.update(ep.select(group=group))
return result


def _lang_dict_paths():
Expand Down

0 comments on commit 08318e5

Please sign in to comment.