Skip to content

Commit 4dbc705

Browse files
committed
[chores] Migrated pkg_resources (deprecated) to importlib
1 parent 7e7fa9b commit 4dbc705

File tree

1 file changed

+25
-8
lines changed

1 file changed

+25
-8
lines changed

openwisp_utils/admin_theme/system_info.py

Lines changed: 25 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,37 @@
11
import platform
2+
import sys
23
from collections import OrderedDict
34

4-
import pkg_resources
55
from django.conf import settings
66
from django.utils.module_loading import import_string
77

88
EXTRA_OPENWISP_PACKAGES = ["netdiff", "netjsonconfig"]
99

1010

11-
def get_installed_openwisp_packages():
12-
dists = pkg_resources.working_set
13-
return {
14-
dist.key: dist.version
15-
for dist in dists
16-
if dist.key.startswith("openwisp") or dist.key in EXTRA_OPENWISP_PACKAGES
17-
}
11+
# python 3.10+
12+
if sys.version_info > (3, 9):
13+
import importlib
14+
15+
def get_installed_openwisp_packages():
16+
dists = importlib.metadata.distributions()
17+
return {
18+
dist.name: dist.version
19+
for dist in dists
20+
if dist.name.startswith("openwisp") or dist.name in EXTRA_OPENWISP_PACKAGES
21+
}
22+
23+
24+
# legacy python 3.9, deprecated on recent python versions
25+
else:
26+
import pkg_resources
27+
28+
def get_installed_openwisp_packages():
29+
dists = pkg_resources.working_set
30+
return {
31+
dist.key: dist.version
32+
for dist in dists
33+
if dist.key.startswith("openwisp") or dist.key in EXTRA_OPENWISP_PACKAGES
34+
}
1835

1936

2037
def _get_openwisp2_detail(attribute_name, fallback=None):

0 commit comments

Comments
 (0)