Skip to content

Commit

Permalink
Replace pkg_resources with importlib.metadata
Browse files Browse the repository at this point in the history
pkg_resources is deprecated in favor of importlib.metadata (https://setuptools.readthedocs.io/en/latest/pkg_resources.html).

Due to its caching behaviour, using pkg_resources causes errors on google colab (huggingface/transformers#10964), which switching to importlib.metadata solves. For version before 3.8, the importlib-metadata package provides an official backport.
  • Loading branch information
konstin committed Sep 1, 2021
1 parent ee915d2 commit 43ba549
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
11 changes: 9 additions & 2 deletions pynndescent/__init__.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,14 @@
import pkg_resources
import sys

import numba

from .pynndescent_ import NNDescent, PyNNDescentTransformer

if sys.version_info[:2] >= (3, 8):
import importlib.metadata as importlib_metadata
else:
import importlib_metadata

# Workaround: https://github.com/numba/numba/issues/3341
if numba.config.THREADING_LAYER == "omp":
try:
Expand All @@ -12,4 +19,4 @@
# might be a missing symbol due to e.g. tbb libraries missing
numba.config.THREADING_LAYER = "workqueue"

__version__ = pkg_resources.get_distribution("pynndescent").version
__version__ = importlib_metadata.version("pynndescent")
1 change: 1 addition & 0 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ def readme():
"numba >= 0.51.2",
"llvmlite >= 0.30",
"joblib >= 0.11",
'importlib-metadata >= 4.8.1; python_version < "3.8"',
],
"ext_modules": [],
"cmdclass": {},
Expand Down

0 comments on commit 43ba549

Please sign in to comment.