Skip to content

Commit 814cf03

Browse files
committed
Move from pkg_resources to importlib.metadata
1 parent 5de9a33 commit 814cf03

File tree

1 file changed

+16
-5
lines changed

1 file changed

+16
-5
lines changed

robotpy_build/pkgcfg_provider.py

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import importlib.util
2+
from importlib.metadata import entry_points, EntryPoint
23
from os.path import join, dirname
3-
from pkg_resources import iter_entry_points
44
import sys
55
from typing import Dict, List, Optional, Set
66
import warnings
@@ -27,12 +27,17 @@ class PkgCfg:
2727
Contains information about an installed package that uses robotpy-build
2828
"""
2929

30-
def __init__(self, entry_point):
30+
def __init__(self, entry_point: EntryPoint):
3131
try:
3232
self.module = entry_point.load()
3333
except Exception as e:
3434
try:
35-
self.module = _hacky_entrypoint_loader(entry_point.module_name)
35+
mod = (
36+
entry_point.module
37+
if hasattr(entry_point, "module")
38+
else entry_point.value
39+
)
40+
self.module = _hacky_entrypoint_loader(mod)
3641
except Exception:
3742
raise e
3843

@@ -147,7 +152,13 @@ def detect_pkgs(self) -> None:
147152
Only loads packages that are dependencies.
148153
"""
149154
deps_names = set().union(*[pkg.depends for pkg in self.pkgs.values()])
150-
entry_points = list(iter_entry_points(group="robotpybuild", name=None))
155+
ep_ret = entry_points()
156+
157+
# Python 3.8/3.9
158+
if isinstance(ep_ret, dict):
159+
all_entry_points = ep_ret.get("robotpybuild", [])
160+
else:
161+
all_entry_points = [e for e in entry_points() if e.group == "robotpybuild"]
151162

152163
# Only load the dependencies of the package we're building.
153164
# If we load the [package being built], then the current build will fail.
@@ -156,7 +167,7 @@ def detect_pkgs(self) -> None:
156167
run_loop = True
157168
while run_loop:
158169
run_loop = False
159-
for ep in entry_points:
170+
for ep in all_entry_points:
160171
if ep.name in self.pkgs: # Prevents loading the package being built
161172
continue
162173
if ep.name not in deps_names and ep.name != "robotpy-build":

0 commit comments

Comments
 (0)