Skip to content

Commit 4f373a2

Browse files
authored
Change from pkg_resources to importlib (#281)
1 parent fb381f3 commit 4f373a2

File tree

6 files changed

+36
-9
lines changed

6 files changed

+36
-9
lines changed

CHANGELOG.md

+4
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1111
[CSP rules](https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Content-Security-Policy)
1212
enforced by `webviz-config` (inline script hashes are added automatically).
1313

14+
### Changed
15+
- [#281](https://github.com/equinor/webviz-config/pull/281) - Now uses `importlib` instead of `pkg_resources` for
16+
detecting plugin entry points and package versions.
17+
1418
## [0.1.2] - 2020-09-09
1519
### Added
1620
- [#279](https://github.com/equinor/webviz-config/pull/279) - Added scrollbar to menu (when larger than screen size).

setup.py

+1
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@
4646
"pyarrow>=0.16",
4747
"pyyaml>=5.1",
4848
"tqdm>=4.8",
49+
"importlib_metadata>=1.7; python_version<'3.8'",
4950
"typing-extensions>=3.7", # Needed on Python < 3.8
5051
"webviz-core-components>=0.0.19",
5152
],

webviz_config/__init__.py

+8-3
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,9 @@
1-
from pkg_resources import get_distribution, DistributionNotFound
1+
try:
2+
# Python 3.8+
3+
from importlib.metadata import version, PackageNotFoundError # type: ignore
4+
except ModuleNotFoundError:
5+
# Python < 3.8
6+
from importlib_metadata import version, PackageNotFoundError # type: ignore
27

38
from ._theme_class import WebvizConfigTheme
49
from ._localhost_token import LocalhostToken
@@ -7,7 +12,7 @@
712
from ._shared_settings_subscriptions import SHARED_SETTINGS_SUBSCRIPTIONS
813

914
try:
10-
__version__ = get_distribution(__name__).version
11-
except DistributionNotFound:
15+
__version__ = version("webviz-config")
16+
except PackageNotFoundError:
1217
# package is not installed
1318
pass

webviz_config/_docs/_build_docs.py

+9-2
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,14 @@
1818
from collections import defaultdict
1919
from typing import Any, Dict, Optional, Tuple, List
2020

21-
import pkg_resources
21+
try:
22+
# Python 3.8+
23+
# pylint: disable=ungrouped-imports
24+
from importlib.metadata import version # type: ignore
25+
except ModuleNotFoundError:
26+
# Python < 3.8
27+
from importlib_metadata import version # type: ignore
28+
2229
import jinja2
2330
from typing_extensions import TypedDict
2431

@@ -69,7 +76,7 @@ def _document_plugin(plugin: Tuple[str, Any]) -> PluginInfo:
6976
"module": module.__name__, # type: ignore
7077
"package": top_package_name,
7178
"package_doc": import_module(subpackage).__doc__, # type: ignore
72-
"package_version": pkg_resources.get_distribution(top_package_name).version,
79+
"package_version": version(top_package_name),
7380
}
7481

7582
if argspec.defaults is not None:

webviz_config/plugins/__init__.py

+7-2
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,12 @@
22
the utility itself.
33
"""
44

5-
import pkg_resources
5+
try:
6+
# Python 3.8+
7+
from importlib.metadata import entry_points # type: ignore
8+
except ModuleNotFoundError:
9+
# Python < 3.8
10+
from importlib_metadata import entry_points # type: ignore
611

712
from ._example_plugin import ExamplePlugin
813
from ._example_data_download import ExampleDataDownload
@@ -29,6 +34,6 @@
2934
"Markdown",
3035
]
3136

32-
for entry_point in pkg_resources.iter_entry_points("webviz_config_plugins"):
37+
for entry_point in entry_points().get("webviz_config_plugins", []):
3338
globals()[entry_point.name] = entry_point.load()
3439
__all__.append(entry_point.name)

webviz_config/themes/__init__.py

+7-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,9 @@
1-
import pkg_resources
1+
try:
2+
# Python 3.8+
3+
from importlib.metadata import entry_points # type: ignore
4+
except ModuleNotFoundError:
5+
# Python < 3.8
6+
from importlib_metadata import entry_points # type: ignore
27

38
from .. import WebvizConfigTheme
49
from ._default_theme import default_theme
@@ -9,7 +14,7 @@
914

1015
__all__ = ["installed_themes"]
1116

12-
for entry_point in pkg_resources.iter_entry_points("webviz_config_themes"):
17+
for entry_point in entry_points().get("webviz_config_themes", []):
1318
theme = entry_point.load()
1419

1520
globals()[entry_point.name] = theme

0 commit comments

Comments
 (0)